Difference between revisions of "Boot option"

From Rockchip open source Document
Jump to: navigation, search
Line 138: Line 138:
 
*For armv7 with SPL with SPL_BACK_TO_BROM option disabled:  
 
*For armv7 with SPL with SPL_BACK_TO_BROM option disabled:  
 
**idbspl.img  
 
**idbspl.img  
**uboot.bin  
+
**u-boot.bin  
 
**boot.img or boot folder with zImage, dtb and exitlinulx inside  
 
**boot.img or boot folder with zImage, dtb and exitlinulx inside  
 
**rootfs.img   
 
**rootfs.img   
Line 158: Line 158:
 
**rootfs.img   
 
**rootfs.img   
  
 
+
 
  
 
== Boot from eMMC ==
 
== Boot from eMMC ==
Line 172: Line 172:
 
*For armv7 with SPL with SPL_BACK_TO_BROM option enabled(rk3036, rk3188, rk3288):  
 
*For armv7 with SPL with SPL_BACK_TO_BROM option enabled(rk3036, rk3188, rk3288):  
 
<pre style="margin-left: 40px;">rkdeveloptool db rkxx_loader_vx.xx.bin
 
<pre style="margin-left: 40px;">rkdeveloptool db rkxx_loader_vx.xx.bin
rkdeveloptool wl 0x40 idbLoader.img
+
rkdeveloptool wl 0x40 idbloader.img
 
rkdeveloptool wl 0x8000 boot.img
 
rkdeveloptool wl 0x8000 boot.img
 
rkdeveloptool wl 0x40000 rootfs.img
 
rkdeveloptool wl 0x40000 rootfs.img
Line 181: Line 181:
 
<pre style="margin-left: 40px;">rkdeveloptool db rkxx_loader_vx.xx.bin
 
<pre style="margin-left: 40px;">rkdeveloptool db rkxx_loader_vx.xx.bin
 
rkdeveloptool wl 0x40 idbspl.img
 
rkdeveloptool wl 0x40 idbspl.img
rkdeveloptool wl 0x200 uboot.bin
+
rkdeveloptool wl 0x200 u-boot.bin
 
rkdeveloptool wl 0x8000 boot.img
 
rkdeveloptool wl 0x8000 boot.img
 
rkdeveloptool wl 0x40000 rootfs.img
 
rkdeveloptool wl 0x40000 rootfs.img
Line 189: Line 189:
 
*For armv7 with miniloader(rk3036, rk3188, rk3288)  
 
*For armv7 with miniloader(rk3036, rk3188, rk3288)  
 
<pre style="margin-left: 40px;">rkdeveloptool db rkxx_loader_vx.xx.bin
 
<pre style="margin-left: 40px;">rkdeveloptool db rkxx_loader_vx.xx.bin
rkdeveloptool wl 0x40 idbLoader.img
+
rkdeveloptool wl 0x40 idbloader.img
 
rkdeveloptool wl 0x4000 uboot.img
 
rkdeveloptool wl 0x4000 uboot.img
 
rkdeveloptool wl 0x8000 boot.img
 
rkdeveloptool wl 0x8000 boot.img
Line 195: Line 195:
 
rkdeveloptool rd
 
rkdeveloptool rd
 
</pre>
 
</pre>
 
&nbsp;
 
  
 
*For armv8 with SPL(rk3399):  
 
*For armv8 with SPL(rk3399):  
Line 208: Line 206:
  
 
*For armv8 with miniloader(rk3399, rk3328)  
 
*For armv8 with miniloader(rk3399, rk3328)  
<pre style="margin-left: 40px;">rkdeveloptool db
+
<pre style="margin-left: 40px;">rkdeveloptool db rkxx_loader_vx.xx.bin
rkdeveloptool wl 0x40 idbLoader.img
+
rkdeveloptool wl 0x40 idbloader.img
 
rkdeveloptool wl 0x4000 uboot.img
 
rkdeveloptool wl 0x4000 uboot.img
 
rkdeveloptool wl 0x6000 trust.img
 
