Open main menu

DAVE Developer's Wiki β

Changes

Standalone boot (SDVX)

7,485 bytes added, 14:31, 22 October 2018
Program root file system into eMMC flash
{{ImportantMessage|text=The following programming examples are intended for <b>laboratory usage</b> or for ''preliminary deployment strategy''.<br><br>A complete deployment strategy has to be carefully identifiyed taking into account the overall arguments like: boot speed, safe boot, recovery mechanisms, watchdog supervisor, etc.}}
 
 
We'll explain how to program and configure an [[:Category:SDVX |SDVX]] to boot in standalone mode, without the need of a system microSD card or an NFS server, with threee options:
42547 bytes written: OK
=>
</pre>
 
Reboot the system and configure U-Boot to apply the new configuration
 
<pre class="board-terminal">
=> setenv bootcmd run nand_nand
=> saveenv
</pre>
mmc_update=mmc dev; setexpr blocks ${filesize} / 0x200; setexpr blocks ${blocks} + 1; mmc write ${loadaddr} 2 ${blocks}
</pre>
 
Load u-boot binary form a <code>tftp</code> server:
<pre class="board-terminal">
done
Bytes transferred = 671788 (a402c hex)
=> run mmc_update
switch to partitions #0, OK
mmc2(part 0) is current device (eMMC)
 
MMC write: dev # 2, block # 2, count 1313 ... 1313 blocks written: OK
=>
</pre>
 
Load u-boot binary form an <code>SD</code> card:
 
<pre class="board-terminal">
Hit ENTER within 1 seconds to stop autoboot
=> fatload mmc 0:1 ${loadaddr} sdvx-1.0.1_mx6dlaxel_u-boot.imx
reading sdvx-1.0.1_mx6dlaxel_u-boot.imx
671788 bytes read in 50 ms (12.8 MiB/s)
=> mmc dev 2
switch to partitions #0, OK
mmc2(part 0) is current device (eMMC)
=> run mmc_update
switch to partitions #0, OK
mmc_loadfdt=fatload mmc ${mmcdev}:1 ${fdtaddr} ${fdtfile}
mmc_loadsplash=fatload mmc ${mmcdev}:1 ${loadaddr} ${splashfile}; cp.b ${loadaddr} ${splashimage} ${filesize}
mmcboot=run mmcargs addcons addmisc; if run mmc_loadk; then if run mmc_loadfdt; then if run configid_fixupfdt; then bootm ${loadaddr} - ${fdtaddr}; fi; fi; fi
</pre>
mmcargs=setenv bootargs root=${mmcroot}
mmcroot=/dev/mmcblk2p2 rootwait rw
</pre>
 
=== boot vars ===
 
The following environment variables should be configured for u-boot properly reading the boot files from the first SD card partition, e.g.
 
<pre class="board-terminal">
=> setenv normalboot mmcboot
=> setenv bootfile sdvx-1.0.1_lite_uImage
=> setenv fdtfile sdvx-1.0.1_lite_imx6dl-sdv03-cb002a.dtb
=> setenv splashfile splash_image.bmp
</pre>
 
then save the environment and reboot the system to apply the new configuration:
 
<pre class="board-terminal">
=> saveenv
Saving Environment to MMC...
Writing to MMC(2)... done
=> reset
</pre>
mtd7: 3e600000 00020000 "nand-ubi"
root@sdvx-lite:~#
</pre>
 
