Difference between revisions of "Standalone boot (DIVELK)"

From DAVE Developer's Wiki
Jump to: navigation, search
(History)
(Undo revision 7654 by U0012 (talk))
(10 intermediate revisions by 3 users not shown)
Line 11: Line 11:
 
!Notes
 
!Notes
 
|-
 
|-
|{{oldid|7655|3.0.0}}
+
|3.0.0
 
|June 2017
 
|June 2017
 
|[[Diva_Embedded_Linux_Kit_(DIVELK)#DIVELK_3.0.0|DIVELK 3.0.0]]
 
|[[Diva_Embedded_Linux_Kit_(DIVELK)#DIVELK_3.0.0|DIVELK 3.0.0]]
|
 
|-
 
|4.0.0
 
|April 2018
 
|[[Diva_Embedded_Linux_Kit_(DIVELK)#DIVELK_4.0.0|DIVELK 4.0.0]]
 
 
|
 
|
 
|-
 
|-
Line 27: Line 22:
 
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.
 
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  
+
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:
[[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
 
* 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.
 
** 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
 
* 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.
 
** 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.
 
== Update u-boot NOR ==
 
<pre>
 
tftp ${loadaddr} diva/divelk-4.0.0_diva_spiboot_MLO.byteswap
 
sf probe 0:0; sf erase 0x0 0x40000; sf write ${loadaddr} 0x0 0x40000
 
tftp ${loadaddr} diva/divelk-4.0.0_diva_spiboot_u-boot.img
 
sf probe 0:0; sf erase 0x40000 0x100000; sf write ${loadaddr} 0x40000 0x100000
 
</pre>
 
<pre class="board-terminal">
 
=> tftp ${loadaddr} diva/divelk-4.0.0_diva_spiboot_MLO.byteswap
 
link up on port 0, speed 100, full duplex
 
Using cpsw device
 
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
 
Filename 'diva/divelk-4.0.0_diva_spiboot_MLO.byteswap'.
 
Load address: 0x82000000
 
Loading: #############
 
        1.3 MiB/s
 
done
 
Bytes transferred = 65868 (1014c hex)
 
 
=> sf probe 0:0; sf erase 0x0 0x40000; sf write ${loadaddr} 0x0 0x40000
 
SF: Detected s25fl256s_64k with page size 256 Bytes, erase size 64 KiB, total 32 MiB
 
SF: 262144 bytes @ 0x0 Erased: OK
 
device 0 offset 0x0, size 0x40000
 
SF: 262144 bytes @ 0x0 Written: OK
 
 
=> tftp ${loadaddr} diva/divelk-4.0.0_diva_spiboot_u-boot.img
 
link up on port 0, speed 100, full duplex
 
Using cpsw device
 
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
 
Filename 'diva/divelk-4.0.0_diva_spiboot_u-boot.img'.
 
Load address: 0x82000000
 
Loading: #################################################################
 
        #########################################
 
        1.3 MiB/s
 
done
 
Bytes transferred = 540424 (83f08 hex)
 
 
=> sf probe 0:0; sf erase 0x40000 0x100000; sf write ${loadaddr} 0x40000 0x100000
 
SF: Detected s25fl256s_64k with page size 256 Bytes, erase size 64 KiB, total 32 MiB
 
SF: 1048576 bytes @ 0x40000 Erased: OK
 
device 0 offset 0x40000, size 0x100000
 
SF: 1048576 bytes @ 0x40000 Written: OK
 
 
</pre>
 
'''Note:''' Adjust the SYSBOOT pins to enable boot from spi.
 
 
== Update u-boot NAND ==
 
<pre>
 
tftp ${loadaddr} diva/divelk-4.0.0_diva_nandboot_MLO
 
nand erase.part nand-spl; nand write ${loadaddr} nand-spl ${filesize}
 
tftp ${loadaddr} diva/divelk-4.0.0_diva_nandboot_u-boot.img
 
nand erase.part nand-uboot; nand write ${loadaddr} nand-uboot ${filesize}
 
</pre>
 
 
<pre class="board-terminal">
 
=> tftp ${loadaddr} diva/divelk-4.0.0_diva_nandboot_MLO
 
link up on port 0, speed 100, full duplex
 
Using cpsw device
 
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
 
Filename 'diva/divelk-4.0.0_diva_nandboot_MLO'.
 
Load address: 0x82000000
 
Loading: #############
 
        825.2 KiB/s
 
done
 
Bytes transferred = 61716 (f114 hex)
 
=> nand erase.part nand-spl; nand write ${loadaddr} nand-spl ${filesize}
 
 
NAND erase.part: device 0 offset 0x0, size 0x20000
 
Erasing at 0x0 -- 100% complete.
 
OK
 
 
NAND write: device 0 offset 0x0, size 0xf114
 
61716 bytes written: OK
 
 
=> tftp ${loadaddr} diva/divelk-4.0.0_diva_nandboot_u-boot.img
 
link up on port 0, speed 100, full duplex
 
Using cpsw device
 
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
 
Filename 'diva/divelk-4.0.0_diva_nandboot_u-boot.img'.
 
Load address: 0x82000000
 
Loading: #################################################################
 
        #########################################
 
        1 MiB/s
 
done
 
Bytes transferred = 539856 (83cd0 hex)
 
 
=> nand erase.part nand-uboot; nand write ${loadaddr} nand-uboot ${filesize}
 
 
NAND erase.part: device 0 offset 0x80000, size 0x1e0000
 
Erasing at 0x240000 -- 100% complete.
 
OK
 
 
NAND write: device 0 offset 0x80000, size 0x83cd0
 
539856 bytes written: OK
 
</pre>
 
'''Note:''' Adjust the SYSBOOT pins to enable boot from nand.
 
  
 
== Program root file system in NAND flash ==
 
== Program root file system in NAND flash ==
Line 136: Line 32:
 
This is a common step for both booting options.  
 
This is a common step for both booting options.  
  
* Boot the system via SD or NFS
+
* 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)
 
* 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">
 
<pre class="board-terminal">
 
root@diva:~# cat /proc/mtd
 
root@diva:~# cat /proc/mtd
 
dev:    size  erasesize  name
 
dev:    size  erasesize  name
mtd0: 00040000 00010000 "spi-MLO"
+
mtd0: 00040000 00010000 "MLO"
mtd1: 00100000 00010000 "spi-uboot"
+
mtd1: 00080000 00010000 "u-boot"
mtd2: 00040000 00010000 "spi-env1"
+
mtd2: 00040000 00010000 "env1"
mtd3: 00040000 00010000 "spi-env2"
+
mtd3: 00040000 00010000 "env2"
mtd4: 00040000 00010000 "spi-fdt"
+
mtd4: 00040000 00010000 "fdt"
mtd5: 00600000 00010000 "spi-kernel"
+
mtd5: 00600000 00010000 "kernel"
mtd6: 00400000 00010000 "spi-splash"
+
mtd6: 00400000 00010000 "splash"
mtd7: 01400000 00010000 "spi-free"
+
mtd7: 01480000 00010000 "free"
mtd8: 00020000 00020000 "nand-spl"
+
mtd8: 00020000 00020000 "NAND.SPL"
mtd9: 00020000 00020000 "nand-spl.backup1"
+
mtd9: 00020000 00020000 "NAND.SPL.backup1"
mtd10: 00020000 00020000 "nand-spl.backup2"
+
mtd10: 00020000 00020000 "NAND.SPL.backup2"
mtd11: 00020000 00020000 "nand-spl.backup3"
+
mtd11: 00020000 00020000 "NAND.SPL.backup3"
mtd12: 001e0000 00020000 "nand-uboot"
+
mtd12: 001e0000 00020000 "NAND.u-boot"
mtd13: 00020000 00020000 "nand-uboot-env"
+
mtd13: 00020000 00020000 "NAND.u-boot-env"
mtd14: 00020000 00020000 "nand-uboot-env.backup1"
+
mtd14: 00020000 00020000 "NAND.u-boot-env.backup1"
mtd15: 00020000 00020000 "nand-fdt"
+
mtd15: 00020000 00020000 "NAND.fdt"
mtd16: 00600000 00020000 "nand-kernel"
+
mtd16: 00600000 00020000 "NAND.kernel"
mtd17: 00400000 00020000 "nand-splash"
+
mtd17: 00400000 00020000 "NAND.splash"
mtd18: 3f340000 00020000 "nand-filesystem"
+
mtd18: 1f340000 00020000 "NAND.file-system"
 +
root@diva:~#
 
</pre>
 
</pre>
  
Line 166: Line 64:
  
  
* Format and initialize ''nand-filesystem'' partition, which in our case is <code>mtd18</code>, using [[Memory Tecnology Device (MTD)#UBI|UBI]] with:
+
* Format and initialize ''nand-ubi'' partition, which in our case is <code>mtd18</code>, using [[Memory Tecnology Device (MTD)#UBI|UBI]] with:
  
 
<pre>
 
<pre>
 
ubiformat /dev/mtd18
 
ubiformat /dev/mtd18
 
ubiattach -m 18
 
ubiattach -m 18
ubimkvol /dev/ubi0 -N rootfs -m
+
ubimkvol /dev/ubi0 -N diva-rootfs -m
 
</pre>
 
</pre>
  
Line 179: Line 77:
 
root@diva:~# ubiformat /dev/mtd18
 
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
 
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 6 % complete 
+
libscan: scanning eraseblock 8089 -- 100 % complete
 
ubiformat: 8089 eraseblocks have valid erase counter, mean value is 1
 
ubiformat: 8089 eraseblocks have valid erase counter, mean value is 1
ubiformat: 1 bad eraseblocks found, numbers: 2991
+
ubiformat: 1 bad eraseblocks found, numbers: 1705
ubiformat: formatting eraseblock 8089 -- 100 % complete
+
ubiformat: formatting eraseblock 8089 -- 100 % complete
root@diva:~#
 
 
root@diva:~# ubiattach -m 18
 
root@diva:~# ubiattach -m 18
932.829348] ubi0: attaching mtd18
+
191.278340] ubi0: attaching mtd18
935.304512] ubi0: scanning is finished
+
193.528706] ubi0: scanning is finished
935.334456] ubi0: attached mtd18 (name "nand-filesystem", size 1011 MiB)
+
193.557104] ubi0: attached mtd18 (name "NAND.file-system", size 1011 MiB)
935.341934] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
+
193.564231] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
935.353377] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 512
+
193.571629] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 512
935.362897] ubi0: VID header offset: 512 (aligned 512), data offset: 2048
+
193.578373] ubi0: VID header offset: 512 (aligned 512), data offset: 2048
935.372570] ubi0: good PEBs: 8089, bad PEBs: 1, corrupted PEBs: 0
+
193.585716] ubi0: good PEBs: 8089, bad PEBs: 1, corrupted PEBs: 0
935.381808] ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
+
193.591905] ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
935.391863] ubi0: max/mean erase counter: 3/2, WL threshold: 4096, image sequence number: 1786346429
+
193.599445] ubi0: max/mean erase counter: 3/2, WL threshold: 4096, image sequence number: 1551879958
935.403777] ubi0: available PEBs: 7926, total reserved PEBs: 163, PEBs reserved for bad PEB handling: 159
+
193.608622] ubi0: available PEBs: 7926, total reserved PEBs: 163, PEBs reserved for bad PEB handling: 159
935.416248] ubi0: background thread "ubi_bgt0d" started, PID 1025
+
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 byte)
+
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@axel-lite:~# ubimkvol /dev/ubi0 -N rootfs -m
+
root@diva:~# ubimkvol /dev/ubi0 -N diva-rootfs -m
 
