How to make your own SD-bootable ROM

From FriendlyELEC WiKi
Revision as of 02:58, 11 December 2018 by Wuweidong (Talk | contribs) (Make Linux ROM for H5)

Jump to: navigation, search

查看中文

1 Change the files in rootfs.img and boot.img

apt install android-tools-fsutils
simg2img rootfs.img r.img
mount -t ext4 -o loop r.img /mnt
… To Change Something …
umount /mnt
img2simg r.img rootfs.img

2 Make Linux Image Files for 4418/6818

The key point is to make the boot section in the SD card to a boot.img and the rootfs section in the SD card to a rootfs.img and replace the corresponding files in an eflasher. Run the following commands on a PC host:
1) Download https://github.com/friendlyarm/debian_nanopi2;
2) Copy all the files in your SD card's boot section to "debian_nanopi2/boot" and all the files in your SD card's rootfs section to "debian_nanopi2/rootfs";
You can make changes in these two directories according to your requirements.
We suggest you remove the "etc/fs.resized" file under the rootfs directory to allow system's automatic file system extension.
3) Make an img file with the make_ext4fs utility under "debian_nanopi2":

./tools/make_ext4fs -s -l 67108864 -a root -L boot boot.img boot
./tools/make_ext4fs -s -l 3670016000 -a root -L rootfs rootfs.img rootfs

one thing you should be aware of is that the size of the .img file needs to be larger than the rootfs directory size,
below are the image size values for each system we’ve provided:
lubuntu: 5368709120
debian: 3670016000
friendlycore: 3670016000

4) Copy the newly generated boot.img and rootfs.img to the "core-gte" directory of an eflasher's FAT section and replace the corresponding files. This eflasher will be ready for use

3 Make Linux ROM for H3

If you have compiled a U-boot, Linux kernel and a file system, and want to make a your own Linux image (ROM) with these files you can refer to the following steps:
Download a package "rom-maker-lite.tar.gz" : download link, extract it in host PC running Ubuntu and you will get the following directorie:

rom-maker-lite

The "rom-maker-lite" directory has the script utilities which can be used to make a ROM that boots from an SD card.

Currently the script utilities under the "rom-maker-lite" directory can be only used to make Linux ROMs for H3/H5. You can check its usage by running the "./mkimage.sh" script:

