有用的鏈接:php
Rockchip官方資料:linux
http://opensource.rock-chips.com/wiki_Main_Pagegit
http://opensource.rock-chips.com/wiki_RK3399shell
http://opensource.rock-chips.com/wiki_Boot_option工具
http://opensource.rock-chips.com/wiki_U-Boot#Download_U-Bootgitlab
Firefly官方資料:ui
http://wiki.t-firefly.com/index.php/Firefly-RK3399spa
http://wiki.t-firefly.com/index.php/Firefly-RK3399/Flash_image 命令行
SDKcode
https://gitlab.com/TeeFirefly/FireNow-Nougat
https://gitlab.com/TeeFirefly/FireNow-Marshmallow
一、燒寫工具
這裏用到的主要是upgrade_tool,在按住recovery鍵開機會進入下載模式,此時運行這個工具,而後選擇板子對應的設備號,就會進入命令行:
$sudo upgrade_tool List of rockusb connected DevNo=1 Vid=0x2207,Pid=0x330c,LocationID=307 Loader Found 1 rockusb,Select input DevNo,Rescan press <R>,Quit press <Q>:1 ---------------------Tool Usage --------------------- Help: H Quit: Q Version: V Clear Screen: CS ------------------Upgrade Command ------------------ ChooseDevice: CD SwitchDevice: SD UpgradeFirmware: UF <Firmware> UpgradeLoader: UL <Loader> DownloadImage: DI <-p|-b|-k|-s|-r|-m image> [parameter file] DownloadBoot: DB <Loader> EraseFlash: EF <Loader|firmware> LowerFormat: LF ----------------Professional Command ----------------- TestDevice: TD ResetDevice: RD [subcode] ResetPipe: RP [pipe] ReadFlashID: RID ReadFlashInfo: RFI ReadChipInfo: RCI ReadSector: RS <BeginSec> <SectorLen> [-decode] [File] WriteSector: WS <BeginSec> <File> ReadLBA: RL <BeginSec> <SectorLen> [File] WriteLBA: WL <BeginSec> <File> EraseBlock: EB <CS> <BeginBlock> <BlokcLen> [--Force] ------------------------------------------------------- Rockusb>
咱們能夠利用這個工具完成不少操做。
這個工具的下載地址: 百度雲 或 Linux_Upgrade_Tool_v1.24.zip
幫助手冊: upgrade_tool幫助手冊.pdf
二、使用upgrade_tool燒寫uboot.img
閱讀wiki:http://wiki.t-firefly.com/index.php/Firefly-RK3399/Flash_image 能夠知道各個鏡像在emmc中對應的地址:
從這裏能夠看到uboot被燒寫到了emmc的0x2000處。
燒寫方法1:
進入upgrade_tool的命令行模式,執行:
Rockusb>WL 0x2000 uboot.img
燒寫方法2:
直接執行:
sudo upgrade_tool wl 0x2000 ./uboot.img
其中wl也能夠寫成WL
用upgrade_tool燒寫其餘分區的鏡像的命令以下:
燒寫統一固件 update.img: sudo upgrade_tool uf update.img 燒寫分區鏡像: sudo upgrade_tool di -b /path/to/boot.img sudo upgrade_tool di -k /path/to/kernel.img sudo upgrade_tool di -s /path/to/system.img sudo upgrade_tool di -r /path/to/recovery.img sudo upgrade_tool di -m /path/to/misc.img sudo upgrade_tool di resource /path/to/resource.img sudo upgrade_tool di -p paramater #燒寫 parameter sudo upgrade_tool ul bootloader.bin # 燒寫 bootloader sudo upgrade_tool di trust /path/to/trust.img #燒寫 trust
di參數的格式: di <分區名稱/縮寫> <對應的鏡像文件的路徑信息>,具體分區的名字能夠查看parameter.txt文件,好比上面用upgrade_tool燒寫uboot也能夠用:
sudo upgrate_tool di uboot /path/to/uboot.img
從parameter.txt中能夠獲得以下emmc的分區:
mtdparts=rk29xxnand:0x00002000@0x00002000(uboot),0x00002000@0x00004000(trust),0x00002000@0x00006000(misc),0x00008000@0x00008000(resource),0x0000C000@0x00010000(kernel),0x00010000@0x0001C000(boot),0x00010000@0x0002C000(recovery),0x00038000@0x0003C000(backup),0x00040000@0x00074000(cache),0x00300000@0x000B4000(system),0x00008000@0x003B4000(metadata),0x00002000@0x003BC000(baseparamer),-@0x003BE000(userdata)
uboot:對應的是uboot.img
trust:對應的是trust.img, 其中含有ATF以及休眠喚醒相關的文件
misc: misc 分區映像,對應misc.img,負責啓動模式切換和急救模式的參數傳遞。
resource: 資源映像,對應的是resource.img,內含開機圖片和內核的設備樹信息。
kernel: 內核映像,對應的是kernel.img
boot: Android 的初始文件映像,即ramdisk,負責初始化並加載 system 分區,對應的是boot.img
recovery:急救模式映像,對應的是recovery.img
system: Android 的 system 分區映像,ext4 文件系統格式,對應的是system.img
三、在maskrom模式也能夠使用upgrade_tool
四、audit2allow的使用
在kernel log裏能夠看到不少avc的log:
[ 143.450213] type=1400 audit(1358499630.406:133): avc: denied { read open } for pid=1812 comm="vm" path="/system/bin/sh" dev="mmcblk1p10" ino=399 scontext=u:r:sudaemon:s0 tcontext=u:object_r:shell_exec:s0 tclass=file permissive=1 [ 143.450484] type=1400 audit(1358499630.406:134): avc: denied { execute_no_trans } for pid=1812 comm="vm" path="/system/bin/sh" dev="mmcblk1p10" ino=399 scontext=u:r:sudaemon:s0 tcontext=u:object_r:shell_exec:s0 tclass=file permissive=1 [ 143.450738] type=1400 audit(1358499630.410:135): avc: denied { getattr } for pid=1812 comm="sh" path="/system/bin/sh" dev="mmcblk1p10" ino=399 scontext=u:r:sudaemon:s0 tcontext=u:object_r:shell_exec:s0 tclass=file permissive=1 [ 143.462718] type=1400 audit(1358499630.423:136): avc: denied { getattr } for pid=1812 comm="sh" path="/dev/pts/0" dev="devpts" ino=3 scontext=u:r:sudaemon:s0 tcontext=u:object_r:devpts:s0 tclass=chr_file permissive=1 [ 143.463075] type=1400 audit(1358499630.423:137): avc: denied { ioctl } for pid=1812 comm="sh" path="/dev/pts/0" dev="devpts" ino=3 ioctlcmd=5401 scontext=u:r:sudaemon:s0 tcontext=u:object_r:devpts:s0 tclass=chr_file permissive=1
能夠用下面的辦法將上面的這些語句轉換爲相似下面的selinux的語法:
allow adbd graphics_device:dir { search };
allow adbd surfaceflinger:fifo_file rw_file_perms;
首先將要轉換的avc信息保存到一個臨時文件中,好比tmp.txt
而後用adb pull將板子上的sepolicy文件拷貝出來:adb pull /sepolicy
設置環境變量ANDROID_BUILD_TOP爲Android源碼的路徑:export ANDROID_BUILD_TOP=/home/pengdonglin/disk_ext/Firefly/RK3399/sdk_7_1_1
而後Android源碼中提供的audit2allow工具進行轉換:./external/selinux/prebuilts/bin/audit2allow -p ~/logcat/rk3399/selinux/sepolicy -i ~/logcat/rk3399/selinux/tmp.txt
五、fastboot的使用
參考:http://opensource.rock-chips.com/wiki_Fastboot
使用方法:
Rockchip use 0x2207 as its USB vendor ID. This VID is not in Google's original fastboot code. So every fastboot command have to use "-i" parameter to specify vid to fastboot.
To list all the Rockchip devices attached to your USB port in fastboot mode.
進入fastboot:
adb reboot fastboot
在uboot的log中能夠看到:
#Boot ver: 2017-12-30#1.06 empty serial no. reboot normal.
查看:
fastboot -i 0x2207 devices
0123456789 fastboot
六、用命令進入下載模式
在Android系統下進入:
adb reboot bootloader
在fastboot模式下進入:
fastboot reboot-bootloader
能夠在uboot的log中看到:
#Boot ver: 2017-12-30#1.06 empty serial no. reboot rockusb.
此時咱們能夠適用upgrade_tool進行鏡像的燒寫等等。
七、unlock設備
在fastboot模式下執行下面的命令:
先執行 fastboot -i 0x2207 oem unlock
而後在5s內執行 fastboot -i 0x2207 oem unlock_accept
八、使用fastboot啓動內核
在進行開發時,爲了延長flash的壽命,每次改完內核後,沒有必要每次都燒進emmc。fastboot提供了boot命令。
默認的uboot已經支持fastboot了,可是在用fastboot boot啓動新的kernel時提示以下錯誤:
creating boot image...
creating boot image - 18911232 bytes
downloading 'boot.img'...
FAILED (remote: not support "-u" option)
finished. total time: 0.000s
經過分析uboot代碼發現,fastboot每次只能接受16MB的數據,而咱們的kernel.img爲19MB,因此須要修改uboot代碼:
diff --git a/u-boot/include/configs/rk_default_config.h b/u-boot/include/configs/rk_default_config.h index d408d05..849b8ca 100755 --- a/u-boot/include/configs/rk_default_config.h +++ b/u-boot/include/configs/rk_default_config.h @@ -256,7 +256,7 @@ * CONFIG_FASTBOOT_TRANSFER_BUFFER_SIZE should be larger than our boot/recovery image size. */ #define CONFIG_FASTBOOT_TRANSFER_BUFFER_SIZE CONFIG_RK_BOOT_BUFFER_SIZE -#define CONFIG_FASTBOOT_TRANSFER_BUFFER_SIZE_EACH (CONFIG_FASTBOOT_TRANSFER_BUFFER_SIZE >> 1) +#define CONFIG_FASTBOOT_TRANSFER_BUFFER_SIZE_EACH (CONFIG_FASTBOOT_TRANSFER_BUFFER_SIZE)
重新編譯uboot,將生成的uboot.img燒寫到emmc中,從新啓動。
而後用下面的命令:
adb reboot fastboot
fastboot -i 0x2207 boot /home/pengdonglin/disk_ext/Firefly/RK3399/sdk_7_1_1/kernel/kernel.img
==