Standalone boot (XUELK)

From DAVE Developer's Wiki
Jump to: navigation, search
Info Box
AXEL ULite-top.png Applies to AXEL ULite
SBC Lynx-top.png Applies to SBC Lynx

History[edit | edit source]

Version Date XUELK version Hardware Part Nr Notes
1.0.0 November 2016 XUELK 1.0.0 XUBE0000I1R

Introduction[edit | edit source]

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

We'll explain how to program and configure an SBC Lynx to boot in standalone mode, without the need of a system microSD card or an 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 flash storage, all images and the root file system will be fetched from NAND flash.

Storing root file system into 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@sbc-lynx:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00800000 00020000 "nand-uboot"
mtd1: 00100000 00020000 "nand-env1"
mtd2: 00100000 00020000 "nand-env2"
mtd3: 00100000 00020000 "nand-fdt"
mtd4: 00100000 00020000 "nand-spare"
mtd5: 00800000 00020000 "nand-kernel"
mtd6: 00400000 00020000 "nand-splash"
mtd7: 3e800000 00020000 "nand-ubi"
mtd8: 00100000 00010000 "spi-uboot"
mtd9: 00040000 00010000 "spi-env1"
mtd10: 00040000 00010000 "spi-env2"
mtd11: 00080000 00010000 "spi-dtb"
mtd12: 00600000 00010000 "spi-kernel"
mtd13: 00400000 00010000 "spi-splash"
mtd14: 01400000 00010000 "spi-free"


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

Flashing the root file system from a tarball archive[edit | edit source]

This example is using a tarball compressed archive to be extracted into a formatted and mounted UBI File System.

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

E.g.

root@sbc-lynx:~# 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@sbc-lynx:~# 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@sbc-lynx:~# 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
  • 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@sbc-lynx:~# mkdir -p /mnt/nand
root@sbc-lynx:~# 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
  • you can now extract the root file system into that directory
tar xvjf xuelk-1.0.0_lynx-image-gui-sbc-lynx.tar.bz2 -C /mnt/nand
  • finally, you need to cleanly umount and detach the MTD partition
umount /mnt/nand/
ubidetach -m 7

E.g.

root@sbc-lynx:~# umount /mnt/nand/
[ 2446.743091] UBIFS: un-mount UBI device 0, volume 0
[ 2446.749670] UBIFS: background thread "ubifs_bgt0_0" stops
root@sbc-lynx:~# ubidetach -m 7
[ 2450.738153] UBI: detaching mtd7 from ubi0
[ 2450.759527] UBI: mtd7 is detached from ubi0

You can now safely reboot or turn off the system.

Creating and flashing a UBI root file system image[edit | edit source]

This example is using the UBI tools for creating an UBI File System image.

  • Prepare and initialize a UBI image to be flashed with:
mkfs.ubifs
ubinize

E.g. preparing an image for a 512MB SLC NAND with:

  • 2048 bytes page size (parameter -m)
  • 126976 bytes LEB size (parameter -e)
  • 4095 LEBs (parameter -c)
  • an already extracted root file system into the directory xuelk-2.0.1-rfs
root@sbc-lynx:~# mkfs.ubifs -m 2048 -e 126976 -c 4095 -r xuelk-2.0.1-rfs -o xuelk-2.0.1_lynx-image-core-sbc-lynx.ubifs

the output file is then:

root@sbc-lynx:~# ls -la xuelk-2.0.1_lynx-image-core-sbc-lynx.ubifs
-rw-r--r-- 1 root root 41140224 Mar  2  2020 xuelk-2.0.1_lynx-image-core-sbc-lynx.ubifs
root@sbc-lynx:~#

The ubifs file can be used for creating a UBI image using ubinize with a proper configuration file:

root@sbc-lynx:~# cat lynx-ubi.cfg
[rootfs]
mode=ubi
image=xuelk-2.0.1_lynx-image-core-sbc-lynx.ubifs
vol_id=0
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
vol_alignment=1
root@sbc-lynx:~# ubinize -o xuelk-2.0.1_lynx-image-core-sbc-lynx.img -m 2048 -p 128KiB -s 2048 lynx-ubi.cfg
ubinize: volume size was not specified in section "rootfs", assume minimum to fit image "xuelk-2.0.1_lynx-image-core-sbc-lynx.ubifs"41140224 bytes (39.2 MiB)
root@sbc-lynx:~# ls -la xuelk-2.0.1_lynx-image-core-sbc-lynx.img
-rw-r--r-- 1 root root 42729472 Mar  2  2020 xuelk-2.0.1_lynx-image-core-sbc-lynx.img
root@sbc-lynx:~#

Then, the UBI image can be directly flashed on NAND using ubiformat:

root@sbc-lynx:~# ubiformat /dev/mtd7 -f xuelk-2.0.1_lynx-image-core-sbc-lynx.img
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 50
ubiformat: flashing eraseblock 325 -- 100 % complete
ubiformat: formatting eraseblock 7999 -- 100 % complete
root@sbc-lynx:~#

Flashing the UBI image using u-boot[edit | edit source]

Once created, it is possibile to flash the UBI image directly on u-boot, e.g.

  • load the previosuly created UBI img on memory using tftp
=> tftp ${loadaddr} lynx/xuelk-2.0.1_lynx-image-core-sbc-lynx.img
Using FEC0 device
TFTP from server 192.168.0.13; our IP address is 192.168.0.90
Filename 'lynx/xuelk-2.0.1_lynx-image-core-sbc-lynx.img'.
Load address: 0x80800000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
...
...
...
         #################################################################
         #################################################################
         #################################################################
         ######################################
         1.3 MiB/s
done
Bytes transferred = 42729472 (28c0000 hex)
=>
  • erase the nand part
=> pri mtdparts
mtdparts=mtdparts=gpmi-nand:8M(nand-uboot),1M(nand-env1),1M(nand-env2),1M(nand-fdt),1M(nand-spare),8M(nand-kernel),4M(nand-splash),-(nand-ubi)
=> nand erase.part nand-ubi

NAND erase.part: device 0 offset 0x1800000, size 0x3e800000
Erasing at 0x3ffe0000 -- 100% complete.
OK
=>
  • flash the image using nand write
=> nand write.trimffs ${loadaddr} nand-ubi ${filesize}

NAND write: device 0 offset 0x1800000, size 0x28c0000
 42729472 bytes written: OK
=>

Once flashed, it is possible to verify the UBI filesystem mounting the partition:

=> ubi part nand-ubi
ubi0: attaching mtd1
ubi0: scanning is finished
ubi0: volume 0 ("rootfs") re-sized from 324 to 7836 LEBs
ubi0: attached mtd1 (name "mtd=7", size 1000 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
ubi0: good PEBs: 8000, bad PEBs: 0, corrupted PEBs: 0
ubi0: user volume: 1, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 969162404
ubi0: available PEBs: 0, total reserved PEBs: 8000, PEBs reserved for bad PEB handling: 160
=> ubifsmount ubi0:rootfs
=> ubifsls
<DIR>        4816  Wed Oct 04 07:27:18 2017  bin
<DIR>         160  Fri Sep 29 14:38:33 2017  dev
<DIR>        5168  Wed Oct 04 07:27:36 2017  etc
<DIR>        4760  Tue Oct 03 16:38:32 2017  lib
<DIR>         160  Fri Sep 29 14:38:33 2017  mnt
<DIR>         160  Fri Sep 29 14:38:33 2017  run
<DIR>         160  Fri Sep 29 14:38:34 2017  tmp
<DIR>         160  Fri Sep 29 14:38:33 2017  sys
<DIR>         744  Fri Sep 29 15:18:32 2017  var
<DIR>         672  Fri Sep 29 15:08:41 2017  usr
<DIR>         320  Wed Oct 04 07:27:03 2017  boot
<DIR>         224  Wed Oct 04 07:27:01 2017  home
<DIR>         160  Fri Sep 29 14:38:33 2017  proc
<DIR>        5176  Wed Oct 04 07:27:20 2017  sbin
<DIR>         160  Fri Sep 29 14:38:33 2017  media
=>

You can now safely boot the system.

u.boot configuration[edit | edit source]

In U-Boot environment check the following variable, which must contain the same MTD partition number used above

nand_args=setenv bootargs root=ubi0:rootfs rootfstype=ubifs rw ubi.mtd=7

Storing boot images ...[edit | edit source]

... into NOR flash[edit | edit source]

We assume that the following variables are defined in the U-Boot environment:

load=tftp ${loadaddr} ${uboot}
loadk=tftpboot ${loadaddr} ${serverip}:${bootfile}
loadfdt=tftpboot ${fdtaddr} ${serverip}:${fdtfile}
spi_updatek=sf erase 200000 800000; sf write ${loadaddr} 200000 ${filesize}
spi_updatefdt=sf erase 180000 80000; sf write ${fdtaddr} 180000 ${filesize}
spi_loadk=sf read ${loadaddr} 200000 800000
spi_loadfdt=sf read ${fdtaddr} 180000 80000
spi_nand=sf probe; run spi_loadk spi_loadfdt nandargs addcons addmisc; if run configid_fixupfdt; then bootm ${loadaddr} - ${fdtaddr}; fi
spi_update=sf probe; sf erase 0 +${filesize};sf write ${loadaddr} 400 ${filesize}

U-Boot[edit | edit source]

The following example shows how to store a U-Boot image in NOR flash replacing the existing one (version xuelk-2.0.0). The variable uboot is edited to select a specific U-Boot image which is download from the TFTP server (version xuelk-2.0.2) over the Ethernet connection.

U-Boot 2016.03-xuelk-2.0.0 (Sep 27 2017 - 16:52:39 +0200), Build: jenkins-XUELK_U-Boot-35

CPU:   Freescale i.MX6UL rev1.1 528 MHz (running at 396 MHz)
CPU:   Industrial temperature grade (-40C to 105C) at 34C
Reset cause: POR
Environment: SPI Flash
I2C:   ready
DRAM:  512 MiB
Relocating to 9ff24000, new gd at 9ef13eb8, sp at 9ef13e90
WARNING: CB ConfigID is UNLOCKED, use configid cb_lock 0 to lock it
PMIC: PFUZE3000 DEV_ID=0x30 REV_ID=0x11
NAND:  2048 MiB
MMC:   FSL_SDHC: 0
SF: Detected S25FL256S_64K with page size 256 Bytes, erase size 64 KiB, total 32 MiB
In:    serial
Out:   serial
Err:   serial
MMC: no card present
SOM ConfigID#: 00000013
SOM UniqueID#: e6b3f362:262c61d4
CB ConfigID#: 00000030
CB UniqueID#: 00000000:00000000
Board: MX6UL SBC Lynx
Net:   FEC0
Normal Boot
Hit any key to stop autoboot:  0
=> editenv uboot
edit: lynx/u-boot/xuelk-2.0.2_mx6ul_lynx_spi_u-boot.imx
=> run load
Using FEC0 device
TFTP from server 192.168.0.23; our IP address is 192.168.0.80
Filename 'lynx/u-boot/xuelk-2.0.2_mx6ul_lynx_spi_u-boot.imx'.
Load address: 0x80800000
Loading: #################################################################
         ##############################################
         1.8 MiB/s
done
Bytes transferred = 565292 (8a02c hex)
=> run update
## Error: "update" not defined
=> run spi_update
SF: Detected S25FL256S_64K with page size 256 Bytes, erase size 64 KiB, total 32 MiB
SF: 589824 bytes @ 0x0 Erased: OK
device 0 offset 0x400, size 0x8a02c
SF: 565292 bytes @ 0x400 Written: OK
=> res
resetting ...


U-Boot 2016.03-xuelk-2.0.2 (Jan 12 2018 - 09:14:35 +0100), Build: jenkins-XUELK_U-Boot-38

CPU:   Freescale i.MX6UL rev1.1 528 MHz (running at 396 MHz)
CPU:   Industrial temperature grade (-40C to 105C) at 44C
Reset cause: POR
Environment: SPI Flash
I2C:   ready
DRAM:  512 MiB
Relocating to 9ff24000, new gd at 9ef13eb8, sp at 9ef13e90
WARNING: CB ConfigID is UNLOCKED, use configid cb_lock 0 to lock it
PMIC: PFUZE3000 DEV_ID=0x30 REV_ID=0x11
NAND:  2048 MiB
MMC:   FSL_SDHC: 0
SF: Detected S25FL256S_64K with page size 256 Bytes, erase size 64 KiB, total 32 MiB
In:    serial
Out:   serial
Err:   serial
MMC: no card present
SOM ConfigID#: 00000013
SOM UniqueID#: e6b3f362:262c61d4
CB ConfigID#: 00000030
CB UniqueID#: 00000000:00000000
Board: MX6UL SBC Lynx
Net:   FEC0
Normal Boot
Hit any key to stop autoboot:  0
=>

Linux kernel image and device tree[edit | edit source]

  • 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
=> sf probe; run loadk spi_updatek loadfdt spi_updatefdt

E.g.:

=> 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
Using FEC0 device
TFTP from server 192.168.0.23; our IP address is 192.168.0.86
Filename 'lynx/linux/xuelk-1.1.0_uImage'.
Load address: 0x80800000
Loading: #################################################################
[...]
         ##############
         2 MiB/s
done
Bytes transferred = 6723656 (669848 hex)
SF: 8388608 bytes @ 0x200000 Erased: OK
SF: 6723656 bytes @ 0x200000 Written: OK
Using FEC0 device
TFTP from server 192.168.0.23; our IP address is 192.168.0.86
Filename 'lynx/linux/xuelk-1.1.0_imx6ul-lynx-som0010.dtb'.
Load address: 0x83000000
Loading: #######
         1.6 MiB/s
done
Bytes transferred = 31663 (7baf hex)
SF: 524288 bytes @ 0x180000 Erased: OK
SF: 31663 bytes @ 0x180000 Written: OK


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

=> setenv bootcmd run spi_nand
=> saveenv

... into 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 ${loadaddr} 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
nand_nand=run nand_loadk nand_loadfdt nandargs addip addcons addmisc; bootm ${loadaddr} - ${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.:

=> run loadk nand_updatek loadfdt nand_updatefdt
Using FEC0 device
TFTP from server 192.168.0.13; our IP address is 192.168.0.77
Filename 'lynx/linux/xuelk-1.0.0_uImage'.
Load address: 0x80800000
Loading: #################################################################
         #################################################################
[...]
         ###########################
         1.9 MiB/s
done
Bytes transferred = 6459304 (628fa8 hex)

NAND erase.part: device 0 offset 0xc00000, size 0x800000
Skipping bad block at  0x010a0000
Erasing at 0x13e0000 -- 100% complete.
OK

NAND write: device 0 offset 0xc00000, size 0x628fa8
Skip bad block 0x010a0000
 6459304 bytes written: OK
Using FEC0 device
TFTP from server 192.168.0.13; our IP address is 192.168.0.77
Filename 'lynx/linux/xuelk-1.0.0_imx6ul-lynx-som000c.dtb'.
Load address: 0x83000000
Loading: #######
         1.3 MiB/s
done
Bytes transferred = 31168 (79c0 hex)

NAND erase.part: device 0 offset 0xa00000, size 0x100000
Erasing at 0xae0000 -- 100% complete.
OK

NAND write: device 0 offset 0xa00000, size 0x79c0
 31168 bytes written: OK


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

=> setenv bootcmd run nand_nand
=> saveenv