rkdeveloptool wl 0x6000 trust.img
Line 218: Line 216:
 
== Boot from SD/TF Card ==
 
== Boot from SD/TF Card ==
  
=== Creating Image ===
+
We can write SD/TF card with Linux PC ''dd'' command very easily.
  
Follow [[Linux_user_guide|Linux user guide to]] build kernel and U-Boot.<br/> get uboot-spl.img and u-boot-dtb.img
+
Insert SD card to PC and we assume the /dev/sdb is the SD card device.
<pre>tools/mkimage -n rk3288 -T rksd -d spl/u-boot-spl-dtb.bin uboot-spl.img
 
</pre>
 
  
&nbsp;
+
*For armv7 with SPL with SPL_BACK_TO_BROM option enabled(rk3036, rk3188, rk3288):
 
+
<pre style="margin-left: 40px;">dd if=idbloader.img of=sdb seek=0x40
=== <br/> <var>build boot.img</var> ===
+
dd if=boot.img of=sdb seek=0x8000
<pre>sudo dd if=/dev/zero of=boot.img bs=1M count=128
+
dd if=rootfs.img of=sdb seek=0x40000
sudo mkfs.fat boot.img
 
mkdir boot
 
sudo mount  boot.img boot
 
sudo cp zImage boot
 
sudo cp rk3288-fennec.dtb boot
 
sudo mkdir boot/extlinux
 
sudo cp extlinux.conf boot/extlinux
 
sudo umount boot
 
 
</pre>
 
</pre>
  
Download rootfs image and rename it
+
*For armv7 with SPL with SPL_BACK_TO_BROM option disabled(rk3288):
<pre>mv linaro-rootfs.img rootfs.img
+
<pre style="margin-left: 40px;">dd if=idbspl.img of=sdb seek=0x40
 +
dd if=u-boot.bin of=sdb seek=0x200
 +
dd if=boot.img of=sdb seek=0x8000
 +
dd if=rootfs.img of=sdb seek=0x40000
 
</pre>
 
</pre>
  
&nbsp;
+
*For armv7 with miniloader(rk3036, rk3188, rk3288)
 
+
<pre style="margin-left: 40px;">dd if=idbloader.img of=sdb seek=0x40
=== Making a SD Card for updating ===
+
dd if=uboot.img of=sdb seek=0x4000
 
