Changes

Jump to: navigation, search

Standalone boot (DIVELK)

12,384 bytes added, 16:30, 19 June 2017
Created page with "{{InfoBoxTop}} {{AppliesToDIVA}} {{InfoBoxBottom}} == History == {| class="wikitable" border="1" !Version !Date !DIVELK version !Notes |- |3.0.0 |June 2017 |Diva_Embedded_..."
{{InfoBoxTop}}
{{AppliesToDIVA}}
{{InfoBoxBottom}}

== History ==

{| class="wikitable" border="1"
!Version
!Date
!DIVELK version
!Notes
|-
|3.0.0
|June 2017
|[[Diva_Embedded_Linux_Kit_(DIVELK)#DIVELK_3.0.0|DIVELK 3.0.0]]
|
|-
|}

== Introduction ==

This document has been written and tested with the software/hardware combination described in the history table above. However it contains general concept that can be adapted on any DAVE Embedded Systems' Linux platform.

We'll explain how to program and configure a [[Category:DIVA|DIVA]] to boot in standalone mode, without the need of a system microSD card or a NFS server, with two options:
* booting with NOR + NAND
** U-Boot will fetch Linux kernel binary images (kernel + device tree) from on-board NOR flash memory, while later the OS will mount the root file system from a NAND partition.
* booting with NAND only
** in this configuration the whole system will boot without the need of a NOR storage, all images and the root file system will be fetch from NAND.

== Program root file system in NAND flash ==

This is a common step for both booting options.

* Boot the system via SD or NFS as described into the [[Diva_Embedded_Linux_Kit_(DIVELK)#Quick_start_guide|Quick_start_guide]]
* By default, the NAND is already partitioned to allow booting from NAND-only (see next section) and, thus, some partitions are reserved for U-boot and kernel images. Here we won't modify this default configuration. The [[Memory Tecnology Device (MTD)|MTD]] partitions can be dumped with <code>/proc/mtd</code> (the partition's name should be self-explanatory)


<pre class="board-terminal">
root@diva:~# cat /proc/mtd
dev: size erasesize name
mtd0: 00040000 00010000 "MLO"
mtd1: 00080000 00010000 "u-boot"
mtd2: 00040000 00010000 "env1"
mtd3: 00040000 00010000 "env2"
mtd4: 00040000 00010000 "fdt"
mtd5: 00600000 00010000 "kernel"
mtd6: 00400000 00010000 "splash"
mtd7: 01480000 00010000 "free"
mtd8: 00020000 00020000 "NAND.SPL"
mtd9: 00020000 00020000 "NAND.SPL.backup1"
mtd10: 00020000 00020000 "NAND.SPL.backup2"
mtd11: 00020000 00020000 "NAND.SPL.backup3"
mtd12: 001e0000 00020000 "NAND.u-boot"
mtd13: 00020000 00020000 "NAND.u-boot-env"
mtd14: 00020000 00020000 "NAND.u-boot-env.backup1"
mtd15: 00020000 00020000 "NAND.fdt"
mtd16: 00600000 00020000 "NAND.kernel"
mtd17: 00400000 00020000 "NAND.splash"
mtd18: 1f340000 00020000 "NAND.file-system"
root@diva:~#
</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>mtd18</code>, using [[Memory Tecnology Device (MTD)#UBI|UBI]] with:

<pre>
ubiformat /dev/mtd18
ubiattach -m 18
ubimkvol /dev/ubi0 -N rootfs -m
</pre>

E.g.

<pre class="board-terminal">
root@diva:~# ubiformat /dev/mtd18
ubiformat: mtd18 (nand), size 1060372480 bytes (1011.2 MiB), 8090 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 8089 -- 100 % complete
ubiformat: 8089 eraseblocks have valid erase counter, mean value is 1
ubiformat: 1 bad eraseblocks found, numbers: 1705
ubiformat: formatting eraseblock 8089 -- 100 % complete
root@diva:~# ubiattach -m 18
[ 191.278340] ubi0: attaching mtd18
[ 193.528706] ubi0: scanning is finished
[ 193.557104] ubi0: attached mtd18 (name "NAND.file-system", size 1011 MiB)
[ 193.564231] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
[ 193.571629] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 512
[ 193.578373] ubi0: VID header offset: 512 (aligned 512), data offset: 2048
[ 193.585716] ubi0: good PEBs: 8089, bad PEBs: 1, corrupted PEBs: 0
[ 193.591905] ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
[ 193.599445] ubi0: max/mean erase counter: 3/2, WL threshold: 4096, image sequence number: 1551879958
[ 193.608622] ubi0: available PEBs: 7926, total reserved PEBs: 163, PEBs reserved for bad PEB handling: 159
[ 193.618708] ubi0: background thread "ubi_bgt0d" started, PID 1068
UBI device number 0, total 8089 LEBs (1043675136 bytes, 995.3 MiB), available 7926 LEBs (1022644224 bytes, 975.3 MiB), LEB size 129024 bytes (126.0 KiB)
root@diva:~# ubimkvol /dev/ubi0 -N diva-rootfs -m
Set volume size to 1022644224
Volume ID 0, size 7926 LEBs (1022644224 bytes, 975.3 MiB), LEB size 129024 bytes (126.0 KiB), dynamic, name "diva-rootfs", alignment 1
root@diva:~#
</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@sbc-lynx:~# mkdir -p /mnt/nand
root@sbc-lynx:~# mount -t ubifs ubi0_0 /mnt/nand
root@diva:~# mount -t ubifs ubi0_0 /mnt/nand
[ 232.550330] UBIFS (ubi0:0): default file-system created
[ 232.559955] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 1074
[ 232.618905] UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "diva-rootfs"
[ 232.626611] UBIFS (ubi0:0): LEB size: 129024 bytes (126 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 232.637797] UBIFS (ubi0:0): FS size: 1020321792 bytes (973 MiB, 7908 LEBs), journal size 33546240 bytes (31 MiB, 260 LEBs)
[ 232.649164] UBIFS (ubi0:0): reserved for root: 4952683 bytes (4836 KiB)
[ 232.655844] UBIFS (ubi0:0): media format: w4/r0 (latest is w4/r0), UUID 92010F4A-9456-491C-A5DC-9B0DE0E25992, small LPT model
root@diva:~#
</pre>

* you can now extract the root file system into that directory

<pre>
root@diva:~# tar zxvf divelk-image-matrix-diva.tar.gz -C /mnt/nand
</pre>

* finally, you need to cleanly umount and detach the MTD partition

<pre class="board-terminal">
root@diva:~# umount /mnt/nand/
[ 1033.824165] UBIFS (ubi0:0): un-mount UBI device 0
[ 1033.829317] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" stops
root@diva:~# ubidetach -m 18
[ 1047.424806] ubi0: detaching mtd18
[ 1047.444423] ubi0: mtd18 is detached
root@diva:~#
</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=18
</pre>


== Program boot images ==

=== NOR flash ===

We assume that the following environment variables are present in u-boot:

<pre>
spisrcaddrk=0x180000
spisrcaddrfdt=0x140000
loadk=tftp ${kloadaddr} ${bootfile}
loadfdt=tftpboot ${fdtaddr} ${fdtfile}
spi_updatek=sf probe 0:0; sf erase ${spisrcaddrk} 0x600000; sf write ${kloadaddr} ${spisrcaddrk} 0x600000
spi_updatefdt=sf probe 0:0; sf erase ${spisrcaddrfdt} 0x40000; sf write ${fdtaddr} ${spisrcaddrfdt} 0x40000
spi_loadk=sf read ${kloadaddr} ${spisrcaddrk} 0x600000
spi_loadfdt=sf read ${fdtaddr} ${spisrcaddrfdt} 0x40000
spi_nand=sf probe; run spi_loadk spi_loadfdt nandargs addcons addmisc; if run configid_fixupfdt; then bootm ${loadaddr} - ${fdtaddr}; fi
</pre>

* Update the <code>bootfile</code> and <code>fdtfile</code> environment variables to fit the filename as found inside the TFTP server.
* Program kernel and device tree on NOR flash with the following U-Boot command

<pre class="board-terminal">
U-Boot# sf probe; run loadk spi_updatek loadfdt spi_updatefdt
SF: Detected S25FL256S_64K with page size 256 Bytes, erase size 64 KiB, total 32 MiB
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.23; our IP address is 192.168.0.94
Filename 'diva/linux/divelk-3.0.0_uImage'.
Load address: 0x80007fc0
Loading: #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
###############################
1.6 MiB/s
done
Bytes transferred = 4148488 (3f4d08 hex)
SF: Detected S25FL256S_64K with page size 256 Bytes, erase size 64 KiB, total 32 MiB
SF: 6291456 bytes @ 0x180000 Erased: OK
device 0 offset 0x180000, size 0x600000
SF: 6291456 bytes @ 0x180000 Written: OK
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.23; our IP address is 192.168.0.94
Filename 'diva/linux/divelk-3.0.0_am335x-divelk.dtb'.
Load address: 0x80f80000
Loading: ########
918.9 KiB/s
done
Bytes transferred = 39558 (9a86 hex)
SF: Detected S25FL256S_64K with page size 256 Bytes, erase size 64 KiB, total 32 MiB
SF: 262144 bytes @ 0x140000 Erased: OK
device 0 offset 0x140000, size 0x40000
SF: 262144 bytes @ 0x140000 Written: OK
U-Boot#
</pre>


Reboot the system and configure U-Boot to apply the new configuration

<pre class="board-terminal">
=> setenv bootcmd run spi_nand
=> saveenv
</pre>

== NAND flash ==

We assume that the following environment variables are present in u-boot:

<pre>
nand_updatek=nand erase.part NAND.kernel; nand write ${kloadaddr} NAND.kernel ${filesize}
nand_updatefdt=nand erase.part NAND.fdt; nand write ${fdtaddr} NAND.fdt ${filesize}
nand_loadk=nand read ${loadaddr} NAND.kernel
nand_loadfdt=nand read ${fdtaddr} NAND.fdt
nandargs=setenv bootargs ubi.mtd=NAND.file-system root=ubi0:diva-rootfs rootfstype=ubifs rw rootwait=1
nand_nand=nand read ${kloadaddr} NAND.kernel; nand read ${fdtaddr} NAND.fdt; run nandargs addeth addcons addmisc configid_fixupfdt; bootm ${kloadaddr} - ${fdtaddr}
</pre>


* Update the <code>bootfile</code> and <code>fdtfile</code> environment variables to fit the filename as found inside the TFTP server.
* Program kernel and device tree on NAND flash with the following U-Boot command

<pre class="board-terminal">
=> run loadk nand_updatek loadfdt nand_updatefdt
</pre>

E.g.:

<pre class="board-terminal">
U-Boot# run loadk nand_updatek loadfdt nand_updatefdt
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.23; our IP address is 192.168.0.94
Filename 'diva/uImage'.
Load address: 0x80007fc0
Loading: #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#
1.6 MiB/s
done
Bytes transferred = 3332840 (32dae8 hex)

NAND erase.part: device 0 offset 0x2c0000, size 0x600000
Erasing at 0x8a0000 -- 100% complete.
OK

NAND write: device 0 offset 0x2c0000, size 0x32dae8
3332840 bytes written: OK
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.23; our IP address is 192.168.0.94
Filename 'diva/am335x-divelk.dtb'.
Load address: 0x80f80000
Loading: ########
954.1 KiB/s
done
Bytes transferred = 37129 (9109 hex)

NAND erase.part: device 0 offset 0x2a0000, size 0x20000
Erasing at 0x2a0000 -- 100% complete.
OK

NAND write: device 0 offset 0x2a0000, size 0x9109
37129 bytes written: OK
U-Boot#
</pre>


Reboot the system and configure U-Boot to apply the new configuration

<pre class="board-terminal">
=> setenv bootcmd run nand_nand
=> saveenv
</pre>
8,226
edits

Navigation menu