diff --git a/README.md b/README.md index 1daf94b9628b9f1ad8c05b41f4ab3a90b5022983..b21f0a843afa43312c07441bb0555804c2e30e57 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ In my case **\<PATH_TO_SCALP_FIRMWARE_PROJECT\>** corresponds to /home/jo/Docume ### Bug in the U-Boot config with the selection of the ZYNQ_SPI driver -Despite the fact that some drivers and commands are preselected in the U-Boot configuration specific to the SCALP board, they are not automatically taken into account. It is therefore necessary to select the ZYNQ\_SPI driver manually. The same applies to the drivers relating to the Fixed-Link PHY (PHY\_FIXED) and Xilinx Ethernet PHYs support (PHY\_XILINX) and to the commands relating to the UBIFS file system (CMD\_UBI and CMD\_UBIFS). +Despite the fact that some drivers and commands are preselected in the U-Boot configuration specific to the SCALP board, they are not automatically taken into account. It is therefore necessary to select the ZYNQ\_SPI driver manually. The same applies to the drivers relating to the Fixed-Link PHY (PHY\_FIXED) and Xilinx Ethernet PHYs support (PHY\_XILINX) and to the commands relating to the UBIFS file system (CMD\_UBI and CMD\_UBIFS) and the UBIFS environment (ENV\_IS\_IN\_UBI, ENV\_UBI\_PART, ENV\_UBI\_VOLUME and ENV\_UBI\_VID\_OFFSET). First, you need to open the U-Boot configuration menu, after cleaning up the project. @@ -221,11 +221,23 @@ U-Boot 2020.01 Configuration [*] Enable UBIFS - Unsorted block images filesystem commands (NEW) (select with spacebar) ``` +and... + +``` +U-Boot 2020.01 Configuration + Environment ---> + [*] Environment in a UBI volume + (0x100000) Environment Size + (ubi) UBI partition name + (uenv-vol) UBI volume name + (0) ubi environment VID offset +``` + Then select 2 times EXIT... And save the configuration. -**You can optionally return to the U-Boot configuration menu to check that the ZYNQ_SPI, PHY_FIXED and PHY_XILINX drivers and the CMD_UBI and CMD_UBIFS commands have been taken into account.** +**You can optionally return to the U-Boot configuration menu to check that the ZYNQ_SPI, PHY_FIXED and PHY_XILINX drivers and the CMD_UBI and CMD_UBIFS commands and the UBI environment have been taken into account.** ### Build the PetaLinux project @@ -254,18 +266,7 @@ $ find . -name ubifs.o > ... ``` -### Creation of the basic image of the U-Boot environment - -The image content can be produced by using the **mkenvimage** command. - -``` -Do not use this command : - -$ echo -e "custom_board_name=\"Zynq Scalp Board\"\ncustom_board_version=\"RevB 2008\"\ncustom_board_vendor=\"Hepia CoRES - LSN\"" > images/linux/scalp-u-boot.env -$ /tools/u-boot-tools/mkenvimage -s 0x20000 -o images/linux/scalp-u-boot.env.bin images/linux/scalp-u-boot.env -``` - -In my case, I copied the tools produced by U-Boot into the **/tools/u-boot-tools/** folder. +**And you can do the same for other ".o" binary files related to other U-Boot configuration settings.** ### Create UBIFS images @@ -279,14 +280,29 @@ Extract the root file system to the previously created directory. ``` $ cd images/linux -$ mkdir rootfs -$ tar -xzvpf rootfs.tar.gz -C rootfs +$ mkdir rootfs-vol +$ tar -xzvpf rootfs.tar.gz -C rootfs-vol ``` -**Do not go to the rootfs folder** and create a second folder named datafs. +**Do not go to the rootfs folder** and create the other folders associated with the different UBI volumes. + +**For information purposes only** + +* Image : **ubi** +* Size : **28311552 Bytes - 0x1B00000** + +| **Names** | uenv-vol | datafs-vol | rootfs-vol | +|-------------------|----------|------------|------------| +| **Sizes (Bytes)** | 2097152 | 8519680 | 17039360 | + +**The last PEB are reserved for the UBI/UBIFS file system.** + +``` +$ mkdir uenv-vol datafs-vol +``` ``` -$ mkdir datafs +$ cp image.ub datafs-vol/ ``` Then, both rootfs and datafs UBIFS images must be created respecting the geometrical configuration of the flash memory. @@ -295,46 +311,56 @@ Then, both rootfs and datafs UBIFS images must be created respecting the geometr **Information obtained using the sf probe command from U-Boot.** -| QSPI Flash memory size | 33554432 Bytes | -|------------------------|----------------| -| Page size | 256 Bytes | -| Erase block size | 65536 Bytes | -| Max. erase blocks | 512 | +| **QSPI Flash memory size** | **33554432 Bytes** | +|----------------------------|--------------------| +| Page size | 256 Bytes | +| Erase block size | 65536 Bytes | +| Max. erase blocks | 512 | **This information alone is not sufficient. Please refer to subsection [Geometric organisation](#howto-obtain-information-about-the-geometric-organisation-of-the-spi-nor-memory).** ``` -$ sudo mkfs.ubifs -r ./rootfs -m 1 -e 65408 -c 257 -o rootfs.ubifs -$ sudo mkfs.ubifs -r ./datafs -m 1 -e 65408 -c 33 -o datafs.ubifs +$ sudo mkfs.ubifs -r ./rootfs-vol -m 1 -e 65408 -c 260 -o rootfs-vol.ubifs +$ sudo mkfs.ubifs -r ./datafs-vol -m 1 -e 65408 -c 130 -o datafs-vol.ubifs +$ sudo mkfs.ubifs -r ./uenv-vol -m 1 -e 65408 -c 32 -o uenv-vol.ubifs ``` + Next, a configuration file must be created to define the UBI volume. ``` $ echo \ -"[datafs-volume] +"[uenv-volume] mode=ubi -image=datafs.ubifs +image=uenv-vol.ubifs vol_id=0 -vol_size=2MiB +vol_size=2048KiB vol_type=static -vol_name=datafs +vol_name=uenv-vol -[rootfs-volume] +[datafs-volume] mode=ubi -image=rootfs.ubifs +image=datafs-vol.ubifs vol_id=1 -vol_size=16MiB +vol_size=8320KiB +vol_type=static +vol_name=datafs-vol + +[rootfs-volume] +mode=ubi +image=rootfs-vol.ubifs +vol_id=2 +vol_size=16640KiB vol_type=dynamic -vol_name=rootfs +vol_name=rootfs-vol vol_flags=autoresize " \ -> ubiconf.ini +> ubi-image.ini ``` Next, the UBI volume must be created. ``` -$ sudo ubinize -p 65536 -m 1 -s 1 -O 64 -o ubifs.ubi ubiconf.ini +$ sudo ubinize -p 65536 -m 1 -s 1 -O 64 -o ubi-image.ubi ubi-image.ini $ cd ../.. ``` @@ -365,18 +391,19 @@ From old U-Boot source files. From U-Boot ... ``` -ScalpZynq> ubi part ubifs -ubi0: attaching mtd5 +ScalpZynq> ubi part ubi +ubi0: detaching mtd2 +ubi0: mtd2 is detached +ubi0: attaching mtd2 ubi0: scanning is finished -ubi0: volume 1 ("rootfs") re-sized from 257 to 263 LEBs -ubi0: attached mtd5 (name "ubifs", size 18 MiB) +ubi0: attached mtd2 (name "ubi", size 27 MiB) ubi0: PEB size: 65536 bytes (64 KiB), LEB size: 65408 bytes <----- -e 65408 / -p 65536 ubi0: min./max. I/O unit sizes: 1/256, sub-page size 1 <----- -m 1 / -s 1 ubi0: VID header offset: 64 (aligned 64), data offset: 128 <----- -O 64 -ubi0: good PEBs: 300, bad PEBs: 0, corrupted PEBs: 0 -ubi0: user volume: 2, internal volumes: 1, max. volumes count: 128 -ubi0: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 1170760348 -ubi0: available PEBs: 0, total reserved PEBs: 300, PEBs reserved for bad PEB handling: 0 +ubi0: good PEBs: 432, bad PEBs: 0, corrupted PEBs: 0 +ubi0: user volume: 3, internal volumes: 1, max. volumes count: 128 +ubi0: max/mean erase counter: 2/0, WL threshold: 4096, image sequence number: 1976423558 +ubi0: available PEBs: 0, total reserved PEBs: 432, PEBs reserved for bad PEB handling: 0 ``` ``` @@ -387,30 +414,45 @@ Volume information dump: alignment 1 data_pad 0 vol_type 4 - name_len 6 + name_len 8 usable_leb_size 65408 - used_ebs 13 - used_bytes 850304 - last_eb_bytes 65408 + used_ebs 17 + used_bytes 1048576 + last_eb_bytes 2048 corrupted 0 upd_marker 0 skip_check 0 - name datafs + name uenv-vol Volume information dump: vol_id 1 - reserved_pebs 263 + reserved_pebs 131 + alignment 1 + data_pad 0 + vol_type 4 + name_len 10 + usable_leb_size 65408 + used_ebs 124 + used_bytes 8110592 + last_eb_bytes 65408 + corrupted 0 + upd_marker 0 + skip_check 0 + name datafs-vol +Volume information dump: + vol_id 2 + reserved_pebs 264 alignment 1 data_pad 0 vol_type 3 - name_len 6 + name_len 10 usable_leb_size 65408 - used_ebs 263 - used_bytes 17202304 + used_ebs 264 + used_bytes 17267712 last_eb_bytes 65408 corrupted 0 upd_marker 0 skip_check 0 - name rootfs + name rootfs-vol Volume information dump: vol_id 2147479551 reserved_pebs 2 @@ -426,15 +468,16 @@ Volume information dump: upd_marker 0 skip_check 0 name layout volume + ``` ``` ScalpZynq> ubi info -UBI: MTD device name: "ubifs" -UBI: MTD device size: 18 MiB +UBI: MTD device name: "ubi" +UBI: MTD device size: 27 MiB UBI: physical eraseblock size: 65536 bytes (64 KiB) UBI: logical eraseblock size: 65408 bytes -UBI: number of good PEBs: 300 +UBI: number of good PEBs: 432 UBI: number of bad PEBs: 0 UBI: smallest flash I/O unit: 1 UBI: VID header offset: 64 (aligned 64) @@ -442,30 +485,33 @@ UBI: data offset: 128 UBI: max. allowed volumes: 128 UBI: wear-leveling threshold: 4096 UBI: number of internal volumes: 1 -UBI: number of user volumes: 2 +UBI: number of user volumes: 3 UBI: available PEBs: 0 -UBI: total number of reserved PEBs: 300 +UBI: total number of reserved PEBs: 432 UBI: number of PEBs reserved for bad PEB handling: 0 -UBI: max/mean erase counter: 1/0 +UBI: max/mean erase counter: 2/0 + ``` ### QSPI firmware packaging ``` -$ petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --fpga images/linux/system.bit --u-boot --kernel --offset 0x540000 --dtb images/linux/system.dtb --offset 0x520000 --force - - - -petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --fpga images/linux/system.bit --u-boot --kernel --offset 0x540000 --dtb images/linux/system.dtb --offset 0x520000 --add images/linux/ubifs.ubi --offset 0xD40000 --force - -dd if=/dev/zero of=images/linux/BOOT.BIN bs=1 count=$((33554432-$(stat -c%s images/linux/BOOT.BIN))) seek=$(stat -c%s images/linux/BOOT.BIN) && wc -c images/linux/BOOT.BIN +$ export SCALP_QSPI_NOR_SIZE_IN_MiB=32 +``` +We start by packaging the BOOT.BIN firmware. +``` +$ petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --fpga images/linux/system.bit --u-boot --add images/linux/ubi-image.ubi --offset 0x500000 --force +``` -Do not use this command : +Zeros are added at the end of the BOOT.BIN file up to the size of the SPI NOR memory. -$ petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --offset 0x0 --fpga images/linux/system.bit --u-boot --add images/linux/scalp-u-boot.env.bin --offset 0x500000 --kernel --offset 0x540000 --dtb images/linux/system.dtb --offset 0x520000 --force ``` +$ dd if=/dev/zero of=images/linux/BOOT.BIN bs=1 count=$(($((${SCALP_QSPI_NOR_SIZE_IN_MiB}*1024*1024))-$(stat -c%s images/linux/BOOT.BIN))) seek=$(stat -c%s images/linux/BOOT.BIN) && wc -c images/linux/BOOT.BIN +``` + +**This is necessary to prevent a new UBI/UBIFS file system from being partially overwritten with an old UBI/UBIFS file system. In this case, the UBI/UBIFS file system will appear corrupted and errors will appear. The fact that two different versions of a file system can be partially overlapped is due to the fact that the program that flash the memory does not erase the entire memory, but only partially, up to the size of the BOOT.BIN firmware.** The produced binary file can be found in the **./images/linux** folder. The **FIT image** of the Linux kernel is located at the address **0x540000**. @@ -479,53 +525,21 @@ List of MTD devices: - min I/O: 0x1 bytes - 0x000000000000-0x000002000000 : "nor0" - 0x000000000000-0x000000500000 : "boot" - - 0x000000500000-0x000000520000 : "bootenv" - - 0x000000520000-0x000000540000 : "dtb" - - 0x000000540000-0x000000d40000 : "fitimage" - - 0x000000d40000-0x000002000000 : "ubifs" + - 0x000000500000-0x000002000000 : "ubi" ``` ``` -device nor0 <nor_flash>, # parts = 5 +device nor0 <nor_flash>, # parts = 2 #: name size net size offset mask_flags - 0: boot 0x00500000 0x00500000 0x00000000 1 - 1: bootenv 0x00020000 0x00020000 0x00500000 1 - 2: dtb 0x00020000 0x00020000 0x00520000 1 - 3: fitimage 0x00800000 0x00800000 0x00540000 1 - 4: ubifs 0x012c0000 0x012c0000 0x00d40000 0 + 0: boot 0x00500000 0x00500000 0x00000000 1 + 1: ubi 0x01b00000 0x01b00000 0x00500000 0 active partition: nor0,0 - (boot) 0x00500000 @ 0x00000000 defaults: mtdids : nor0=nor_flash -mtdparts: mtdparts=nor_flash:5m(boot)ro,128k(bootenv)ro,128k(dtb)ro,8m(fitimage)or,-(ubifs) -``` - -``` -partition@boot { - label = "boot"; - reg = <0x0 0x500000>; -}; - -partition@bootenv { - label = "bootenv"; - reg = <0x500000 0x20000>; -}; - -partition@dtb { - label = "dtb"; - reg = <0x520000 0x20000>; -}; - -partition@fitimage { - label = "fitimage"; - reg = <0x540000 0x800000>; -}; +mtdparts: mtdparts=nor_flash:5m(boot)ro,-(ubi) -partition@ubifs { - label = "ubifs"; - reg = <0xD40000 0x12C0000>; -}; ``` ``` @@ -542,24 +556,24 @@ partition@ubi { }; ``` - -* Image : **ubi** -* Size : **28311552 Bytes - 0x1B00000** - -| **Names** | uenv-vol | uenv2-vol | datafs-vol | rootfs-vol | -|-------------------|----------|-----------|------------|------------| -| **Sizes (Bytes)** | 20000 | 20000 | 8126464 | 19922944 | - ### Flash firmware on QSPI memory **First of all, to flash the board, it is necessary to set switch SW1 (BOOT MODE) in JTAG mode. Then, once the card is flashed, it is necessary to set switch SW1 back in QSPI mode and reconnect the board.** +**Caution: The frequency used for the operation of the JTAG probe is 30 [MHz]. Check that your JTAG probe supports this operating frequency.** + If you are using a single JTAG probe. +**With a check of the written blocks...** + ``` $ program_flash -blank_check -verify -frequency 30000000 -f images/linux/BOOT.BIN -offset 0 -flash_type qspi-x4-single -fsbl images/linux/zynq_fsbl.elf -cable type xilinx_tcf url TCP:127.0.0.1:3121 +``` + +**Or, without a check of the written blocks...** -$ program_flash -f images/linux/BOOT.BIN -offset 0 -flash_type qspi-x4-single -fsbl images/linux/zynq_fsbl.elf -cable type xilinx_tcf url TCP:127.0.0.1:3121 +``` +$ program_flash -frequency 30000000 -f images/linux/BOOT.BIN -offset 0 -flash_type qspi-x4-single -fsbl images/linux/zynq_fsbl.elf -cable type xilinx_tcf url TCP:127.0.0.1:3121 ``` The **program_flash** command is located in the Vitis installation folder **/\<VITIS_PATH\>/2020.2/bin/program_flash** or in the PetaLinux installation folder **/\<PETALINUX_PATH\>/2020.2/bin/tools/xsct/bin**. @@ -578,10 +592,22 @@ $ program_flash -jtagtarget > 4 Digilent 210299AFB167 > 5 jsn-JTAG-HS3-210299AFB167-4ba00477-0 (name arm_dap idcode 4ba00477) <-- target id 5 > 6 jsn-JTAG-HS3-210299AFB167-0373b093-0 (name xc7z015 idcode 0373b093) +``` + +**With a check of the written blocks...** + +``` +$ program_flash -blank_check -verify -frequency 30000000 -f images/linux/BOOT.BIN -offset 0 -flash_type qspi-x4-single -fsbl images/linux/zynq_fsbl.elf -target_id 2 -url TCP:127.0.0.1:3121 + +$ program_flash -blank_check -verify -frequency 30000000 -f images/linux/BOOT.BIN -offset 0 -flash_type qspi-x4-single -fsbl images/linux/zynq_fsbl.elf -target_id 5 -url TCP:127.0.0.1:3121 +``` -$ program_flash -f images/linux/BOOT.BIN -offset 0 -flash_type qspi-x4-single -fsbl images/linux/zynq_fsbl.elf -target_id 2 -url TCP:127.0.0.1:3121 +**Or, without a check of the written blocks...** -$ program_flash -f images/linux/BOOT.BIN -offset 0 -flash_type qspi-x4-single -fsbl images/linux/zynq_fsbl.elf -target_id 5 -url TCP:127.0.0.1:3121 +``` +$ program_flash -frequency 30000000 -f images/linux/BOOT.BIN -offset 0 -flash_type qspi-x4-single -fsbl images/linux/zynq_fsbl.elf -target_id 2 -url TCP:127.0.0.1:3121 + +$ program_flash -frequency 30000000 -f images/linux/BOOT.BIN -offset 0 -flash_type qspi-x4-single -fsbl images/linux/zynq_fsbl.elf -target_id 5 -url TCP:127.0.0.1:3121 ``` The **image.ub** file corresponds to the image of the Linux kernel, the device tree and the RamFS file system in FIT format. @@ -598,8 +624,67 @@ In my case, I copied the tools produced by U-Boot into the **/tools/u-boot-tools ### Howto access UBIFS partitions from U-Boot. +The SPI NOR memory is activated. + +``` +ScalpZynq> sf probe 0 0 0 +SF: Detected s25fl256s1 with page size 256 Bytes, erase size 64 KiB, total 32 MiB +``` + +We check the names of the MTD partitions that are available. + +``` +ScalpZynq> mtdparts + +device nor0 <nor_flash>, # parts = 2 + #: name size net size offset mask_flags + 0: boot 0x00500000 0x00500000 0x00000000 1 + 1: ubi 0x01b00000 0x01b00000 0x00500000 0 + +active partition: nor0,0 - (boot) 0x00500000 @ 0x00000000 +defaults: +mtdids : nor0=nor_flash +mtdparts: mtdparts=nor_flash:5m(boot)ro,-(ubi) +``` +The MTD partition that contains the volumes related to the UBI/UBIFS file system is activated. + +``` +ScalpZynq> ubi part ubi +ubi0: attaching mtd2 +ubi0: scanning is finished +ubi0: attached mtd2 (name "ubi", size 27 MiB) +ubi0: PEB size: 65536 bytes (64 KiB), LEB size: 65408 bytes +ubi0: min./max. I/O unit sizes: 1/256, sub-page size 1 +ubi0: VID header offset: 64 (aligned 64), data offset: 128 +ubi0: good PEBs: 432, bad PEBs: 0, corrupted PEBs: 0 +ubi0: user volume: 3, internal volumes: 1, max. volumes count: 128 +ubi0: max/mean erase counter: 2/0, WL threshold: 4096, image sequence number: 1976423558 +ubi0: available PEBs: 0, total reserved PEBs: 432, PEBs reserved for bad PEB handling: 0 +``` + +Mount the UBI/UBIFS volume you want. + +``` +ScalpZynq> ubifsmount ubi0:datafs-vol +``` + +We consult the UBI/UBIFS file system contained in the previously mounted volume. + +``` +ScalpZynq> ubifsls / + 6903052 Sun Mar 07 12:53:16 2021 image.ub +``` + +Finally, the previously mounted volume is unmounted. + +``` +ScalpZynq> ubifsumount +Unmounting UBIFS volume datafs-vol! +``` + +Other U-Boot commands for the UBI/UBIFS file system are also available. Please refer to the related documentation. ### Howto create a patch for U-Boot @@ -995,7 +1080,3 @@ $ petalinux-build TODO - - - -