有用的連接:
Rockchip官方資料:
http://opensource.rock-chips.com/wiki_Main_Page
http://opensource.rock-chips.com/wiki_RK3399
http://opensource.rock-chips.com/wiki_Boot_option
http://opensource.rock-chips.com/wiki_U-Boot#Download_U-Boot
Firefly官方資料:
http://wiki.t-firefly.com/index.php/Firefly-RK3399
http://wiki.t-firefly.com/index.php/Firefly-RK3399/Flash_image
SDK
https://gitlab.com/TeeFirefly/FireNow-Nougat
https://gitlab.com/TeeFirefly/FireNow-Marshmallow
1、燒寫工具
這里用到的主要是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
2、使用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
3、在maskrom模式也可以使用upgrade_tool
4、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
5、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
6、用命令進入下載模式
在Android系統下進入:
adb reboot bootloader
在fastboot模式下進入:
fastboot reboot-bootloader
可以在uboot的log中看到:
#Boot ver: 2017-12-30#1.06 empty serial no. reboot rockusb.
此時我們可以適用upgrade_tool進行鏡像的燒寫等等。
7、unlock設備
在fastboot模式下執行下面的命令:
先執行 fastboot -i 0x2207 oem unlock
然后在5s內執行 fastboot -i 0x2207 oem unlock_accept
8、使用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
==