rk3399_upgrade_tool


原文链接: rk3399_upgrade_tool

有用的连接:

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

这里用到的主要是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> [-noreset]
UpgradeLoader:		UL <Loader> [-noreset]
DownloadImage:		DI <-p|-b|-k|-s|-r|-m|-u|-t|-re image>
DownloadBoot:		DB <Loader>
EraseFlash:		    EF <Loader|firmware> [DirectLBA]
PartitionList:		PL
----------------Professional Command -----------------
TestDevice:		    TD
ResetDevice:		RD [subcode]
ResetPipe:		    RP [pipe]
ReadCapability:		RCB
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>

我们可以利用这个工具完成很多操作。

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

`