+
dd if=boot.img of=sdb seek=0x8000
Download&nbsp;[https://github.com/wzyy2/rk-initrd-build ramdisk source]&nbsp;and build.
+
dd if=rootfs.img of=sdb seek=0x40000
<pre>sh ./mk-initrd.sh
 
 
</pre>
 
</pre>
  
Format SD card
+
*For armv8 with SPL(rk3399):  
<pre>chen@chen-HP-ProDesk-680-G1-TWR:~/work/linaro-alip/ramdisk/update$ sudo gdisk /dev/sdb
+
<pre style="margin-left: 40px;">dd if=idbspl.img of=sdb seek=0x40
GPT fdisk (gdisk) version 0.8.8
+
dd if=bl3.itb of=sdb seek=0x200
 
+
dd if=boot.img of=sdb seek=0x8000
Partition table scan:
+
dd if=rootfs.img of=sdb seek=0x40000
  MBR: protective
 
  BSD: not present
 
  APM: not present
 
  GPT: present
 
 
 
Found valid GPT with protective MBR; using GPT.
 
 
 
Command (? for help): o
 
This option deletes all partitions and creates a new protective MBR.
 
Proceed? (Y/N): y
 
 
 
Command (? for help): n
 
Partition number (1-128, default 1): 1
 
First sector (34-126613470, default = 2048) or {+-}size{KMGTP}: 8192
 
Last sector (8192-126613470, default = 126613470) or {+-}size{KMGTP}:
 
Current type is 'Linux filesystem'
 
Hex code or GUID (L to show codes, Enter = 8300):
 
Changed type of partition to 'Linux filesystem'
 
 
 
Command (? for help): w
 
 
 
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
 
PARTITIONS!!
 
 
 
Do you want to proceed? (Y/N): y
 
OK; writing new GUID partition table (GPT) to /dev/sdc.
 
Warning: The kernel is still using the old partition table.
 
The new table will be used at the next reboot.
 
The operation has completed successfully.
 
</pre>
 
<pre>sudo umount /dev/sdb1
 
sudo mkfs.fat /dev/sdb1
 
</pre>
 
<pre>tools/mkimage -n rk3288 -T rksd -d spl/u-boot-spl-dtb.bin out&&
 
sudo dd if=out of=/dev/sdb seek=64&&sudo dd if=u-boot-dtb.img of=/dev/sdb seek=256
 
 
</pre>
 
</pre>
  
Copy zimage, dts and ramdisk to /dev/sdb1
+
*For armv8 with miniloader(rk3399, rk3328)
<pre>cp arch/arm/boot/zImage /media/chen/9F35-9565/
+
<pre style="margin-left: 40px;">dd if=idbloader.img of=sdb seek=0x40
cp arch/arm/boot/dts/rk3288-fennec.dtb /media/chen/9F35-9565/rk3288-fennec.dtb
+
dd if=uboot.img of=sdb seek=0x4000
cp ../rk-initrd-build/initrd.img /media/chen/9F35-9565/
+
dd if=trust.img of=sdb seek=0x6000
</pre>
+
dd if=boot.img of=sdb seek=0x8000
 +
dd if=rootfs.img of=sdb seek=0x40000</pre>
  
Add extlinux/extlinux.conf to /dev/sdb1
+
In order to make sure everything has write to SD card before unpluged, recommand to run below command:
<pre>label kernel-4.4
+
<pre style="margin-left: 40px;">sync</pre>
    kernel /zImage
 
    fdt /rk3288-fennec.dtb
 
    initrd /initrd.img
 
    append  earlyprintk console=ttyS2,115200n8 rw root=/dev/ram0 rootfstype=ext4 init=/sbin/init ramdisk_size=49152
 
</pre>
 
  
Copy u-boot-dtb.img uboot-spl.img boot.img rootfs.img and&nbsp;[https://github.com/wzyy2/rk-initrd-build/blob/master/update/update.sh update.sh]&nbsp;to /dev/sdb1
+
Note, when using boot from SD card, need to update the kernel cmdline(which is in extlinux.conf) for the correct ''root ''value.
<pre>mkdir /media/chen/9F35-9565/update
+
<pre>append  earlyprintk console=ttyS2,115200n8 rw '''root=/dev/mmcblk1p7''' rootwait rootfstype=ext4 init=/sbin/init
cp u-boot-dtb.img /media/chen/9F35-9565/update
 
cp uboot-spl.img /media/chen/9F35-9565/update
 
cp boot.img /media/chen/9F35-9565/update
 
cp rootfs.img /media/chen/9F35-9565/update
 
cp update.sh /media/chen/9F35-9565/update
 
 
</pre>
 
</pre>
  
=== Updating the board ===
+
Write GPT partition table to SD card&nbsp;in U-Boot, and then U-Boot can find the boot partition and run into kernel.
 +
<pre>gpt write mmc 0 $partitions</pre>
  
Boot the board and it will flash image to eMMC
+
== Boot from U-Disk ==
  
&nbsp;
+
Same as&nbsp;[[#Boot_from_SD.2FTF_Card|boot-from-sdcard]], but please note that U-Disk&nbsp;only support stage 4 and 5, see [[#Boot_Stage|Boot Stage]] for detail.
  
== Boot from USB-Disk ==
+
If U-Disk used for stage 4 and 5, format the U-Disk in gpt format and at least 2 partitions, write ''boot.img'' and ''rootfs.img'' in those partitions;
  
Same as&nbsp;[[#Boot_from_SD.2FTF_Card|boot-from-sdcard]], but please note that U-Boot aren't allowed to boot from usb-disk because of restrict of maskrom, only kernel and rootfs can load from USB-Disk.
+
if U-Dist is only used for stage 5, we can ''dd ''the ''rootfs.img'' to U-Disk device directly.
  
Difference:
+
Note, need to update the kernel cmdline(which is in extlinux.conf) for the correct ''root ''value.
<pre>label kernel-4.4
+
<pre>   append  earlyprintk console=ttyS2,115200n8 rw '''root=/dev/sda1''' rootwait rootfstype=ext4 init=/sbin/init
    kernel /zImage
 
    fdt /rk3288-fennec.dtb
 
    append  earlyprintk console=ttyS2,115200n8 rw root=/dev/sda1 rootfstype=ext4 init=/sbin/init
 
</pre>
 
<pre>gpt write usb 0 $partitions
 
ums 0 usb 0
 
 
</pre>
 
</pre>
  

Revision as of 08:13, 22 March 2017

 

 

Boot introduce

 

First, let's make the concept clear, there are many boot stages when we boot up a Linux OS;

Then we need to know about how the image should packaged, where the image locate;

At lase, we will explain how to write to different media and boot from there.

Boot stage

Here is a table show the detail what we may use in Rockchip platform, for 2 boot stage:

- optionally can use U-Boot SPL;

-  or use Rockchp idbLoader which is combinded by Rockchip ddr init bin and miniloader bin;

+--------+----------------+----------+-----------+
| Boot   | Terminology #1 | Actual   | Rockchip  |
| stage  |                | program  |  Loader   |
| number |                | name     |   Name    |
+--------+----------------+----------+-----------+
| 1      |  Primary       | ROM code | BootRom   |
|        |  Program       |          |           |
|        |  Loader        |          |           |
|        |                |          |           |
| 2      |  Secondary     | U-Boot   | idbLoader | 0x40
|        |  Program       | SPL      |           |
|        |  Loader (SPL)  |          |           |
|        |                |          |           |
| 3      |  -             | U-Boot   |  U-Boot   | 0x4000
|        |                |          |           |
|        |                |          |           |
| 4      |  -             | kernel   |  kernel   | 0x8000
|        |                |          |           |
| 5      |  -             | rootfs   |  rootfs   | 0x40000
+--------+----------------+----------+-----------+

Then when we talking about boot from eMMC/SD/U-Disk/net, they are in different concept:

  • Stage 1 is always in boot rom, it loads stage 2 and may load stage 3(when SPL_BACK_TO_BROM option enabled).
  • Boot from SPI flash means firmware for stage 2 and 3(SPL and U-Boot only) in SPI flash and stage 4/5 in other place;
  • Boot from eMMC means all the firmware(including stage 2, 3, 4, 5) in eMMC;
  • Boot from SD card means all the firmware(including stage 2, 3, 4, 5) in SD card;
  • Boot from U-Disk means firmware for stage 4 and 5(not including SPL and U-Boot) in Disk, optionally only including stage 5;
  • Boot from net/tftp means firmeware for stage 4 and 5(not including SPL and U-Boot) on the network;

Package option

After we know about the boot stages,

Here are the file list before package for stage 2~4:

  • From source code:
    • From U-Boot: u-boot-spl.bin, u-boot.bin(may use u-boot-nodtb.bin and u-boot.dtb instead),
    • From kernel: kernel Image/zImage file, kernel dtb,
    • From ATF: bl31.bin;
  • From Rockchip binary:
    • ddr, usbplug, miniloader, bl31, (all with chip 'rkxx_'  prefix and with version '_x.xx.bin' postfix);

Here are the types to package image from those files:

idbspl.img

U-Boot SPL, with SPL_BACK_TO_BROM option disabled.

mkimage -n rkxxxx -T rksd -d spl/u-boot-spl.bin idbspl.img

Flash the idbspl.img to offset 0x40 which only including stage 2, and need flash stage 3  image to 0x200(which is defineded by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR), the stage 3 image may be u-boot.bin directly(when there no ATF requirement), or FIT image bl3.itb(for ATF load from SPL, including bl31.bin, u-boot-nodtb.bin and u-boot.dtb).

idbloader.img

U-Boot SPL, with SPL_BACK_TO_BROM option enabled:

tools/mkimage -n rkxxxx -T rksd -d spl/u-boot-spl.bin idbloader.img
cat u-boot.bin >> idbloader.img

Flash the idbloader.img to offset 0x40 which including boot stage 2 and 3.

Package the image from Rockchip binary:

tools/mkimage -n rkxxxx -T rksd -d rkxx_ddr_vx.xx.bin idbloader.img
cat rkxx_miniloader_vx.xx.bin >> idbloader.img

Flash the idbloader.img to offset 0x40 which including stage 2, and you will need a uboot.img for boot stage 3.

bl3.itb

When using SPL to load the ATF, package the bl31.bin, u-boot-nodtb.bin and uboot.dtb into one FIT image.

tools/mkimage -f fit4spl.its -E bl3.itb

Flash the bl3.itb to offset 0x200, while need idbspl.img flasht to offset 0x40.

uboot.img

When using idbLoader from Rockchip miniloader, need package u-boot.bin into miniloader loadable format by Rockchip tool loaderimage.

tools/loaderimage --pack --uboot u-boot.bin uboot.img

Flash the uboot.img to offset 0x4000 which is stage 3;

trust.img

When using idbLoader from Rockchip miniloader, need package bl31.bin into miniloader loadable format by Rockchip tool trustmerge.

tools/trustmerge tools/rk_tools/RKTRUST_RKXXXXTRUST.ini

Flash the trust.img to offset 0x6000 which is for using Rockchip miniloader

rkxx_loader_vx.xx.xxx.bin

This is provide by Rockchip in binary mode, which is used for firmware upgrade to eMMC with rkdeveloptool.

boot.img

This image is package the kernel Image and dtb file into a know filesystem(FAT or EXT2) image for distro boot.

See Install kernel for detail about generate boot.img from kernel zImage/Image, dtb.

Flash the boot.img to offset 0x8000 which is stage 4.

rootfs.img

Flash the rootfs.img to offset 0x40000 which is stage 5.

Flash and boot from Media device

Here we introduce how to write image to different Medeia device.

Get image Ready:

  • For armv7 with SPL with SPL_BACK_TO_BROM option enabled:
    • idbLoader.img
    • boot.img or boot folder with zImage, dtb and exitlinulx inside
    • rootfs.img
  • For armv7 with SPL with SPL_BACK_TO_BROM option disabled:
    • idbspl.img
    • u-boot.bin
    • boot.img or boot folder with zImage, dtb and exitlinulx inside
    • rootfs.img
  • For armv7 with miniloader
    • idbLoader.img
    • uboot.img
    • boot.img or boot folder with zImage, dtb and exitlinulx inside
    • rootfs.img
  • For armv8 with SPL:
    • idbspl.img
    • bl3.itb
    • boot.img or boot folder with zImage, dtb and exitlinulx inside
    • rootfs.img
  • For armv8 with miniloader
    • idbLoader.img
    • uboot.img
    • trust.img
    • boot.img or boot folder with zImage, dtb and exitlinulx inside
    • rootfs.img

 

Boot from eMMC

The eMMC is on the hardware board, so we need:

Example commands for flash image to target.

  • For armv7 with SPL with SPL_BACK_TO_BROM option enabled(rk3036, rk3188, rk3288):
rkdeveloptool db rkxx_loader_vx.xx.bin
rkdeveloptool wl 0x40 idbloader.img
rkdeveloptool wl 0x8000 boot.img
rkdeveloptool wl 0x40000 rootfs.img
rkdeveloptool rd
  • For armv7 with SPL with SPL_BACK_TO_BROM option disabled(rk3288):
rkdeveloptool db rkxx_loader_vx.xx.bin
rkdeveloptool wl 0x40 idbspl.img
rkdeveloptool wl 0x200 u-boot.bin
rkdeveloptool wl 0x8000 boot.img
rkdeveloptool wl 0x40000 rootfs.img
rkdeveloptool rd
  • For armv7 with miniloader(rk3036, rk3188, rk3288)
rkdeveloptool db rkxx_loader_vx.xx.bin
rkdeveloptool wl 0x40 idbloader.img
rkdeveloptool wl 0x4000 uboot.img
rkdeveloptool wl 0x8000 boot.img
rkdeveloptool wl 0x40000 rootfs.img
rkdeveloptool rd
  • For armv8 with SPL(rk3399):
rkdeveloptool db rkxx_loader_vx.xx.bin
rkdeveloptool wl 0x40 idbspl.img
rkdeveloptool wl 0x200 bl3.itb
rkdeveloptool wl 0x8000 boot.img
rkdeveloptool wl 0x40000 rootfs.img
rkdeveloptool rd
  • For armv8 with miniloader(rk3399, rk3328)
rkdeveloptool db rkxx_loader_vx.xx.bin
rkdeveloptool wl 0x40 idbloader.img
rkdeveloptool wl 0x4000 uboot.img
rkdeveloptool wl 0x6000 trust.img
rkdeveloptool wl 0x8000 boot.img
rkdeveloptool wl 0x40000 rootfs.img
rkdeveloptool r

Boot from SD/TF Card

We can write SD/TF card with Linux PC dd command very easily.

Insert SD card to PC and we assume the /dev/sdb is the SD card device.

  • For armv7 with SPL with SPL_BACK_TO_BROM option enabled(rk3036, rk3188, rk3288):
dd if=idbloader.img of=sdb seek=0x40
dd if=boot.img of=sdb seek=0x8000
dd if=rootfs.img of=sdb seek=0x40000
  • For armv7 with SPL with SPL_BACK_TO_BROM option disabled(rk3288):
dd if=idbspl.img of=sdb seek=0x40
dd if=u-boot.bin of=sdb seek=0x200
dd if=boot.img of=sdb seek=0x8000
dd if=rootfs.img of=sdb seek=0x40000
  • For armv7 with miniloader(rk3036, rk3188, rk3288)
dd if=idbloader.img of=sdb seek=0x40
dd if=uboot.img of=sdb seek=0x4000
dd if=boot.img of=sdb seek=0x8000
dd if=rootfs.img of=sdb seek=0x40000
  • For armv8 with SPL(rk3399):
dd if=idbspl.img of=sdb seek=0x40
dd if=bl3.itb of=sdb seek=0x200
dd if=boot.img of=sdb seek=0x8000
dd if=rootfs.img of=sdb seek=0x40000
  • For armv8 with miniloader(rk3399, rk3328)
dd if=idbloader.img of=sdb seek=0x40
dd if=uboot.img of=sdb seek=0x4000
dd if=trust.img of=sdb seek=0x6000
dd if=boot.img of=sdb seek=0x8000
dd if=rootfs.img of=sdb seek=0x40000

In order to make sure everything has write to SD card before unpluged, recommand to run below command:

sync

Note, when using boot from SD card, need to update the kernel cmdline(which is in extlinux.conf) for the correct root value.

append  earlyprintk console=ttyS2,115200n8 rw '''root=/dev/mmcblk1p7''' rootwait rootfstype=ext4 init=/sbin/init

Write GPT partition table to SD card in U-Boot, and then U-Boot can find the boot partition and run into kernel.

gpt write mmc 0 $partitions

Boot from U-Disk

Same as boot-from-sdcard, but please note that U-Disk only support stage 4 and 5, see Boot Stage for detail.

If U-Disk used for stage 4 and 5, format the U-Disk in gpt format and at least 2 partitions, write boot.img and rootfs.img in those partitions;

if U-Dist is only used for stage 5, we can dd the rootfs.img to U-Disk device directly.

Note, need to update the kernel cmdline(which is in extlinux.conf) for the correct root value.

    append  earlyprintk console=ttyS2,115200n8 rw '''root=/dev/sda1''' rootwait rootfstype=ext4 init=/sbin/init

Boot from Network