Set volume size to 1022644224
 
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 "rootfs", alignment 1
+
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:~#
 
root@diva:~#
 
</pre>
 
</pre>
Line 215: Line 112:
 
root@diva:~# mkdir -p /mnt/nand
 
root@diva:~# mkdir -p /mnt/nand
 
root@diva:~# mount -t ubifs ubi0_0 /mnt/nand
 
root@diva:~# mount -t ubifs ubi0_0 /mnt/nand
[ 1048.356596] UBIFS (ubi0:0): default file-system created
+
[ 232.550330] UBIFS (ubi0:0): default file-system created
[ 1048.371923] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 1033
+
[ 232.559955] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 1074
[ 1048.436268] UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "rootfs"
+
[ 232.618905] UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "diva-rootfs"
[ 1048.443769] UBIFS (ubi0:0): LEB size: 129024 bytes (126 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
+
[ 232.626611] UBIFS (ubi0:0): LEB size: 129024 bytes (126 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 1048.459787] UBIFS (ubi0:0): FS size: 1020321792 bytes (973 MiB, 7908 LEBs), journal size 33546240 bytes (31 MiB, 260 LEBs)
+
[ 232.637797] UBIFS (ubi0:0): FS size: 1020321792 bytes (973 MiB, 7908 LEBs), journal size 33546240 bytes (31 MiB, 260 LEBs)
[ 1048.477979] UBIFS (ubi0:0): reserved for root: 4952683 bytes (4836 KiB)
+
[ 232.649164] UBIFS (ubi0:0): reserved for root: 4952683 bytes (4836 KiB)
[ 1048.484678] UBIFS (ubi0:0): media format: w4/r0 (latest is w4/r0), UUID 506C48EC-890F-476F-BD40-56141C521278, small LPT model
+
[ 232.655844] UBIFS (ubi0:0): media format: w4/r0 (latest is w4/r0), UUID 92010F4A-9456-491C-A5DC-9B0DE0E25992, small LPT model
 
root@diva:~#
 
root@diva:~#
 
</pre>
 
</pre>
Line 228: Line 125:
  
 
<pre>
 
<pre>
tar xvJf divelk-4.0.0_divelk-image-matrix.tar.xz -C /mnt/nand
+
root@diva:~# tar zxvf divelk-image-matrix-diva.tar.gz -C /mnt/nand
 
</pre>
 
</pre>
  
 
* finally, you need to cleanly umount and detach the MTD partition
 
* finally, you need to cleanly umount and detach the MTD partition
 
<pre>
 
umount /mnt/nand/
 
ubidetach -m 18
 
</pre>
 
 
E.g.
 
  
 
<pre class="board-terminal">
 
<pre class="board-terminal">
 
root@diva:~# umount /mnt/nand/
 
root@diva:~# umount /mnt/nand/
[ 1137.013852] UBIFS (ubi0:0): un-mount UBI device 0
+
[ 1033.824165] UBIFS (ubi0:0): un-mount UBI device 0
[ 1137.027471] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" stops
+
[ 1033.829317] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" stops
 
root@diva:~# ubidetach -m 18
 
root@diva:~# ubidetach -m 18
[ 1144.283392] ubi0: detaching mtd18
+
[ 1047.424806] ubi0: detaching mtd18
[ 1144.311866] ubi0: mtd18 is detached
+
[ 1047.444423] ubi0: mtd18 is detached
root@diva:~#  
+
root@diva:~#
 
</pre>
 
</pre>
  
Line 255: Line 145:
  
 
<pre>
 
<pre>
nandargs=setenv bootargs ubi.mtd=nand-filesystem root=ubi0:rootfs rootfstype=ubifs rw rootwait=1
+
nand_args=setenv bootargs root=ubi0:diva-rootfs rootfstype=ubifs rw ubi.mtd=18
 
</pre>
 
</pre>
  
Line 265: Line 155:
  
 
<pre>
 
<pre>
loadk=tftpboot ${loadaddr} ${serverip}:${bootfile}
+
spisrcaddrk=0x180000
loadfdt=tftpboot ${fdtaddr} ${serverip}:${fdtfile}
+
spisrcaddrfdt=0x140000
spi_updatek=sf erase 0x200000 0x600000; sf write ${loadaddr} 0x200000 ${filesize}
+
loadk=tftp ${kloadaddr} ${bootfile}
spi_updatefdt=sf erase 0x1C0000 0x40000; sf write ${fdtaddr} 0x1C0000 ${filesize}
+
loadfdt=tftpboot ${fdtaddr} ${fdtfile}
spi_loadk=sf read ${loadaddr} 0x200000 0x600000
+
spi_updatek=sf probe 0:0; sf erase ${spisrcaddrk} 0x600000; sf write ${kloadaddr} ${spisrcaddrk} 0x600000
spi_loadfdt=sf read ${fdtaddr} 0x1C0000 0x40000
+
spi_updatefdt=sf probe 0:0; sf erase ${spisrcaddrfdt} 0x40000; sf write ${fdtaddr} ${spisrcaddrfdt} 0x40000
spi_nand=sf probe; run spi_loadk spi_loadfdt nandargs addcons addmisc; if run configid_fixupfdt; then bootm ${loadaddr} - ${fdtaddr}; fi
+
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 ${kloadaddr} - ${fdtaddr}; fi
 
</pre>
 
</pre>
  
Line 278: Line 170:
  
 
<pre class="board-terminal">
 
<pre class="board-terminal">
sf probe; run loadk spi_updatek loadfdt spi_updatefdt
+
U-Boot# sf probe; run loadk spi_updatek loadfdt spi_updatefdt
</pre>
+
SF: Detected S25FL256S_64K with page size 256 Bytes, erase size 64 KiB, total 32 MiB
 
 
E.g.:
 
 
 
<pre class="board-terminal">
 
=> 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
 
link up on port 0, speed 100, full duplex
 
Using cpsw device
 
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
+
TFTP from server 192.168.0.23; our IP address is 192.168.0.94
Filename 'diva/uImage'.
+
Filename 'diva/linux/divelk-3.0.0_uImage'.
Load address: 0x82000000
+
Load address: 0x80007fc0
 
Loading: #################################################################
 
Loading: #################################################################
 
         #################################################################
 
         #################################################################
Line 303: Line 189:
 
         #################################################################
 
         #################################################################
 
         #################################################################
 
         #################################################################
         #################################################################
+
         ###############################
         #####################################################
+
         1.6 MiB/s
        1022.5 KiB/s
 
 
done
 
done
Bytes transferred = 4593552 (461790 hex)
+
Bytes transferred = 4148488 (3f4d08 hex)
SF: 6291456 bytes @ 0x200000 Erased: OK
+
SF: Detected S25FL256S_64K with page size 256 Bytes, erase size 64 KiB, total 32 MiB
device 0 offset 0x200000, size 0x461790
+
SF: 6291456 bytes @ 0x180000 Erased: OK
SF: 4593552 bytes @ 0x200000 Written: OK
+
device 0 offset 0x180000, size 0x600000
 +
SF: 6291456 bytes @ 0x180000 Written: OK
 
link up on port 0, speed 100, full duplex
 
link up on port 0, speed 100, full duplex
 
Using cpsw device
 
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
+
TFTP from server 192.168.0.23; our IP address is 192.168.0.94
Filename 'diva/am335x-sbcd.dtb'.
+
Filename 'diva/linux/divelk-3.0.0_am335x-divelk.dtb'.
Load address: 0x88000000
+
Load address: 0x80f80000
Loading: #########
+
Loading: ########
         598.6 KiB/s
+
         918.9 KiB/s
 
done
 
done
Bytes transferred = 44754 (aed2 hex)
+
Bytes transferred = 39558 (9a86 hex)
SF: 262144 bytes @ 0x1c0000 Erased: OK
+
SF: Detected S25FL256S_64K with page size 256 Bytes, erase size 64 KiB, total 32 MiB
device 0 offset 0x1c0000, size 0xaed2
+
SF: 262144 bytes @ 0x140000 Erased: OK
SF: 44754 bytes @ 0x1c0000 Written: OK
+
device 0 offset 0x140000, size 0x40000
 +
SF: 262144 bytes @ 0x140000 Written: OK
 +
U-Boot#
 
</pre>
 
</pre>
  
Line 333: Line 221:
 
</pre>
 
</pre>
  
=== NAND flash ===
+
== NAND flash ==
  
 
We assume that the following environment variables are present in u-boot:
 
We assume that the following environment variables are present in u-boot:
  
 
<pre>
 
<pre>
nand_updatek=nand erase.part nand-kernel; nand write ${loadaddr} nand-kernel ${filesize}
+
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_updatefdt=nand erase.part NAND.fdt; nand write ${fdtaddr} NAND.fdt ${filesize}
 
+
nandargs=setenv bootargs ubi.mtd=NAND.file-system root=ubi0:diva-rootfs rootfstype=ubifs rw rootwait=1
nand_loadk=nand read ${loadaddr} nand-kernel
+
nand_nand=nand read ${kloadaddr} NAND.kernel; nand read ${fdtaddr} NAND.fdt; run nandargs addeth addcons addmisc configid_fixupfdt; bootm ${kloadaddr} - ${fdtaddr}
nand_loadfdt=nand read ${fdtaddr} nand-fdt
 
nand_nand=run nand_loadk nand_loadfdt nandargs addcons addmisc; if run configid_fixupfdt; then bootm ${loadaddr} - ${fdtaddr}; fi
 
 
</pre>
 
</pre>
  
Line 351: Line 237:
  
 
<pre class="board-terminal">
 
<pre class="board-terminal">
run loadk nand_updatek loadfdt nand_updatefdt
+
=> run loadk nand_updatek loadfdt nand_updatefdt
 
</pre>
 
</pre>
  
Line 357: Line 243:
  
 
<pre class="board-terminal">
 
<pre class="board-terminal">
=> run loadk nand_updatek loadfdt nand_updatefdt
+
U-Boot# run loadk nand_updatek loadfdt nand_updatefdt
 
link up on port 0, speed 100, full duplex
 
link up on port 0, speed 100, full duplex
 
Using cpsw device
 
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
+
TFTP from server 192.168.0.23; our IP address is 192.168.0.94
Filename 'diva/uImage'.
+
Filename 'diva/linux/divelk-3.0.0_uImage'.
Load address: 0x82000000
+
Load address: 0x80007fc0
 
Loading: #################################################################
 
Loading: #################################################################
 
         #################################################################
 
         #################################################################
Line 373: Line 259:
 
         #################################################################
 
         #################################################################
 
         #################################################################
 
         #################################################################
         #################################################################
+
         #
         #################################################################
+
         1.6 MiB/s
        #################################################################
 
        #####################################################
 
        1010.7 KiB/s
 
 
done
 
done
Bytes transferred = 4593552 (461790 hex)
+
Bytes transferred = 3332840 (32dae8 hex)
  
 
NAND erase.part: device 0 offset 0x2c0000, size 0x600000
 
NAND erase.part: device 0 offset 0x2c0000, size 0x600000
Line 385: Line 268:
 
OK
 
OK
  
NAND write: device 0 offset 0x2c0000, size 0x461790
+
NAND write: device 0 offset 0x2c0000, size 0x32dae8
  4593552 bytes written: OK
+
  3332840 bytes written: OK
 
link up on port 0, speed 100, full duplex
 
link up on port 0, speed 100, full duplex
 
Using cpsw device
 
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
+
TFTP from server 192.168.0.23; our IP address is 192.168.0.94
Filename 'diva/am335x-sbcd.dtb'.
+
Filename 'diva/linux/divelk-3.0.0_am335x-divelk.dtb'.
Load address: 0x88000000
+
Load address: 0x80f80000
Loading: #########
+
Loading: ########
         682.6 KiB/s
+
         954.1 KiB/s
 
done
 
done
Bytes transferred = 44754 (aed2 hex)
+
Bytes transferred = 37129 (9109 hex)
  
 
NAND erase.part: device 0 offset 0x2a0000, size 0x20000
 
NAND erase.part: device 0 offset 0x2a0000, size 0x20000
Line 401: Line 284:
 
OK
 
OK
  
NAND write: device 0 offset 0x2a0000, size 0xaed2
+
NAND write: device 0 offset 0x2a0000, size 0x9109
  44754 bytes written: OK
+
  37129 bytes written: OK
 +
U-Boot#
 
</pre>
 
</pre>
  

Revision as of 14:42, 27 March 2018

Info Box
Diva-am335x-overview.png Applies to Diva

History[edit | edit source]

Version Date DIVELK version Notes
3.0.0 June 2017 DIVELK 3.0.0

Introduction[edit | edit source]

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 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[edit | edit source]

This is a common step for both booting options.

  • Boot the system via SD or NFS as described into the 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 MTD partitions can be dumped with /proc/mtd (the partition's name should be self-explanatory)


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:~#


200px-Emblem-important.svg.png

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 /proc/mtd to match your specific layout


  • Format and initialize nand-ubi partition, which in our case is mtd18, using UBI with:
ubiformat /dev/mtd18
ubiattach -m 18
ubimkvol /dev/ubi0 -N diva-rootfs -m

E.g.

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:~#
  • Now mount the UBI volume using UBIFS in a temporary directory
mkdir -p /mnt/nand
mount -t ubifs ubi0_0 /mnt/nand

E.g.:

root@diva:~# mkdir -p /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:~#
  • you can now extract the root file system into that directory
root@diva:~# tar zxvf divelk-image-matrix-diva.tar.gz -C /mnt/nand
  • finally, you need to cleanly umount and detach the MTD partition
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:~#

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

nand_args=setenv bootargs root=ubi0:diva-rootfs rootfstype=ubifs rw ubi.mtd=18

Program boot images[edit | edit source]

NOR flash[edit | edit source]

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

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 ${kloadaddr} - ${fdtaddr}; fi
  • Update the bootfile and fdtfile 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
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#


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

=> setenv bootcmd run spi_nand
=> saveenv

NAND flash[edit | edit source]

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

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}
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}


  • Update the bootfile and fdtfile 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
=> run loadk nand_updatek loadfdt nand_updatefdt

E.g.:

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/linux/divelk-3.0.0_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/linux/divelk-3.0.0_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#


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

=> setenv bootcmd run nand_nand
=> saveenv