[rk356x] [firefly Linux] take you through each partition of Ubuntu firmware during a break

Posted by Serpent7 on Sun, 13 Feb 2022 11:56:09 +0100

In order to facilitate development and product customization, Ruixin micro has defined a set of firmware partitions, and these partition information is stored in parameter Txt file, Firefly defines its own Ubuntu partition with reference to this file, and the file is parameter Ubuntu Txt, stored in Linux_ Under the device/rockchip/rk356x directory of SDK; In addition, a package file named rk356x Ubuntu package file is also used when packaging Ubuntu firmware, which is stored in Linux_ Tools / Linux / Linux of SDK_ Pack_ Firmware / rockdev directory. Now let me lead you to briefly analyze these two documents!

1, Parameter Ubuntu txt

Enter the directory of device/rockchip/rk356x, cat parameter Ubuntu txt:

MAGIC: 0x5041524B
ATAG: 0x00200800
MACHINE: 0xffffffff
PWR_HLD: 0,0,A,0,1
CMDLINE: mtdparts=rk29xxnand:0x00002000@0x00004000(uboot),0x00002000@0x00006000(misc),0x00010000@0x00008000(boot),0x00010000@0x00018000(recovery),0x00010000@0x00028000(backup),0x00c00000@0x00038000(rootfs),-@0x00c38000(userdata:grow)

The following is an overview from the Ruixin micro document:

  • The Rockchip android system platform uses the parameter file to configure some system parameters, such as firmware version, memory partition information, etc. (in fact, android system platform is the same as linux system platform)
  • Parameter file is a very important system configuration file. It's best to modify it when you can understand each configuration function, so as to avoid the problem that the system cannot work normally due to abnormal configuration of parameter file.
  • The size of the Parameter file is limited. The maximum size cannot exceed 64KB.

parameter-ubuntu. Description of TXT file content:

FIRMWARE_VER: 1.0Firmware version, package updata IMG will be used, and the upgrade tool will identify the firmware version according to this.
MACHINE_MODEL: RK3568Machine model, packing updata IMG uses different items and can be modified by itself to upgrade the tool display. When upgrading firmware in recovery, it can be used to judge whether the firmware matches.
MACHINE_ID: 007Product development ID, which can be a combination of characters and numbers, packaged updata IMG uses different IDs for different items, which can be used to identify the machine model. When upgrading firmware in recovery, it can be used to judge whether the firmware matches.
MANUFACTURER: RK3568Manufacturer information, package updata IMG can be modified by itself and used to upgrade the tool display.
MAGIC: 0x5041524BMAGIC cannot be modified. Some new AP S use DTS. This item is useless. For compatibility, do not delete or modify it.
ATAG: 0x00200800ATAG cannot be modified. Some new AP S use DTS. This item is useless. For compatibility, do not delete or modify it.
MACHINE: 0xffffffffIt is used for kernel recognition and cannot be modified. This definition matches the kernel.
CHECK_MASK: 0x80Reserved and cannot be modified.
TYPE: GPTSpecify that the partition defined in the file CMDLINE is used to create GPT and will not be burned into NVM (NAND, EMMC, etc.) memory devices.
MACHINE: 0xffffffffIt is used for kernel recognition and cannot be modified. This definition matches the kernel.
CMDLINE(to be explained later)
uuid:rootfs=614e0000-0000-4b53-8000-1d28000054a9Reserved and cannot be modified.

In addition to CMDLINE, we rarely need to modify these in the list!

The CMDLINE attribute is our focus:

CMDLINE: mtdparts=rk29xxnand:0x00002000@0x00004000(uboot),0x00002000@0x00006000(misc),0x00010000@0x00008000(boot),0x00010000@0x00018000(recovery),0x00010000@0x00028000(backup),0x00c00000@0x00038000(rootfs),-@0x00c38000(userdata:grow)