$ ./mkimage.sh 
Usage:
    $ cp ../bsp-prebuilt/* ./ -r
    $ ./mkimage.sh <prepare type> <partmap> <misc dir> <partition1 dir> <partition2 dir>
        prepare type: 
            p1: prepare misc(bootloader) + partition1.img(fat32 boot) + partition2.img(ext4 rootfs)
            p2: prepare misc(bootloader) + partition1.img(fat32 boot) + partition2.img(ext4 rootfs) + partition3.img(fat32 eflashed material)
            p3: prepare misc(bootloader) + partition1.img(ext4 boot) + partition2.img(ext4 rootfs)
Parameter Comment
<prepare type> specifies a ROM type. For H3/H5 p1 means to make a FriendlyCore/Ubuntu/Debian ROM and p2 means to make an Eflasher ROM.
<partmap> specifies a partmap that is needed for making a ROM. A partmap file specifies a ROM Image's partition and components. Different platforms or different BSPs for the same platform use different partmap files.
<misc dir> specifies a bootloader's path for H3/H5.
<partition1 dir> specifies the boot partition's path for H3/H5.
<partition2 dir> specifies the rootfs's path for H3/H5.


  • Make Uboot-2017 + Linux-4.14 ROM for H3

All FriendlyElec's H3 boards work with a Uboot-2017 + Linux-4.14 ROM. So the steps to generate a ROM based on a BSP are the same for all FriendlyElec boards.
If you have a bootable SD card with FriendlyCore the rootfs directory in the SD card should have all the files you need. Insert this SD card to a host PC, mount the SD card's rootfs directory (in our test it was mounted at /media/SD/rootfs) and make a ROM following the steps below:

$ ./mkimage.sh p1 partmap/h3_linux-4.14/partmap.txt misc/uboot-2017_h3/ part1/boot_linux-4.14_h3/ /media/SD/rootfs

Replace the existing files under the directories (misc/uboot-2017_h3, part1/boot_linux-4.14_h3) with your new files. FriendlyElec will periodically update files. You can list all the files by commanding "tree":

$ tree misc/uboot-2017_h3/ part1/boot_linux-4.14_h3/
misc/uboot-2017_h3/
└── u-boot-sunxi-with-spl.bin
part1/boot_linux-4.14_h3/
├── boot.cmd
├── boot.scr
├── rootfs.cpio.gz
├── sun8i-h2-plus-nanopi-duo.dtb
├── sun8i-h3-nanopi-duo2.dtb
├── sun8i-h3-nanopi-m1.dtb
├── sun8i-h3-nanopi-m1-plus.dtb
├── sun8i-h3-nanopi-neo-air.dtb
├── sun8i-h3-nanopi-neo-core.dtb
├── sun8i-h3-nanopi-neo.dtb
└── zImage

For all the FriendlyElec's H3 boards that works with Linux-4.14 BSP they use the same partmap file which is "partmap/h3_linux-4.14/partmap.txt".
After running the mkimage.sh script a "out/SD-bootable-p1" directory will be generated and it will have the following files:

$ tree out/
out/
├── SD-bootable-p1
│   └── your_company
│       ├── boot.img
│       ├── info.conf
│       ├── partmap.txt
│       ├── rootfs.img
│       └── u-boot-sunxi-with-spl.bin
├── SD-bootable-p1.img

The "part1/boot_linux-4.14_h3/" directory will be made to a boot.img, the "part2/rootfs_demo/" directory will be made to a rootfs.img and the SD-bootable-p1.img will be the new ROM. You can use the win32diskimager utility under Windows or command "dd" under Linux to flash a SD-bootable-p1.img to an SD card.


  • Make Uboot-2011 + Linux-3.4 ROM for H3

Let's take FriendlyElec's NanoPi M1 as an example, run the following command:

$ ./mkimage.sh p1 partmap/h3_linux-3.4/partmap.txt misc/uboot-2011_m1/ part1/boot_linux-3.4_m1/ part2/rootfs_demo/

Replace the existing files under the directories with your new files.
For all the FriendlyElec's H3 boards that works with Linux-3.4 BSP they use the same partmap file which is "partmap/h3_linux-3.4/partmap.txt".
So if you want to make a ROM for a NanoPi M1 Plus you can run the following command:

$ ./mkimage.sh p1 partmap/h3_linux-3.4/partmap.txt misc/uboot-2011_m1-plus/ part1/boot_linux-3.4_m1-plus/ part2/rootfs_demo/

This applies to the NanoPi NEO / NanoPi NEO Air too.


  • Make Uboot-2017 + Linux-4.14 Eflasher ROM for H3

In order to make an Eflasher ROM you need to have an existing FriendlyCore ROM. A Uboot-2017 + Linux-4.14 FriendlyCore image has the following files:

$ tree out/
out/
├── SD-bootable-p1
│   └── your_company
│       ├── boot.img
│       ├── info.conf
│       ├── partmap.txt
│       ├── rootfs.img
│       └── u-boot-sunxi-with-spl.bin

If you have a bootable SD card with Eflasher, insert the SD card to a host PC, mount the SD card's rootfs directory(in our test it was mounted at the "/media/SD/rootfs-eflasher" directory) and run the following command to generate an Eflasher ROM:

$ ./mkimage.sh p2 partmap/h3_eflasher-4.14/partmap.txt misc/uboot-2017_h3/ part1/boot_linux-4.14_h3/ /media/SD/rootfs-eflasher out/SD-bootable-p1/

After running the mkimage.sh script an "out/SD-bootable-p2" directory will be generated and it will have the following files:

$ tree out/
out/
├── SD-bootable-p1
│   └── your_company
│       ├── boot.img
│       ├── info.conf
│       ├── partmap.txt
│       ├── rootfs.img
│       └── u-boot-sunxi-with-spl.bin
├── SD-bootable-p1.img
├── SD-bootable-p2
│   └── your_company
│       ├── boot.img
│       ├── friendlyarm.img
│       ├── info.conf
│       ├── partmap.txt
│       ├── rootfs.img
│       └── u-boot-sunxi-with-spl.bin
└── SD-bootable-p2.img

The SD-bootable-p2.img file will be the newly generated Eflasher ROM. What OS the "out/SD-bootable-p1/" contains will be the OS in this Eflasher ROM. You can use the win32diskimager utility under Windows or command "dd" under Linux to flash a SD-bootable-p2.img to an SD card.

4 Make Linux ROM for H5

If you have compiled a U-boot, Linux kernel and a file system, and want to make a your own Linux image (ROM) with these files you can refer to the following steps:
Download a package "rom-maker-lite.tar.gz" : download link, extract it in host PC running Ubuntu and you will get the following directorie:

rom-maker-lite

The "rom-maker-lite" directory has the script utilities which can be used to make a ROM that boots from an SD card.

Currently the script utilities under the "rom-maker-lite" directory can be only used to make Linux ROMs for H3/H5. You can check its usage by running the "./mkimage.sh" script:

$ ./mkimage.sh 
Usage:
    $ cp ../bsp-prebuilt/* ./ -r
    $ ./mkimage.sh <prepare type> <partmap> <misc dir> <partition1 dir> <partition2 dir>
        prepare type: 
            p1: prepare misc(bootloader) + partition1.img(fat32 boot) + partition2.img(ext4 rootfs)
            p2: prepare misc(bootloader) + partition1.img(fat32 boot) + partition2.img(ext4 rootfs) + partition3.img(fat32 eflashed material)
            p3: prepare misc(bootloader) + partition1.img(ext4 boot) + partition2.img(ext4 rootfs)
Parameter Comment
<prepare type> specifies a ROM type. For H3/H5 p1 means to make a FriendlyCore/Ubuntu/Debian ROM and p2 means to make an Eflasher ROM.
<partmap> specifies a partmap that is needed for making a ROM. A partmap file specifies a ROM Image's partition and components. Different platforms or different BSPs for the same platform use different partmap files.
<misc dir> specifies a bootloader's path for H3/H5.
<partition1 dir> specifies the boot partition's path for H3/H5.
<partition2 dir> specifies the rootfs's path for H3/H5.


  • Make Uboot-2017 + Linux-4.14 ROM for H5

All FriendlyElec's H5 boards work with a Uboot-2017 + Linux-4.14 ROM. So the steps to generate a ROM based on a BSP are the same for all FriendlyElec boards. If you have a bootable SD card with FriendlyCore the rootfs directory in the SD card should have all the files you need. Insert this SD card to a host PC, mount the SD card's rootfs directory (in our test it was mounted at /media/SD/rootfs) and make a ROM following the steps below

$ ./mkimage.sh p1 partmap/h5_linux-4.14/partmap.txt misc/uboot-2017_h5/ part1/boot_linux-4.14_h5/ /media/SD/rootfs

Replace the existing files under the directories (misc/uboot-2017_h5, part1/boot_linux-4.14_h5) with your new files. FriendlyElec will periodically update files. You can list all the 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

For all the FriendlyElec's H5 boards that works with Linux-4.14 BSP they use the same partmap file which is "partmap/h5_linux-4.14/partmap.txt".
After running the mkimage.sh script a "out/SD-bootable-p1" directory will be generated and it will have the following files:

$ tree out/
out/
├── SD-bootable-p1
│   └── your_company
│       ├── boot.img
│       ├── info.conf
│       ├── partmap.txt
│       ├── rootfs.img
│       ├── sunxi-spl.bin
│       └── u-boot.itb
├── SD-bootable-p1.img

The "part1/boot_linux-4.14_h5/" directory will be made to a boot.img, the "part2/rootfs_demo/" directory will be made to a rootfs.img and the SD-bootable-p1.img will be the new ROM. You can use the win32diskimager utility under Windows or command "dd" under Linux to flash a SD-bootable-p2.img to an SD card.


  • Make Uboot-2014 + Linux-3.10 ROM for H5

Let's take FriendlyElec's NanoPi NEO2 as an example, run the following command:

$ ./mkimage.sh p1 partmap/h5_linux-3.10/partmap.txt misc/uboot-2014_neo2/ part1/boot_linux-3.10_neo2/ part2/rootfs_demo/

Replace the existing files under the directories with your new files. For all the FriendlyElec's H5 boards that works with Linux-3.10 BSP they use the same partmap file which is "partmap/h5_linux-3.10/partmap.txt".

  • Make Uboot-2017 + Linux-4.14 Eflasher ROM for H5

In order to make an Eflasher ROM you need to have an existing FriendlyCore ROM. A Uboot-2017 + Linux-4.14 FriendlyCore image has the following files:

$ tree out/
out/
├── SD-bootable-p1
│   └── your_company
│       ├── boot.img
│       ├── info.conf
│       ├── partmap.txt
│       ├── rootfs.img
│       ├── sunxi-spl.bin
│       └── u-boot.itb

If you have a bootable SD card with Eflasher, insert the SD card to a host PC, mount the SD card's rootfs directory(in our test it was mounted at the "/media/SD/rootfs-eflasher" directory) and run the following command to generate an Eflasher ROM:

$ ./mkimage.sh p2 partmap/h5_eflasher-4.14/partmap.txt misc/uboot-2017_h5/ part1/boot_linux-4.14_h5/ /media/SD/rootfs-eflasher out/SD-bootable-p1/

After running the mkimage.sh script an "out/SD-bootable-p2" directory will be generated and it will have the following files:

$ tree out/
out/
├── SD-bootable-p1
│   └── your_company
│       ├── boot.img
│       ├── info.conf
│       ├── partmap.txt
│       ├── rootfs.img
│       ├── sunxi-spl.bin
│       └── u-boot.itb
├── SD-bootable-p1.img
├── SD-bootable-p2
│   └── your_company
│       ├── boot.img
│       ├── friendlyarm.img
│       ├── info.conf
│       ├── partmap.txt
│       ├── rootfs.img
│       ├── sunxi-spl.bin
│       └── u-boot.itb
└── SD-bootable-p2.img

The SD-bootable-p2.img file will be the newly generated Eflasher ROM. What OS the "out/SD-bootable-p1/" contains will be the OS in this Eflasher ROM. You can use the win32diskimager utility under Windows or command "dd" under Linux to flash a SD-bootable-p2.img to an SD card.


5 Make Installation TF Card with Custom Image File

Quite often a user makes changes in his own system and wants to use this system for mass production. In this case a user needs to make an image based on his own system. For an Android system an image contains a boot.img and a system.img. For a Ubuntu system an image contains a rootfs.img.
This section lists instructions for users to make a custom image which can be used to make an installation SD card for mass production.
Here are the steps to make an Android image for S5P4418:

git clone https://github.com/friendlyarm/sd-fuse_nanopi2.git
cd sd-fuse_nanopi2
wget http://112.124.9.243/dvdfiles/S5P4418/images-for-eflasher/android-lollipop-images.tgz
tar xvzf android-lollipop-images.tgz

Note: for an S5P6818 SoC you can just change "sd-fuse_nanopi2.git" to "sd-fuse_nanopi3.git" and "S5P4418" to "S5P6818".
Replace the corresponding files under the "Android" directory with your newly generated files and make an installation SD card by running the following commands:

sudo ./fusing.sh /dev/sde android

Note: you need to replace the "/dev/sde" with the actual device name of your SD card in the system

Run this command to make a complete image file:

sudo ./mkimage.sh android

6 Update Log

6.1 Sep-14-2017

  • Released English Version

6.2 Jan-30-2018

  • Updated Section 3

6.3 Dec-5-2018

  • Added Sections 3 & 4