Customize Ubuntu firmware

Preface

There are two ways to customize Ubuntu firmware:

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

  2. Tailor based on existing firmware

    • It is divided into three stages: unpacking, customization and packaging. The host operating system is Linux, and the tools used are open source software

This article mainly explains the second method in detail:

Firmware format

Assuming that release_update.img is the name of the released firmware, the unified firmware release_update.img consists of 2 parts:

  1. Built-in boot loader loader.img

  2. Real firmware data update.img

release_update.img
|- loader.img
`- update.img

Among them, update.img is the real firmware data file, which is a compound file containing multiple files. By replacing the compound file, the firmware can be customized:

├── Image
│   ├── boot.img
│   ├── MiniLoaderAll.bin
│   ├── misc.img
│   ├── parameter.txt
│   ├── parameter.txt.orig
│   ├── recovery.img
│   ├── rootfs.img
│   ├── trust.img
│   └── uboot.img
├── MiniLoaderAll.bin
└── package-file

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

Tool preparation

firefly-linux-repack
    ├── bin
    │   ├── afptool
    │   └── rkImageMaker
    ├── pack.sh
    ├── Readme_en.md
    ├── Readme.md
    └── unpack.sh

Unpack

  1. Unpack 把官方发布的固件拷贝到当前目录,重命名为update.img , 执行unpack.sh 解包完成后,生成的文件在output目录下.

  2. Package 保持当前目录结构,文件名等不变,用客户自己的文件替换output/下同名的文件 执行pack.sh, 执行完后,生成new_update.img,即为打包好的固件 rootfs文件名必须为rootfs.img parameter.txt文件名必须为parameter.txt

  • note: During the package process, if the rootfs partition is not the last partition, the program will follow the size of the rootfs file,Automatically modify the size of the rootfs partition in parameter.txt. If the user himself changes parameter.txt, please pay attention to the entire package process.

## 1. Unpack: Rename the firmware to update.img
tar -xzf firefly-linux-repack.tgz
cd firefly-linux-repack
mv /???/FIREFLY-RK3399-UBUNTU18.04-GPT-20200714-1510.img update.img
./unpack.sh

## 2. Replace the constituent files in the output directory

## 3. Package: generate new_update.img
./pack.sh
ls new_update.img