ROC-RK3328-CC Buy Specs

Firefly first ultra-small open-source main board, unique USB3.0 and DDR4 to make its performance faster and more stable. The ultra-affordable ROC-RK3328-CC is your first choice for exploring the programming world.

Customize Android Firmware

Update time:2018-01-02 Views:2356

Foreword

customize Android firmware, there are two ways:

  1. Change the source code, and then compile to generate the firmware.

  2. Crop based on existing firmware.

The former  method, you can customize Android from all levels, a large degree of  freedom, but the compiler environment and technical requirements are  relatively high, you can refer to RK3399 《Customize Firmware》  article.

Now introduce the latter method, including three stages: unpacking, customization and packaging. Host operating system for Linux, the tools used for open source software.

Firmware Format

Unified firmware release_update.img,Contains the boot loader loader.img and the real firmware data update.img

release_update.img

|- loader.img
`- update.img

update.img is a compound file, containing multiple files, described by the package-file. A typical package-file is:

# NAMERelative path
package-filepackage-file
bootloaderImage/MiniLoaderAll.bin
parameter       Image/parameter.txt
trust           Image/trust.img
uboot           Image/uboot.img
miscImage/misc.img
resourceImage/resource.img
kernelImage/kernel.img
boot            Image/boot.img
recoveryImage/recovery.img
systemImage/system.img
backupRESERVED
#update-scriptupdate-script
#recover-scriptrecover-script
  • package-file

  • update.img package description file, update.img also contains a package-file.

  • Image/MiniLoaderAll.bin

  • Bootloader, that is boot loader.

  • Image/parameter.txt

  • Parameter file, you can set the kernel boot parameters, there is an important partition information.

  • Image/trust.img

  • trust.img is a two-level loader package.

  • Image/misc.img

  • misc partition image, used to control Android to start normally, or to enter the rescue mode (Recovery Mode).

  • Image/kernel.img

  • Android kernel。

  • Image/resource.img

  • Resource image with kernel boot image and Device Tree Blob.

  • Image/boot.img

  • Android kernel  memory boot disk (initrd), is the kernel file system loaded after the  first boot, contains important initialization actions, generally do not  need to change.

  • Image/recovery.img

  • Android first aid mode image, root file system with kernel and first aid mode.

  • Image/system.img

  • Corresponding to the Android / system partition, that is the following custom object.

Unpacking is extracting  update.img in release_update.img and then unpacking multiple files of it which containing the package-file declaration.
Packaging,  it is an inverse process, it can synthesis a number of documents which the package-file lists into update.img, with loader.img, the finally generates release_update.img.

Tools Prepare

git clone https://github.com/TeeFirefly/rk2918_tools.gitcd rk2918_tools
make
sudo cp afptool img_unpack img_maker mkkrnlimg /usr/local/bin

Unpacking

  • Unpacking release_update.img

$ cd /path/to/your/firmware/dir
$ img_unpack Firefly-RK3399_20161027.img img
rom version: 6.0.1
build time: 2016-10-27 14:58:18
chip: 33333043
checking md5sum....OK
  • Unpacking update.img

$ cd img
$ afptool -unpack update.img update
Check file...OK
------- UNPACK -------
package-file	0x00000800	0x00000280
Image/MiniLoaderAll.bin	0x00001000	0x0003E94E
Image/parameter.txt	0x00040000	0x00000350
Image/trust.img	0x00040800	0x00400000
Image/uboot.img	0x00440800	0x00400000
Image/misc.img	0x00840800	0x0000C000
Image/resource.img	0x0084C800	0x0003FE00
Image/kernel.img	0x0088C800	0x00F5D00C
Image/boot.img	0x017EA000	0x0014AD24
Image/recovery.img	0x01935000	0x013C0000
Image/system.img	0x02CF5000	0x2622A000
RESERVED	0x00000000	0x00000000
UnPack OK!
  • Check the file tree in the update directory

$ cd update/
$ tree
.
├── Image
│   ├── boot.img
│   ├── kernel.img
│   ├── MiniLoaderAll.bin
│   ├── misc.img
│   ├── parameter.txt
│   ├── recovery.img
│   ├── resource.img
│   ├── system.img
│   ├── trust.img
│   └── uboot.img
├── package-file
└── RESERVED

1 directory, 12 files

In this way, unpacking firmware successfully, so let us begin to customize it.

Customize

Customize system.img

system.img is an ext4 file system format image file which can be mounted directly to the system to modify:

sudo mkdir -p /mnt/system
sudo mount -o loop Image/system.img /mnt/system
cd /mnt/system
# Modify the contents of the inside, pay attention to the remaining space, 
# can not add too many APKs
# Modify ok, you need to uninstall
cd /
sudo umount /mnt/system

Note that the  system.img remaining space is basically 0, if not delete the file, you  need to expand the system.img, and according to the final file size,  adjust the parameter file partition settings.

The following is  an example of how to expand the space, before extending, run mount to ensure system.img has been uninstalled.
The following commands are to increase the space of 128M

dd if=/dev/zero bs=1M count=128 >> Image/system.img
# Expand file system information
e2fsck -f Image/system.img
resize2fs Image/system.img

Packing

First of all, check  the size of system.img and compare parameter file partitioning situation (refer to the  document 《Parameter file format》), make the necessary resize.
For example, by viewing the system partition size descriped in the parameter.txt file, you can find "CMDLINE" line, and then find the system string:

0x00200000@0x000B0000(system)

In front of the "@" is the size of the partition, the unit is 512 bytes, so the size of the system partition is:

$ echo $(( 0x00200000 * 512 / 1024 / 1024))M
1024M

As long as the size of system.img does not exceed 1024M, the parameter file does not need to change.
If  the partition does not have to change, you can directly burn the new  system.img with programming tools into the system partition  to do the test. Otherwise, you need to make new firmware and burn it before testing.

The following are the steps required to package a unified firmware update.img:

  • synthesis update.img :

# The current directory is still update/, which contains package-file, 
# and files that package-file lists still exist
# Copy the parameter file to paramter, because afptool is used by default
$ cp Image/parameter.txt parameter
$ afptool -pack . ../update_new.img
------ PACKAGE ------
Add file: ./package-file
Add file: ./Image/MiniLoaderAll.bin
Add file: ./Image/parameter.txt
Add file: ./Image/trust.img
Add file: ./Image/uboot.img
Add file: ./Image/misc.img
Add file: ./Image/resource.img
Add file: ./Image/kernel.img
Add file: ./Image/boot.img
Add file: ./Image/recovery.img
Add file: ./Image/system.img
Add file: ./RESERVED
Add CRC...
------ OK ------
Pack OK!
  • synthesis release_update.img :

$ img_maker -rk33 loader.img update_new.img release_update_new.img
generate image...
append md5sum...
success!

release_update_new.img is the final build of a uniform, writable firmware file.

FAQs

Q1: Where is the setting of firmware version?

A1: It is in the parameter file, just find the "FIRMWARE" and modify it, pay attention to the version number, the middle two dots among the number can not be omitted.

FIRMWARE_VER: 6.0.1