http://opensource.rock-chips.com/api.php?action=feedcontributions&user=Ayaka&feedformat=atomRockchip open source Document - User contributions [en]2024-03-29T06:49:11ZUser contributionsMediaWiki 1.28.0http://opensource.rock-chips.com/index.php?title=Boot_option&diff=1689Boot option2017-12-07T02:40:16Z<p>Ayaka: Adjust the organization of the SPL and u-boot sections, following the boot order.</p>
<hr />
<div><br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
<br />
= Boot introduce =<br />
<br />
&nbsp;<br />
<br />
First, let's make the concept clear, there are many boot stages when we boot up a Linux OS;<br />
<br />
Then we need to know about how the image should packaged, where&nbsp;the image locate;<br />
<br />
At last, we will explain how to write to different&nbsp;media and boot from there.<br />
<br />
Here is Rockchip pre-released binaries which may be mentioned later:<br />
<br />
[https://github.com/rockchip-linux/rkbin https://github.com/rockchip-linux/rkbin]<br />
<br />
And [http://opensource.rock-chips.com/wiki_Partitions Rockcip Linux GPT partition] here.<br />
<br />
&nbsp;<br />
<br />
== Boot flow ==<br />
<br />
Here is a table show the detail what we may use in Rockchip platform, for 2 boot stage:<br />
<br />
- use U-Boot SPL;<br />
<br />
- use Rockchp idbLoader which is combinded by Rockchip ddr init bin and miniloader bin;<br />
<pre>+--------+----------------+----------+-------------+---------+<br />
| Boot | Terminology #1 | Actual | Rockchip | |<br />
| stage | | program | Image | |<br />
| number | | name | Name | |<br />
+--------+----------------+----------+-------------+---------+<br />
| 1 | Primary | ROM code | BootRom | |<br />
| | Program | | | |<br />
| | Loader | | | |<br />
| | | | | |<br />
| 2 | Secondary | U-Boot |idbloader.img| 0x40 |including u-boot if not use miniloader<br />
| | Program | SPL |idbspl.img | |<br />
| | Loader (SPL) | | | |<br />
| | | | | |<br />
| 3 | - | U-Boot | u-boot.itb | 0x4000 | including u-boot and atf<br />
| | | | u-boot.bin | 0x4000 |<br />
| | | | uboot.img | 0x4000 | only used with miniloader<br />
| | | | | |<br />
| | | ATF | trust.img | 0x6000 | only used with miniloader for armv8<br />
| | | | | |<br />
| 4 | - | kernel | boot.img | 0x8000 |<br />
| | | | | |<br />
| 5 | - | rootfs | rootfs.img | 0x40000 |<br />
+--------+----------------+----------+-------------+---------+<br />
</pre><br />
<br />
Then when we talking about boot from eMMC/SD/U-Disk/net, they are in different concept:<br />
<br />
*Stage 1 is always in boot rom, it loads stage 2 and may load stage 3(when SPL_BACK_TO_BROM option enabled). <br />
*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; <br />
*Boot from eMMC means all the firmware(including stage 2, 3, 4, 5) in eMMC; <br />
*Boot from SD card means all the firmware(including stage 2, 3, 4, 5) in SD card; <br />
*Boot from U-Disk means firmware for stage 4 and 5(not including SPL and U-Boot) in Disk, optionally only including stage 5; <br />
*Boot from net/tftp means firmeware for stage 4 and 5(not including SPL and U-Boot) on the network; <br />
<br />
&nbsp;<br />
<br />
[[File:Rockchip bootflow.jpg|1000x1000px|Rockchip bootflow.jpg]]<br />
<br />
Boot Flow 1 is typical Rockchip boot flow with Rockchip miniloader;<br/> Boot Flow 2 is used for most SoCs with U-Boot TPL for ddr init and SPL for trust(ATF/OP-TEE) load and run into next stage;<br/> Boot Flow 3 is use only for RK3399 with SPL ATF support;<br/> Boot Flow 4 is used for armv7 SoCs which do not support trust;<br/> <br/> Note 1. If loader1 have more than 1 stage, program will back to bootrom and bootrom load and run into next stage. eg. If loader1 is tpl and spl, the bootrom will run into tpl first, tpl init ddr and back to bootrom, bootrom then load and run into spl.<br/> Note 2. If trust is enabled, loader1 need to load both trust and u-boot, and then run into trust in secure mode(EL3 in armv8), trust do the initialize and run into U-Boot in non-secure mode(EL2 in armv8).<br/> Note 3. For trust(in trust.img or u-boot.itb), armv7 has only one tee.bin with or without ta, armv8 has bl31.elf and option with bl32.<br/> Note 4. In boot.img, content can be zImage and its dtb for Linux, and can optionally be grub.efi, and can be AOSP boot.img, ramdisk is option;<br />
<br />
<br />
<br />
<br />
<br />
== Package option ==<br />
<br />
After we know about the boot stages,<br />
<br />
Here are the file list before package for stage 2~4:<br />
<br />
*From source code: <br />
**From U-Boot: '''u-boot-spl.bin''', '''u-boot.bin'''(may use u-boot-nodtb.bin and u-boot.dtb instead), <br />
**From kernel: kernel '''Image/zImage''' file, kernel dtb, <br />
**From ATF: '''bl31.elf'''; <br />
*From Rockchip binary: <br />
**ddr, usbplug, miniloader, bl31/op-tee, (all with&nbsp;chip 'rkxx_'&nbsp; prefix and with version '_x.xx.bin' postfix); <br />
<br />
We offer two different boot-loader methods for different solutions, the steps and request files are also complete different. But not all the platforms supports the both boot-loader methods. Here are the types to&nbsp;package image from those files:<br />
<br />
=== The Pre-bootloader(TBL/SPL) ===<br />
<br />
==== idbspl.img ====<br />
<br />
U-Boot SPL, with&nbsp;SPL_BACK_TO_BROM option '''disabled'''.<br />
<pre>mkimage -n rkxxxx -T rksd -d spl/u-boot-spl.bin idbspl.img</pre><br />
<br />
Flash the idbspl.img to offset 0x40 which only including stage 2, and need flash stage 3 &nbsp;image to 0x200(which is defineded by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR), the stage 3 image may be&nbsp;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).<br />
<br />
&nbsp;<br />
<br />
==== idbloader.img ====<br />
<br />
U-Boot SPL, with&nbsp;SPL_BACK_TO_BROM option '''enabled''':<br />
<pre>tools/mkimage -n rkxxxx -T rksd -d spl/u-boot-spl.bin idbloader.img<br />
cat u-boot.bin >> idbloader.img</pre><br />
<br />
Flash the idbloader.img to offset 0x40 which including boot stage 2 and 3.<br />
<br />
==== Rockchip Miniloader ====<br />
<br />
Package the image from Rockchip binary:<br />
<pre>dd if=rkxx_ddr_vx.xx.bin of=ddr.bin bs=4 skip=1<br />
tools/mkimage -n rkxxxx -T rksd -d ddr.bin idbloader.img<br />
rm ddr.bin<br />
cat rkxx_miniloader_vx.xx.bin >> idbloader.img</pre><br />
<br />
The ddr binary files for ARM64 platforms from Rockchip, likes RK3399 and RK3328 should not skip first 4 bytes.<br />
<pre>tools/mkimage -n rkxxxx -T rksd -d rkxx_ddr_vx.xx.bin idbloader.img<br />
rm ddr.bin<br />
cat rkxx_miniloader_vx.xx.bin >> idbloader.img</pre><br />
<br />
Flash the idbloader.img to offset 0x40 which including stage 2, and you will need a uboot.img for boot stage 3.<br />
<br />
=== U-Boot ===<br />
<br />
==== u-boot.itb ====<br />
<br />
When using SPL to load the ATF/OP-TEE, package the bl31.bin, u-boot-nodtb.bin and uboot.dtb into one FIT image. You can skip the step to package the Trust image and flash that image in the next section.<br />
<pre>make u-boot.itb<br />
</pre><br />
<br />
Note: please copy the trust binary() to u-boot root directory and rename it to tee.bin(armv7) or bl31.elf(armv8).<br />
<br />
Flash the u-boot.itb to offset 0x4000, while&nbsp;need idbspl.img flash&nbsp;to offset 0x40.<br />
<br />
==== uboot.img ====<br />
<br />
When using idbLoader from&nbsp;Rockchip miniloader, need package u-boot.bin into miniloader loadable format by Rockchip tool loaderimage.<br />
<pre>tools/loaderimage --pack --uboot u-boot.bin uboot.img</pre><br />
<br />
Flash the uboot.img to offset 0x4000 which is stage 3;<br />
<br />
=== Trust ===<br />
<br />
When using idbLoader from&nbsp;Rockchip miniloader, need package bl31.bin into miniloader loadable format by Rockchip tool trustmerge.<br />
<pre>tools/trustmerge tools/rk_tools/RKTRUST_RKXXXXTRUST.ini</pre><br />
<br />
Flash the trust.img to offset 0x6000 which is for using Rockchip miniloader<br />
<br />
=== boot.img ===<br />
<br />
This image is package the kernel Image and dtb file into a know filesystem(FAT or EXT2) image for distro boot.<br />
<br />
See [[Rockchip_Kernel#Install_Boot.2Fkernel|Install kernel]] for detail about generate boot.img from kernel zImage/Image, dtb.<br />
<br />
Flash the boot.img to offset 0x8000 which is stage 4.<br />
<br />
=== rootfs.img ===<br />
<br />
Flash the rootfs.img to offset 0x40000 which is stage 5. As long as the kernel you chosen can support that filesystem, there is not limit in the format of the image.<br />
<br />
=== rkxx_loader_vx.xx.xxx.bin ===<br />
<br />
This is provide by Rockchip in binary mode, which is used for firmware upgrade to eMMC with [[Rkdeveloptool|rkdeveloptool]], can not be wirte to media device directly.<br />
<br />
This is a package from ddr.bin, usbplug.bin, miniloader.bin, Rockchip tool ''DB ''command will make usbplug.bin running in target which perform as a Rockusb device. You can skip to package this image, Rockchip will offer this image at the most of time.<br />
<br />
= Flash and boot from Media device =<br />
<br />
Here we introduce how to write image to different Medeia device.<br />
<br />
Get image Ready:<br />
<br />
*For armv7 with SPL with SPL_BACK_TO_BROM option enabled: <br />
**idbLoader.img <br />
**boot.img or boot folder with zImage, dtb and exitlinulx inside <br />
**rootfs.img <br />
*For armv7 with SPL with SPL_BACK_TO_BROM option disabled: <br />
**idbspl.img <br />
**u-boot.bin <br />
**boot.img or boot folder with zImage, dtb and exitlinulx inside <br />
**rootfs.img <br />
*For armv7 with miniloader <br />
**idbLoader.img <br />
**uboot.img <br />
**boot.img or&nbsp;boot folder with zImage, dtb and exitlinulx inside <br />
**rootfs.img <br />
*For armv8 with SPL: <br />
**idbspl.img <br />
**bl3.itb <br />
**boot.img or&nbsp;boot folder with Image, dtb and exitlinulx inside <br />
**rootfs.img <br />
*For armv8 with miniloader <br />
**idbLoader.img <br />
**uboot.img <br />
**trust.img <br />
**boot.img or&nbsp;boot folder with Image, dtb and exitlinulx inside <br />
**rootfs.img <br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
== Boot from eMMC ==<br />
<br />
The eMMC is on the hardware board, so we need:<br />
<br />
*Get the board into [[Rockusb#Maskrom_mode|maskrom mode]]; <br />
*Connect the target to PC with USB cable; <br />
*Flash the image to eMMC with [[Rkdeveloptool|rkdeveloptool]] <br />
<br />
Example commands for flash image to target.<br />
<br />
Flash the gpt partition to target:<br />
<pre style="margin-left: 40px;">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool gpt parameter_gpt.txt</pre><br />
<br />
*For armv7 with SPL with SPL_BACK_TO_BROM option enabled(rk3036, rk3188, rk3288): <br />
<pre style="margin-left: 40px">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool wl 0x40 idbloader.img<br />
rkdeveloptool wl 0x8000 boot.img<br />
rkdeveloptool wl 0x40000 rootfs.img<br />
rkdeveloptool rd<br />
</pre><br />
<br />
*For armv7 with SPL with SPL_BACK_TO_BROM option disabled(rk3288): <br />
<pre style="margin-left: 40px">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool wl 0x40 idbspl.img<br />
rkdeveloptool wl 0x200 u-boot.bin<br />
rkdeveloptool wl 0x8000 boot.img<br />
rkdeveloptool wl 0x40000 rootfs.img<br />
rkdeveloptool rd<br />
</pre><br />
<br />
*For armv7 with miniloader(rk3036, rk3188, rk3288) <br />
<pre style="margin-left: 40px">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool wl 0x40 idbloader.img<br />
rkdeveloptool wl 0x4000 uboot.img<br />
rkdeveloptool wl 0x8000 boot.img<br />
rkdeveloptool wl 0x40000 rootfs.img<br />
rkdeveloptool rd<br />
</pre><br />
<br />
*For armv8 with SPL(rk3399): <br />
<pre style="margin-left: 40px">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool wl 0x40 idbspl.img<br />
rkdeveloptool wl 0x200 bl3.itb<br />
rkdeveloptool wl 0x8000 boot.img<br />
rkdeveloptool wl 0x40000 rootfs.img<br />
rkdeveloptool rd<br />
</pre><br />
<br />
*For armv8 with miniloader(rk3399, rk3328) <br />
<pre style="margin-left: 40px">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool wl 0x40 idbloader.img<br />
rkdeveloptool wl 0x4000 uboot.img<br />
rkdeveloptool wl 0x6000 trust.img<br />
rkdeveloptool wl 0x8000 boot.img<br />
rkdeveloptool wl 0x40000 rootfs.img<br />
rkdeveloptool rd</pre><br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
== Boot from SD/TF Card ==<br />
<br />
We can write SD/TF card with Linux PC ''dd'' command very easily.<br />
<br />
Insert SD card to PC and we assume the /dev/sdb is the SD card device.<br />
<br />
*For armv7 with SPL with SPL_BACK_TO_BROM option enabled(rk3036, rk3188, rk3288): <br />
<pre style="margin-left: 40px">dd if=idbloader.img of=sdb seek=64<br />
dd if=boot.img of=sdb seek=32768<br />
dd if=rootfs.img of=sdb seek=262144<br />
</pre><br />
<br />
*For armv7 with SPL with SPL_BACK_TO_BROM option disabled(rk3288): <br />
<pre style="margin-left: 40px">dd if=idbspl.img of=sdb seek=64<br />
dd if=u-boot.bin of=sdb seek=512<br />
dd if=boot.img of=sdb seek=32768<br />
dd if=rootfs.img of=sdb seek=262144<br />
</pre><br />
<br />
*For armv7 with miniloader(rk3036, rk3188, rk3288) <br />
<pre style="margin-left: 40px">dd if=idbloader.img of=sdb seek=64<br />
dd if=uboot.img of=sdb seek=16384<br />
dd if=boot.img of=sdb seek=32768<br />
dd if=rootfs.img of=sdb seek=262144<br />
</pre><br />
<br />
*For armv8 with SPL(rk3399): <br />
<pre style="margin-left: 40px">dd if=idbspl.img of=sdb seek=64<br />
dd if=bl3.itb of=sdb seek=512<br />
dd if=boot.img of=sdb seek=32768<br />
dd if=rootfs.img of=sdb seek=262144<br />
</pre><br />
<br />
*For armv8 with miniloader(rk3399, rk3328) <br />
<pre style="margin-left: 40px">dd if=idbloader.img of=sdb seek=64<br />
dd if=uboot.img of=sdb seek=16384<br />
dd if=trust.img of=sdb seek=24576<br />
dd if=boot.img of=sdb seek=32768<br />
dd if=rootfs.img of=sdb seek=262144</pre><br />
<br />
In order to make sure everything has write to SD card before unpluged, recommand to run below command:<br />
<pre style="margin-left: 40px">sync</pre><br />
<br />
Note, when using boot from SD card, need to update the kernel cmdline(which is in extlinux.conf) for the correct ''root ''value.<br />
<pre>append earlyprintk console=ttyS2,115200n8 rw root=/dev/mmcblk1p7 rootwait rootfstype=ext4 init=/sbin/init<br />
</pre><br />
<br />
Write GPT partition table to SD card&nbsp;in U-Boot, and then U-Boot can find the boot partition and run into kernel.<br />
<pre>gpt write mmc 0 $partitions</pre><br />
<br />
&nbsp;<br />
<br />
== Boot from U-Disk ==<br />
<br />
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.<br />
<br />
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;<br />
<br />
if U-Dist is only used for stage 5, we can ''dd ''the ''rootfs.img'' to U-Disk device directly.<br />
<br />
Note, need to update the kernel cmdline(which is in extlinux.conf) for the correct ''root ''value.<br />
<pre> append earlyprintk console=ttyS2,115200n8 rw root=/dev/sda1 rootwait rootfstype=ext4 init=/sbin/init<br />
</pre><br />
<br />
== Boot from Network ==<br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
= See also =<br />
<br />
[[Rkdeveloptool|rkdeveloptool]]<br />
<br />
[[Rockusb|rockusb]]<br />
<br />
[[Partitions|Rockchip Linux partition definition]]</div>Ayakahttp://opensource.rock-chips.com/index.php?title=Boot_option&diff=1554Boot option2017-11-20T03:38:05Z<p>Ayaka: Split the first bootloader method into two sections</p>
<hr />
<div><br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
<br />
= Boot introduce =<br />
<br />
&nbsp;<br />
<br />
First, let's make the concept clear, there are many boot stages when we boot up a Linux OS;<br />
<br />
Then we need to know about how the image should packaged, where&nbsp;the image locate;<br />
<br />
At last, we will explain how to write to different&nbsp;media and boot from there.<br />
<br />
Here is Rockchip pre-released binaries which may be mentioned later:<br />
<br />
[https://github.com/rockchip-linux/rkbin https://github.com/rockchip-linux/rkbin]<br />
<br />
And [http://opensource.rock-chips.com/wiki_Partitions Rockcip Linux GPT partition] here.<br />
<br />
&nbsp;<br />
<br />
== Boot flow ==<br />
<br />
Here is a table show the detail what we may use in Rockchip platform, for 2 boot stage:<br />
<br />
- use U-Boot SPL;<br />
<br />
- use Rockchp idbLoader which is combinded by Rockchip ddr init bin and miniloader bin;<br />
<pre>+--------+----------------+----------+-------------+---------+<br />
| Boot | Terminology #1 | Actual | Rockchip | |<br />
| stage | | program | Image | |<br />
| number | | name | Name | |<br />
+--------+----------------+----------+-------------+---------+<br />
| 1 | Primary | ROM code | BootRom | |<br />
| | Program | | | |<br />
| | Loader | | | |<br />
| | | | | |<br />
| 2 | Secondary | U-Boot |idbloader.img| 0x40 |including u-boot if not use miniloader<br />
| | Program | SPL |idbspl.img | |<br />
| | Loader (SPL) | | | |<br />
| | | | | |<br />
| 3 | - | U-Boot | u-boot.itb | 0x4000 | including u-boot and atf<br />
| | | | u-boot.bin | 0x4000 |<br />
| | | | uboot.img | 0x4000 | only used with miniloader<br />
| | | | | |<br />
| | | ATF | trust.img | 0x6000 | only used with miniloader for armv8<br />
| | | | | |<br />
| 4 | - | kernel | boot.img | 0x8000 |<br />
| | | | | |<br />
| 5 | - | rootfs | rootfs.img | 0x40000 |<br />
+--------+----------------+----------+-------------+---------+<br />
</pre><br />
<br />
Then when we talking about boot from eMMC/SD/U-Disk/net, they are in different concept:<br />
<br />
*Stage 1 is always in boot rom, it loads stage 2 and may load stage 3(when SPL_BACK_TO_BROM option enabled). <br />
*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; <br />
*Boot from eMMC means all the firmware(including stage 2, 3, 4, 5) in eMMC; <br />
*Boot from SD card means all the firmware(including stage 2, 3, 4, 5) in SD card; <br />
*Boot from U-Disk means firmware for stage 4 and 5(not including SPL and U-Boot) in Disk, optionally only including stage 5; <br />
*Boot from net/tftp means firmeware for stage 4 and 5(not including SPL and U-Boot) on the network; <br />
<br />
&nbsp;<br />
<br />
[[File:Rockchip bootflow.jpg|1000x1000px|Rockchip bootflow.jpg]]<br />
<br />
Boot Flow 1 is typical Rockchip boot flow with Rockchip miniloader;<br/> Boot Flow 2 is used for most SoCs with U-Boot TPL for ddr init and SPL for trust(ATF/OP-TEE) load and run into next stage;<br/> Boot Flow 3 is use only for RK3399 with SPL ATF support;<br/> Boot Flow 4 is used for armv7 SoCs which do not support trust;<br/> <br/> Note 1. If loader1 have more than 1 stage, program will back to bootrom and bootrom load and run into next stage. eg. If loader1 is tpl and spl, the bootrom will run into tpl first, tpl init ddr and back to bootrom, bootrom then load and run into spl.<br/> Note 2. If trust is enabled, loader1 need to load both trust and u-boot, and then run into trust in secure mode(EL3 in armv8), trust do the initialize and run into U-Boot in non-secure mode(EL2 in armv8).<br/> Note 3. For trust(in trust.img or u-boot.itb), armv7 has only one tee.bin with or without ta, armv8 has bl31.elf and option with bl32.<br/> Note 4. In boot.img, content can be zImage and its dtb for Linux, and can optionally be grub.efi, and can be AOSP boot.img, ramdisk is option;<br />
<br />
<br />
<br />
<br />
== Package option ==<br />
<br />
After we know about the boot stages,<br />
<br />
Here are the file list before package for stage 2~4:<br />
<br />
*From source code: <br />
**From U-Boot: '''u-boot-spl.bin''', '''u-boot.bin'''(may use u-boot-nodtb.bin and u-boot.dtb instead), <br />
**From kernel: kernel '''Image/zImage''' file, kernel dtb, <br />
**From ATF: '''bl31.elf'''; <br />
*From Rockchip binary: <br />
**ddr, usbplug, miniloader, bl31/op-tee, (all with&nbsp;chip 'rkxx_'&nbsp; prefix and with version '_x.xx.bin' postfix); <br />
<br />
We offer two different boot-loader methods for different solutions, the steps and request files are also complete different. But not all the platforms supports the both boot-loader methods. Here are the types to&nbsp;package image from those files:<br />
<br />
=== Using U-Boot SPL as the first bootloader ===<br />
<br />
==== idbspl.img ====<br />
<br />
U-Boot SPL, with&nbsp;SPL_BACK_TO_BROM option '''disabled'''.<br />
<pre>mkimage -n rkxxxx -T rksd -d spl/u-boot-spl.bin idbspl.img</pre><br />
<br />
Flash the idbspl.img to offset 0x40 which only including stage 2, and need flash stage 3 &nbsp;image to 0x200(which is defineded by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR), the stage 3 image may be&nbsp;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).<br />
<br />
&nbsp;<br />
<br />
==== u-boot.itb ====<br />
<br />
When using SPL to load the ATF/OP-TEE, package the bl31.bin, u-boot-nodtb.bin and uboot.dtb into one FIT image.<br />
<pre>make u-boot.itb<br />
</pre><br />
<br />
Note: please copy the trust binary() to u-boot root directory and rename it to tee.bin(armv7) or bl31.elf(armv8).<br />
<br />
Flash the bl3.itb to offset 0x4000, while&nbsp;need idbspl.img flash&nbsp;to offset 0x40.<br />
<br />
=== Using Miniloader as the first bootloader ===<br />
<br />
==== idbloader.img ====<br />
<br />
U-Boot SPL, with&nbsp;SPL_BACK_TO_BROM option '''enabled''':<br />
<pre>tools/mkimage -n rkxxxx -T rksd -d spl/u-boot-spl.bin idbloader.img<br />
cat u-boot.bin >> idbloader.img</pre><br />
<br />
Flash the idbloader.img to offset 0x40 which including boot stage 2 and 3.<br />
<br />
Package the image from Rockchip binary:<br />
<pre>dd if=rkxx_ddr_vx.xx.bin of=ddr.bin bs=4 skip=1<br />
tools/mkimage -n rkxxxx -T rksd -d ddr.bin idbloader.img<br />
rm ddr.bin<br />
cat rkxx_miniloader_vx.xx.bin >> idbloader.img</pre><br />
<br />
Flash the idbloader.img to offset 0x40 which including stage 2, and you will need a uboot.img for boot stage 3.<br />
<br />
&nbsp;<br />
<br />
==== uboot.img ====<br />
<br />
When using idbLoader from&nbsp;Rockchip miniloader, need package u-boot.bin into miniloader loadable format by Rockchip tool loaderimage.<br />
<pre>tools/loaderimage --pack --uboot u-boot.bin uboot.img</pre><br />
<br />
Flash the uboot.img to offset 0x4000 which is stage 3;<br />
<br />
==== trust.img ====<br />
<br />
When using idbLoader from&nbsp;Rockchip miniloader, need package bl31.bin into miniloader loadable format by Rockchip tool trustmerge.<br />
<pre>tools/trustmerge tools/rk_tools/RKTRUST_RKXXXXTRUST.ini</pre><br />
<br />
Flash the trust.img to offset 0x6000 which is for using Rockchip miniloader<br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
=== rkxx_loader_vx.xx.xxx.bin ===<br />
<br />
This is provide by Rockchip in binary mode, which is used for firmware upgrade to eMMC with [[Rkdeveloptool|rkdeveloptool]], can not be wirte to media device directly.<br />
<br />
This is a package from ddr.bin, usbplug.bin, miniloader.bin, Rockchip tool ''DB ''command will make usbplug.bin running in target which perform as a Rockusb device.<br />
<br />
=== boot.img ===<br />
<br />
This image is package the kernel Image and dtb file into a know filesystem(FAT or EXT2) image for distro boot.<br />
<br />
See [[Rockchip_Kernel#Install_Boot.2Fkernel|Install kernel]] for detail about generate boot.img from kernel zImage/Image, dtb.<br />
<br />
Flash the boot.img to offset 0x8000 which is stage 4.<br />
<br />
=== rootfs.img ===<br />
<br />
Flash the rootfs.img to offset 0x40000 which is stage 5. As long as the kernel you chosen can support that filesystem, there is not limit in the format of the image.<br />
<br />
&nbsp;<br />
<br />
= Flash and boot from Media device =<br />
<br />
Here we introduce how to write image to different Medeia device.<br />
<br />
Get image Ready:<br />
<br />
*For armv7 with SPL with SPL_BACK_TO_BROM option enabled: <br />
**idbLoader.img <br />
**boot.img or boot folder with zImage, dtb and exitlinulx inside <br />
**rootfs.img <br />
*For armv7 with SPL with SPL_BACK_TO_BROM option disabled: <br />
**idbspl.img <br />
**u-boot.bin <br />
**boot.img or boot folder with zImage, dtb and exitlinulx inside <br />
**rootfs.img <br />
*For armv7 with miniloader <br />
**idbLoader.img <br />
**uboot.img <br />
**boot.img or&nbsp;boot folder with zImage, dtb and exitlinulx inside <br />
**rootfs.img <br />
*For armv8 with SPL: <br />
**idbspl.img <br />
**bl3.itb <br />
**boot.img or&nbsp;boot folder with Image, dtb and exitlinulx inside <br />
**rootfs.img <br />
*For armv8 with miniloader <br />
**idbLoader.img <br />
**uboot.img <br />
**trust.img <br />
**boot.img or&nbsp;boot folder with Image, dtb and exitlinulx inside <br />
**rootfs.img <br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
== Boot from eMMC ==<br />
<br />
The eMMC is on the hardware board, so we need:<br />
<br />
*Get the board into [[Rockusb#Maskrom_mode|maskrom mode]]; <br />
*Connect the target to PC with USB cable; <br />
*Flash the image to eMMC with [[Rkdeveloptool|rkdeveloptool]] <br />
<br />
Example commands for flash image to target.<br />
<br />
Flash the gpt partition to target:<br />
<pre style="margin-left: 40px;">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool gpt parameter_gpt.txt</pre><br />
<br />
*For armv7 with SPL with SPL_BACK_TO_BROM option enabled(rk3036, rk3188, rk3288): <br />
<pre style="margin-left: 40px">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool wl 0x40 idbloader.img<br />
rkdeveloptool wl 0x8000 boot.img<br />
rkdeveloptool wl 0x40000 rootfs.img<br />
rkdeveloptool rd<br />
</pre><br />
<br />
*For armv7 with SPL with SPL_BACK_TO_BROM option disabled(rk3288): <br />
<pre style="margin-left: 40px">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool wl 0x40 idbspl.img<br />
rkdeveloptool wl 0x200 u-boot.bin<br />
rkdeveloptool wl 0x8000 boot.img<br />
rkdeveloptool wl 0x40000 rootfs.img<br />
rkdeveloptool rd<br />
</pre><br />
<br />
*For armv7 with miniloader(rk3036, rk3188, rk3288) <br />
<pre style="margin-left: 40px">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool wl 0x40 idbloader.img<br />
rkdeveloptool wl 0x4000 uboot.img<br />
rkdeveloptool wl 0x8000 boot.img<br />
rkdeveloptool wl 0x40000 rootfs.img<br />
rkdeveloptool rd<br />
</pre><br />
<br />
*For armv8 with SPL(rk3399): <br />
<pre style="margin-left: 40px">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool wl 0x40 idbspl.img<br />
rkdeveloptool wl 0x200 bl3.itb<br />
rkdeveloptool wl 0x8000 boot.img<br />
rkdeveloptool wl 0x40000 rootfs.img<br />
rkdeveloptool rd<br />
</pre><br />
<br />
*For armv8 with miniloader(rk3399, rk3328) <br />
<pre style="margin-left: 40px">rkdeveloptool db rkxx_loader_vx.xx.bin<br />
rkdeveloptool wl 0x40 idbloader.img<br />
rkdeveloptool wl 0x4000 uboot.img<br />
rkdeveloptool wl 0x6000 trust.img<br />
rkdeveloptool wl 0x8000 boot.img<br />
rkdeveloptool wl 0x40000 rootfs.img<br />
rkdeveloptool rd</pre><br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
== Boot from SD/TF Card ==<br />
<br />
We can write SD/TF card with Linux PC ''dd'' command very easily.<br />
<br />
Insert SD card to PC and we assume the /dev/sdb is the SD card device.<br />
<br />
*For armv7 with SPL with SPL_BACK_TO_BROM option enabled(rk3036, rk3188, rk3288): <br />
<pre style="margin-left: 40px">dd if=idbloader.img of=sdb seek=64<br />
dd if=boot.img of=sdb seek=32768<br />
dd if=rootfs.img of=sdb seek=262144<br />
</pre><br />
<br />
*For armv7 with SPL with SPL_BACK_TO_BROM option disabled(rk3288): <br />
<pre style="margin-left: 40px">dd if=idbspl.img of=sdb seek=64<br />
dd if=u-boot.bin of=sdb seek=512<br />
dd if=boot.img of=sdb seek=32768<br />
dd if=rootfs.img of=sdb seek=262144<br />
</pre><br />
<br />
*For armv7 with miniloader(rk3036, rk3188, rk3288) <br />
<pre style="margin-left: 40px">dd if=idbloader.img of=sdb seek=64<br />
dd if=uboot.img of=sdb seek=16384<br />
dd if=boot.img of=sdb seek=32768<br />
dd if=rootfs.img of=sdb seek=262144<br />
</pre><br />
<br />
*For armv8 with SPL(rk3399): <br />
<pre style="margin-left: 40px">dd if=idbspl.img of=sdb seek=64<br />
dd if=bl3.itb of=sdb seek=512<br />
dd if=boot.img of=sdb seek=32768<br />
dd if=rootfs.img of=sdb seek=262144<br />
</pre><br />
<br />
*For armv8 with miniloader(rk3399, rk3328) <br />
<pre style="margin-left: 40px">dd if=idbloader.img of=sdb seek=64<br />
dd if=uboot.img of=sdb seek=16384<br />
dd if=trust.img of=sdb seek=24576<br />
dd if=boot.img of=sdb seek=32768<br />
dd if=rootfs.img of=sdb seek=262144</pre><br />
<br />
In order to make sure everything has write to SD card before unpluged, recommand to run below command:<br />
<pre style="margin-left: 40px">sync</pre><br />
<br />
Note, when using boot from SD card, need to update the kernel cmdline(which is in extlinux.conf) for the correct ''root ''value.<br />
<pre>append earlyprintk console=ttyS2,115200n8 rw root=/dev/mmcblk1p7 rootwait rootfstype=ext4 init=/sbin/init<br />
</pre><br />
<br />
Write GPT partition table to SD card&nbsp;in U-Boot, and then U-Boot can find the boot partition and run into kernel.<br />
<pre>gpt write mmc 0 $partitions</pre><br />
<br />
&nbsp;<br />
<br />
== Boot from U-Disk ==<br />
<br />
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.<br />
<br />
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;<br />
<br />
if U-Dist is only used for stage 5, we can ''dd ''the ''rootfs.img'' to U-Disk device directly.<br />
<br />
Note, need to update the kernel cmdline(which is in extlinux.conf) for the correct ''root ''value.<br />
<pre> append earlyprintk console=ttyS2,115200n8 rw root=/dev/sda1 rootwait rootfstype=ext4 init=/sbin/init<br />
</pre><br />
<br />
== Boot from Network ==<br />
<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
= See also =<br />
<br />
[[Rkdeveloptool|rkdeveloptool]]<br />
<br />
[[Rockusb|rockusb]]<br />
<br />
[[Partitions|Rockchip Linux partition definition]]</div>Ayaka