The following is a description extracted from the Ruixin micro document:

  1. For compatibility, all AP S of RK are identified with rk29xxnand.
  2. Single partition Description:
    For example: 0x00010000@0x00008000(boot), the value before the @ symbol is the partition size, the value after the @ symbol is the starting position of the partition, and the characters in parentheses are the name of the partition. The unit of all values is sector, and one sector is 512Bytes. In the above example, the start position of boot partition is 0x8000 sectors and the size is 0x10000 sectors(32MB).
  3. For performance, the starting address of each partition needs to be aligned with 32KB (64 sectors), and the size also needs an integer multiple of 32KB.
  4. If the image in spark format is used, the data will be erased during upgrade. For better compatibility, the corresponding partition should be aligned according to 4MB, and the size should also be configured according to 4MB integer multiples.
  5. When GPT partition is used, the addresses defined in the parameter are all real logical addresses (LBA s). For example, uboot is defined as 0x4000, so when burning into EMMC and NAND, the logical address is also 0x4000. The last partition needs to specify the grow th parameter, and the tool will allocate the remaining space to the last partition.

The following is a description of the functions of each partition of Ubuntu firmware:

  • Uboot partition: burn uboot compiled by uboot img.
  • Misc partition: burn misc img. Boot detection enters recovery mode.
  • Boot partition: burn the boot compiled by kernel IMG contains kernel and device tree information.
  • Recovery partition: burn recovery img.
  • Backup partition: reserved, temporarily useless. It will be used as the backup of recovery just like android.
  • rootfs partition: store ubuntu file system, read-only.
  • userdata partition: store files temporarily generated by app or for end users. Read and write, mounted in the / userdata directory.

2, Rk356x Ubuntu package file

Enter tools/linux/Linux_Pack_Firmware/rockdev directory, cat rk356x Ubuntu package file:

# NAME          Relative path
#HWDEF          HWDEF
package-file    package-file
bootloader      Image/MiniLoaderAll.bin
parameter       Image/parameter.txt
uboot           Image/uboot.img
misc            Image/misc.img
boot            Image/boot.img
recovery        Image/recovery.img
rootfs          Image/rootfs.img
userdata        RESERVED
backup          RESERVED

It is not difficult to see that this file is used to specify the corresponding relationship between the partition and the packaged image! The following is the Ubuntu firmware log packaged in RK format:

neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ ./build.sh updateimg
processing option: updateimg
File name is  ROC-RK3568-PC-UBUNTU20.04-GPT 
Rename the file? [N|y]n
Make update.img
start to make update.img...
Resize rootfs partition size
dumpe2fs 1.44.1 (24-Mar-2018)
Android Firmware Package Tool v1.66
------ PACKAGE ------
Add file: ./package-file
Add file: ./package-file done,offset=0x800,size=0x11a,userspace=0x1
Add file: ./Image/MiniLoaderAll.bin
Add file: ./Image/MiniLoaderAll.bin done,offset=0x1000,size=0x719c0,userspace=0xe4
Add file: ./Image/parameter.txt
Add file: ./Image/parameter.txt done,offset=0x73000,size=0x1d5,userspace=0x1
Add file: ./Image/uboot.img
Add file: ./Image/uboot.img done,offset=0x73800,size=0x400000,userspace=0x800
Add file: ./Image/misc.img
Add file: ./Image/misc.img done,offset=0x473800,size=0xc000,userspace=0x18
Add file: ./Image/boot.img
Add file: ./Image/boot.img done,offset=0x47f800,size=0x1ff4800,userspace=0x3fe9
Add file: ./Image/recovery.img
Add file: ./Image/recovery.img done,offset=0x2474000,size=0x1e23800,userspace=0x3c47
Add file: ./Image/rootfs.img
Add file: ./Image/rootfs.img done,offset=0x4297800,size=0xa744fc00,userspace=0x14e8a0
Add CRC...
Make firmware OK!
------ OK ------
********RKImageMaker ver 1.66********
Generating new image, please wait...
Writing head info...
Writing boot file...
Writing firmware...
Generating MD5 data...
MD5 data generated successfully!
New image generated successfully!
Making ./Image/update.img OK.
Make update image ok!
Running build_updateimg succeeded.

3, Attention

Linux released by Firefly_ When SDK packages firmware, the size of rootfs partition will change dynamically according to the actual file size of rootfs, in other words, parameter Ubuntu Txt file 0x00c00000@0x00038000(rootfs),-@0x00c38000(userdata:grow) the specified rootfs partition size of the content and the starting address of the userdata partition will be dynamically modified! This is because the size of partitions occupied by different file systems varies greatly. This operation can avoid partition waste!

Topics: Linux Ubuntu server microchip rk3568