{{ImportantMessage|text=Please note that MTD partition index may change depending of flash device availability, flash device size, u-boot environment variables or kernel device driver load order. Always take care of looking inside <code>/proc/mtd</code> to match your specific layout}}
 
 
* Format and initialize ''nand-ubi'' partition, which in our case is <code>mtd7</code>, using [[Memory Tecnology Device (MTD)#UBI|UBI]] with:
 
<pre>
ubiformat /dev/mtd7
ubiattach -m 7
ubimkvol /dev/ubi0 -N rootfs -m
</pre>
 
E.g.
 
<pre class="board-terminal">
root@sdvx-lite:~# ubiformat /dev/mtd7
ubiformat: mtd7 (nand), size 1048576000 bytes (1000.0 MiB), 8000 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 7999 -- 100 % complete
ubiformat: 8000 eraseblocks have valid erase counter, mean value is 1
ubiformat: formatting eraseblock 7999 -- 100 % complete
root@sdvx-lite:~# ubiattach -m 7
[ 1714.823600] UBI: attaching mtd7 to ubi0
[ 1726.415587] UBI: scanning is finished
[ 1726.483765] UBI: attached mtd7 (name "nand-ubi", size 1000 MiB) to ubi0
[ 1726.491062] UBI: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 1726.498301] UBI: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 1726.505030] UBI: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 1726.512430] UBI: good PEBs: 8000, bad PEBs: 0, corrupted PEBs: 0
[ 1726.518861] UBI: user volume: 0, internal volumes: 1, max. volumes count: 128
[ 1726.526025] UBI: max/mean erase counter: 3/2, WL threshold: 4096, image sequence number: 623070258
[ 1726.535433] UBI: available PEBs: 7836, total reserved PEBs: 164, PEBs reserved for bad PEB handling: 160
[ 1726.545260] UBI: background thread "ubi_bgt0d" started, PID 714
UBI device number 0, total 8000 LEBs (1015808000 bytes, 968.8 MiB), available 7836 LEBs (994983936 bytes, 948.9 MiB), LEB size 126976 bytes (124.0 KiB)
root@sdvx-lite:~# ubimkvol /dev/ubi0 -N rootfs -m
Set volume size to 994983936
Volume ID 0, size 7836 LEBs (994983936 bytes, 948.9 MiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "rootfs", alignment 1
</pre>
 
* Now mount the UBI volume using [[Memory Tecnology Device (MTD)#UBIFS|UBIFS]] in a temporary directory
 
<pre>
mkdir -p /mnt/nand
mount -t ubifs ubi0_0 /mnt/nand
</pre>
 
E.g.:
 
<pre class="board-terminal">
root@sdvx-lite:~# mkdir -p /mnt/nand
root@sdvx-lite:~# mount -t ubifs ubi0_0 /mnt/nand
[ 1810.301461] UBIFS: default file-system created
[ 1810.308952] UBIFS: background thread "ubifs_bgt0_0" started, PID 717
[ 1810.452274] UBIFS: mounted UBI device 0, volume 0, name "rootfs"
[ 1810.459421] UBIFS: LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 1810.469398] UBIFS: FS size: 992698368 bytes (946 MiB, 7818 LEBs), journal size 33521664 bytes (31 MiB, 264 LEBs)
[ 1810.480976] UBIFS: reserved for root: 4952683 bytes (4836 KiB)
[ 1810.487210] UBIFS: media format: w4/r0 (latest is w4/r0), UUID 99D0F3C6-5955-4B30-9E2D-72202281BD30, small LPT model
</pre>
 
* you can now extract the root file system into that directory
 
<pre>
tar xvjf sdvx-1.0.1_image-devel-sdvx-lite.tar.bz2 -C /mnt/nand
</pre>
 
* finally, you need to cleanly umount and detach the MTD partition
 
<pre>
umount /mnt/nand/
ubidetach -m 7
</pre>
 
E.g.
 
<pre class="board-terminal">
root@sdvx-lite:~# umount /mnt/nand/
[ 2446.743091] UBIFS: un-mount UBI device 0, volume 0
[ 2446.749670] UBIFS: background thread "ubifs_bgt0_0" stops
root@sdvx-lite:~# ubidetach -m 7
[ 2450.738153] UBI: detaching mtd7 from ubi0
[ 2450.759527] UBI: mtd7 is detached from ubi0
</pre>
 
You can now safely reboot or turn off the system.
 
In U-Boot environment check the following variable, which must contain the same MTD partition number used above
 
<pre>
nand_args=setenv bootargs root=ubi0:rootfs rootfstype=ubifs rw ubi.mtd=7
</pre>
* an example of SD partitioning script is the following one:
=== FAT32 partition ===
<pre>
#!/bin/sh
root@sdvx-lite:~#
</pre>
 
* create a mount point and mount the first partition
<pre>
mkdir -p /mnt/emmc
mount /dev/mmcblk2p1 /mnt/emmc
</pre>
 
* copy kernel, dtb and splash_image files
 
<pre class="workstation-terminal">
root@sdvx-lite:~# mount /dev/mmcblk2p1 /mnt/emmc
[ 40.988575] FAT-fs (mmcblk2p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
root@sdvx-lite:~# cd /mnt/emmc
root@sdvx-lite:/mnt/emmc# cp /tftpboot/sdvx/linux/sdvx-1.0.1*dtb .
root@sdvx-lite:/mnt/emmc# cp /tftpboot/sdvx/linux/sdvx-1.0.1*uImage .
root@sdvx-lite:/mnt/emmc# cp /tftpboot/sdvx/linux/splash_image.bmp .
root@sdvx-lite:/mnt/emmc# cd
root@sdvx-lite:~# umount /mnt/emmc
</pre>
 
* now mount the EXT4 volume in the temporary directory
 
E.g.:
 
<pre class="workstation-terminal">
root@sdvx-lite:~# mount /dev/mmcblk2p2 /mnt/emmc
[ 1810.899327] EXT4-fs (mmcblk2p2): mounted filesystem with ordered data mode. Opts: (null)
root@sdvx-lite:~# cd /mnt/emmc
root@sdvx-lite:/mnt/emmc#
</pre>
 
* you can now extract the root file system into that directory
 
<pre>
tar xvjf sdvx-1.0.1_image-devel-sdvx-lite.tar.bz2
</pre>
 
* finally, you need to cleanly umount and safely reboot or turn off the system.
 
<pre class="workstation-terminal">
root@sdvx-lite:/mnt/emmc# cd
root@sdvx-lite:~# umount /mnt/emmc
root@sdvx-lite:~# reboot
</pre>
 
Reboot the system and configure U-Boot to apply the new configuration
 
<pre class="workstation-terminal">
=> setenv bootcmd run mmcboot
=> saveenv
</pre>
 
=== ext4 partition ===
For using an <b>ext4</b> partition also for boot files, it is possibile to change the formatting script:
 
{ echo ${boot_start},${boot_size},'''83''',-; echo ${rfs_start},${rfs_size},83,-; } | sfdisk --force ${node}
 
and formatting the first partition using ''mkfs.ext4''
 
mkfs.ext4 -F ${node}${part}1 -Lboot
 
then, the u-boot <code>environment</code> has to be properly configured:
 
<pre class="workstation-terminal">
=> setenv mmc_loadk 'ext4load mmc ${mmcdev}:1 ${loadaddr} ${bootfile}'
=> setenv mmc_loadfdt 'ext4load mmc ${mmcdev}:1 ${fdtaddr} ${fdtfile}'
=> setenv mmc_loadsplash 'ext4load mmc ${mmcdev}:1 ${loadaddr} ${splashfile}; cp.b ${loadaddr} ${splashimage} ${filesize}'
=> saveenv
</pre>
8,231
edits