How to make your own SD-bootable ROM
Contents
1 Make Image Files for RK3399
Refer to this repo: https://github.com/friendlyarm/sd-fuse_rk3399
2 Make Image Files for S5P4418
Refer to this repo: https://github.com/friendlyarm/sd-fuse_s5p4418
Example:
mkdir test cd test git clone https://github.com/friendlyarm/sd-fuse_s5p4418 cd sd-fuse_s5p4418/ tar xzf /mnt/dvd/S5P4418/images-for-eflasher/friendlycore-images.tgz tar xzf /mnt/dvd/S5P4418/images-for-eflasher/emmc-flasher-images.tgz tar xzf /mnt/dvd/S5P4418/rootfs/rootfs-friendlycore-20190718.tgz sed "s/\${BOARD}/XXYYZZ/g" friendlycore/rootfs/etc/rc.local -i ./build-rootfs-img.sh friendlycore/rootfs friendlycore/rootfs.img ./mk-emmc-image.sh friendlycore dd if=out/s5p4418-eflasher-friendlycore-20190730.img of=/dev/sdX bs=32M
3 Make Image Files for S5P6818
Refer to this repo: https://github.com/friendlyarm/sd-fuse_s5p6818
4 Make Image Files for H3
Refer to this repo: https://github.com/friendlyarm/sd-fuse_h3
5 Make Image File for H5
If you have a customized U-boot, Linux kernel and file system and want to use them to make a customized Linux image file(we call it "ROM" in the following sections) you can do it this way: use the "dd" command to copy all the data and files from an existing SD card with a Linux ROM, replace the U-boot, kernel or file system with your customzied files and use the "dd" command again to combine these files to a ROM. However this is inefficient. We suggest you use our rom-maker-lite utility to do it, which can be downloaded at rom-maker-lite.
The rom-maker-lite utility is a general tool to make a ROM. It currently supports making a Linux based sd/eflasher ROM for FriendlyElec's H3/H5 boards .Making an Android image is not supported yet.
- Run ./mkimage.sh to check usage info:
$ ./mkimage.sh Usage: $ apt-get install tree exfat-utils dosfstools python3-tk $ ./mkimage.sh -c <filesystem type> -m <partmap> -d "<misc dir>;<partition1 dir>;<partition2 dir>;..." -c <filesystem type>: 1: misc(bootloader) + fat32 boot.img + ext4 rootfs.img 2: misc(bootloader) + fat32 boot.img + ext4 rootfs.img + exfat friendlyarm.img 3: misc(bootloader) + ext4 boot.img + ext4 rootfs.img
Parameter Comment -c <filesystem type> -c specifies file systems' formats for the partitions in a ROM Image. Specifically for an H3/H5 based board:
-c 1 stands for "misc(bootloader) + fat32 boot.img + ext4 rootfs.img" and this applies to an sd ROM of FriendlyCore/Ubuntu/Debian/OpenWrt;
-c 2 stands for "misc(bootloader) + fat32 boot.img + ext4 rootfs.img + exfat friendlyarm.img" and this applies to an eflasher ROM.-m <partmap> -m specifies a partmap file for making a ROM.
A partmap file is used to specify the files and their sizes included in a ROM. ROMs made for different boards or BSPs may need different partmap files.-d "<misc dir>;<partition1 dir>;<partition2 dir>;..." -d specifies file system's path and each path is separated by a ";". Specifically for an H3/H5 based board:
<misc dir>: specifies the bootloader's path;
<partition1 dir>: specifies the boot partition's path;
<partition2 dir>: specifies the rootfs partition's path;
"..." means more paths can be defined. When you make an eflasher ROM you need to include the friendlyarm partition's path;
- Preparations
We tested the following Ubuntu versions that worked with a PC host:
1) ubuntu-16.04.5-desktop-amd64.iso
2) ubuntu-18.04.1-desktop-amd64.iso
If you cannot make a ROM under a Linux system with your PC host you'd better use either one of the above two systems we tested.
Before proceed make sure you have installed the following packages:
$ apt-get install tree exfat-utils dosfstools python3-tk
You need the root access right to make a ROM:
$ su root
5.1 Make sd ROM
5.1.1 Linux-4.14
For Linux-4.14 BSP all FriendlyElec's H5 platforms that have the same rootfs share the same SD ROM. Therefore the steps to make an sd ROM for all FriendlyElec's H5 platforms that support this BSP are the same.
We take FriendlyCore's sd ROM as an example to show how to do it. The steps for making an sd ROM for Ubuntu,Debian,OpenWrt are the same.
- Get a Full FriendlyCore's rootfs Directory
There are two ways to do it:
1) Make an SD card with FriendlyCore and mount the SD card's rootfs partition on a PC host;
2) Extract the /rootfs/rootfs_friendlycore_4.14_YYYYMMDD.tgz file
- Suppose rootfs' path is "./rom-maker-lite/part2/h5/4.14/friendlycore/rootfs/". After you run the following command you will be able to get an sd ROM:
$ cd rom-maker-lite $ ./mkimage.sh -c 1 -m partmap/h5_linux-4.14/partmap.txt -d "misc/uboot-2017_h5/;part1/boot_linux-4.14_h5/;part2/h5/4.14/friendlycore/rootfs/"
- All FriendlyElec's H5 platforms that run the Linux-4.14 BSP use the same partmap file: partmap/h5_linux-4.14/partmap.txt
- You can replace the files under "misc/uboot-2017_h5" and "part1/boot_linux-4.14_h5" with your application files. You can check the existing files by commanding "tree":
$ tree misc/uboot-2017_h5/ part1/boot_linux-4.14_h5/ misc/uboot-2017_h5/ ├── sunxi-spl.bin └── u-boot.itb part1/boot_linux-4.14_h5/ ├── boot.cmd ├── boot.scr ├── Image ├── overlays │ └── sun50i-h5-gpio-dvfs-overlay.dtb ├── rootfs.cpio.gz ├── sun50i-h5-nanopi-k1-plus.dtb ├── sun50i-h5-nanopi-neo2.dtb ├── sun50i-h5-nanopi-neo-core2.dtb └── sun50i-h5-nanopi-neo-plus2.dtb
After the mkimage.sh script is run successfully an "out/SD-bootable-1" directory ("1" corresponds to parameter "-c 1"). Here is what it will show:
$ tree out/ out/ ├── SD-bootable-1 │ └── your_company │ ├── boot.img │ ├── info.conf │ ├── partmap.txt │ ├── rootfs.img │ ├── sunxi-spl.bin │ └── u-boot.itb ├── SD-bootable-1.img
- The "part1/boot_linux-4.14_h5/" directory will be converted to "boot.img";
- The "part2/h5/4.14/friendlycore/rootfs/" directory will be converted to "rootfs.img";
- The "SD-bootable-1.img" file will be an sd ROM which is composed of all files under the "SD-bootable-1" directory and is equivalent to a nanopi-[h5]_sd_friendlycore-xenial_4.14_armhf_YYYYMMDD.img file released by FriendlyElec;
5.2 Make eflasher ROM
Before you make an eflasher ROM make sure you have already made a FriendlyCore/Debian/OpenWrt sd ROM.
For example if you want to make a Linux-4.14 based FriendlyCore eflasher ROM you need to have a Linux-4.14 based FriendlyCore sd ROM. You can check the existing files by commanding "tree":
$ tree out/ out/ ├── SD-bootable-1 │ └── your_company │ ├── boot.img │ ├── info.conf │ ├── partmap.txt │ ├── rootfs.img │ ├── sunxi-spl.bin │ └── u-boot.itb
- Get a Full eflasher rootfs Directory
There are two ways to do it:
1) Make an eflasher SD card and mount the SD card's rootfs partition on a PC host;
2) Extract the /rootfs/rootfs_eflasher_4.14_YYYYMMDD.tgz file
- Suppose eflasher rootfs' path is "./rom-maker-lite/part2/h5/4.14/eflasher/rootfs/",After you run the following command you will be able to get an eflasher ROM:
$ cd rom-maker-lite $ ./mkimage.sh -c 2 -m partmap/h5_eflasher-4.14/partmap.txt -d "misc/uboot-2017_h5/;part1/boot_linux-4.14_h5/;part2/h5/4.14/eflasher/rootfs;out/SD-bootable-1"
After the mkimage.sh script is run successfully an "out/SD-bootable-2" directory. Here is what it will show:
$ tree out/SD-bootable-2 out/SD-bootable-2 ├── SD-bootable-2 │ └── your_company │ ├── boot.img │ ├── friendlyarm.img │ ├── info.conf │ ├── partmap.txt │ ├── rootfs.img │ ├── sunxi-spl.bin │ └── u-boot.itb └── SD-bootable-2.img
- The "part1/boot_linux-4.14_h5" directory will be converted to "boot.img";
- The "part2/h5/4.14/eflasher/rootfs/" directory will be converted to "rootfs.img";
- The "out/SD-bootable-1/" directory will be converted to "friendlyarm.img";
- The "SD-bootable-2.img" file will be an eflasher ROM which is composed of all files under the "SD-bootable-2" directory and is equivalent to a nanopi-[h5]_eflasher_friendlycore-xenial_4.14_arm64_YYYYMMDD.img file released by FriendlyElec;
Actually all FriendlyElec's H5 platforms use the same file "nanopi-[h5]_eflasher_friendlycore-xenial_4.14_arm64_YYYYMMDD.img".
5.3 Make boot.img/rootfs.img
Actually the rom-maker-lite utility calls the "./tools/mk_fsimg.sh" script to generate a boot.img and rootfs.img. Here are the popular parameters the "mk_fsimg.sh" script usually takes:
Parameter Comment Parameter1 Specifies a partition format. It currently supports vfat/ext4/exfat
Parameter 2 Specifies an output file;
Parameter 3 Specifies an input directory;
Parameter 4 Specifies an output file's size and the unit is MByte. This size should be greater than the input directory's size and less than the corresponding size specified(in "length") in the partmap.txt file;
Since some file system information needs to be included in an image file this size will be greater than the input directory's size;
Parameter 5 Specifies a partition's tag;
5.3.1 Linux-4.14
You can run the following commands to generate a boot.img and rootfs.img for a Linux-4.14 based sd ROM:
$ cd rom-maker-lite $ ./tools/mk_fsimg.sh vfat boot.img ./part1/boot_linux-4.14_h5/ 40 boot $ ./tools/mk_fsimg.sh ext4 rootfs.img ./part2/h5/4.14/friendlycore/rootfs/ 2048 rootfs
These commands apply to all FriendlyElec's H5 platforms.