Skip to content
Snippets Groups Projects
Select Git revision
  • a658ec24978963c1920e45005b03fe2f0bb5612c
  • master default protected
  • scalp_fast_router_firmware_petalinux
  • scalp_router_firmware_petalinux
  • feature-mipi
  • SCALP-USER-USB
  • SCALP_ROUTER_DMA-v0.3
  • SCALP_ROUTER_DMA-v0.2
  • SCALP-FAST-ROUTER-v0.1
  • SCALP_ROUTER_SLOW-v0.3
  • SCALP_ROUTER_SLOW-v0.2
  • SCALP_ROUTER_SLOW-v0.1
  • SCALP-USER-v0.5.1
  • SCALP-SAFE-v0.5.1
  • SCALP-SAFE-v0.5
  • SCALP-USER-v0.5
  • SCALP-SAFE-v0.4.3
  • SCALP-USER-v0.1
  • SCALP-SAFE-v0.4.2
  • SCALP-SAFE-v0.4.1
  • SCALP-SAFE-v0.4
  • SCALP-SAFE-v0.3
  • SCALP-SAFE-v0.2
  • SCALP-SAFE-DEBUG-SJA1105-v0.01
  • SCALP-SAFE-v0.01
25 results

scalp_petalinux

Name Last commit Last update
bsp
scalp_safe_petalinux
Howto.md
README.md

PetaLinux for Scalp board

Documentation to create a PetaLinux distribution for Scalp board

PetaLinux is an extension of the Yocto project that provides official support (Xilinx layers) for Xilinx SoCs Arm (Zynq and ZynqMP) and Xilinx Microblaze.

Please note that this workflow only works with Linux. Please consult the Linux distributions supported by Vivado. If you intend to use Windows and the Linux subsystem. Don't waste your time asking me questions.

PetaLinux 2020.2 Package List

PetaLinux 2020.2 user guide

First steps to perform

  • Installing Vivado 2020.2
  • Installing PetaLinux 2020.2
  • Setting-Up your environnement

Setting-Up your environnement

Run the following command from a terminal.

$ source /<XILINX_INSTALL_FOLDER>/PetaLinux/2020.2/bin/settings.sh

In my case <XILINX_INSTALL_FOLDER> corresponds to /tools/Xilinx/.

Check that the "rsync" tool is installed.

Parts of a BSP (Board Support Package)

  • Device-tree (U-Boot and Linux)
  • Kernel configuration
  • U-Boot configuration
  • Boot script
  • Possible patchs

BSP creation workflow

  • Create and export hardware design.
  • Create a blank PetaLinux project without a BSP.
  • Customization process to meet the requirements of the BSP.
  • Package the PetaLinux project into a BSP.
  • Test the BSP by running directly and by creating a new project.

Clone of the GIT Scalp Firmware repository (HDL)

cd <SCALP_PROJECT_FOLDER>
$ git clone https://gitedu.hesge.ch/soma/scalp_firmware.git
$ cd scalp_firmware
$ git checkout SCALP-SAFE-v0.01

FPGA scalp_safe_firmware creation

First of all... Go to the board_files folder of the GIT scalp_firmware deposit. Scalp Firmware - Board files

And follow these instructions...

The scalp_node folder can be copied into <Vivado directory>/<version>/data/boards/board_files to add SCALP node support in Vivado. The definition "hepia-cores.ch:scalp_node:part0:0.1" can then be used as a proper board definition for project creation. This board definition is currently blank and does not provide full board definition but it will evolve in the future and should be used for new project creation.

In your case, the definition is already present in the scalp_safe_firmware project. However, if the scalp_node folder is not copied, the creation of the project will fail.

Next...

$ cd <SCALP_PROJECT_FOLDER>/scalp_firmware/designs/vivado/scalp_safe_firmware/2020.2/lin64/
$ source setup.sh
$ create_project
$ gen_bitstream
$ export_hw
or
$ open_gui
and File -> Export -> Export Hardware -> include bitstream

Clone of the GIT Scalp PetaLinux repository

$ cd <SCALP_PROJECT_FOLDER>
$ git clone https://gitedu.hesge.ch/soma/scalp_petalinux.git
$ cd scalp_petalinux
$ git checkout SCALP-SAFE-v0.4

Use version 0.4 only for the GIT scalp_petalinux repository and not for the GIT scalp_firmware repository. The version difference is not an error.

Create new Petalinux project from a BSP

$ cd <SCALP_PROJECT_FOLDER>/scalp_petalinux/
$ petalinux-create --type project -s <path-to-bsp> --name <PROJECT NAME>
$ cd <PROJECT NAME>

In my case <path-to-bsp> corresponds to /home/jo/Documents/Projets/Hepia/scalp_project/scalp_petalinux/bsp/SCALP-SAFE-FIRMWARE-BSP-V0.4.bsp

Importing hardware configuration

The hardware description of the project must have been exported from Vivado beforehand.

$ export SCALP_FIRMWARE_PATH="\<PATH_TO_SCALP_FIRMWARE_PROJECT\>"
$ petalinux-config --get-hw-description=$(find ${SCALP_FIRMWARE_PATH} -name scalp_safe_firmware.xsa) --silentconfig

In my case <PATH_TO_SCALP_FIRMWARE_PROJECT> corresponds to /home/jo/Documents/Projets/Hepia/scalp_project/scalp_firmware/

Directory tree

<PROJECT NAME>
├── components
│   └── plnx_workspace
│       └── device-tree
│           └── device-tree
│               └── include
│                   └── dt-bindings
│                       ├── clock
│                       ├── power
│                       └── reset
├── hardware
│   └── scalp_safe_firmware
│       ├── scalp_safe_firmware.cache
│       │   ├── compile_simlib
│       │   │   ├── activehdl
│       │   │   ├── ies
│       │   │   ├── modelsim
│       │   │   ├── questa
│       │   │   ├── riviera
│       │   │   ├── vcs
│       │   │   └── xcelium
│       │   ├── ip
│       │   │   └── 2020.2
│       │   │       ├── 0aa2a8d458771a97
│       │   │       ├── 0bbb37acf8a11f47
│       │   │       ├── 129637f02d4c08f6
│       │   │       ├── 13ec2d6b4b16e74c
│       │   │       ├── 1b48bca4c59faa2a
│       │   │       ├── 2ddf55dbeb806356
│       │   │       ├── 72c991d9c4c4299d
│       │   │       └── 9a7eae85eedde786
│       │   └── wt
│       ├── scalp_safe_firmware.hw
│       ├── scalp_safe_firmware.ip_user_files
│       ├── scalp_safe_firmware.runs
│       │   ├── impl_1
│       │   ├── scalp_zynqps_auto_pc_0_synth_1
│       │   ├── scalp_zynqps_processing_system7_0_0_synth_1
│       │   ├── scalp_zynqps_rst_ps7_0_125M_0_synth_1
│       │   ├── scalp_zynqps_scalp_axi4lite_0_0_synth_1
│       │   ├── scalp_zynqps_util_vector_logic_0_0_synth_1
│       │   ├── scalp_zynqps_util_vector_logic_1_0_synth_1
│       │   ├── scalp_zynqps_vio_0_0_synth_1
│       │   └── synth_1
│       └── scalp_safe_firmware.sim
└── project-spec
    ├── configs
    │   ├── busybox
    │   ├── init-ifupdown
    │   └── u-boot-xlnx
    ├── hw-description
    └── meta-user
        ├── conf
        ├── recipes-apps
        │   ├── gpio-demo
        │   │   └── files
        │   └── peekpoke
        │       └── files
        ├── recipes-bsp
        │   ├── device-tree
        │   │   └── files
        │   ├── fsbl
        │   └── u-boot
        │       ├── files
        │       └── u-boot-zynq-scr
        └── recipes-kernel
            └── linux
                └── linux-xlnx

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) 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.

$ petalinux-build -x mrproper -f
$ petalinux-config -c u-boot

Please select...

U-Boot 2020.01 Configuration
    Device Drivers  --->
    -*- SPI Support  --->
        [*]   Zynq SPI driver (select with spacebar)

and...

U-Boot 2020.01 Configuration
    Device Drivers  --->
    -*- Ethernet PHY (physical media interface) support  --->
        [*]   Fixed-Link PHY (select with spacebar)
        [*]   Xilinx Ethernet PHYs support (select with spacebar)

and...

U-Boot 2020.01 Configuration
    Command line interface  --->
    [*] Enable UBI - Unsorted block images commands (select with spacebar)
    [*]   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 and the UBI environment have been taken into account.

Build the PetaLinux project

$ petalinux-build

The produced binary files can be found in the ./images/linux folder.

You can possibly check that the ZYNQ_SPI driver and the CMD_UBI and CMD_UBIFS commands have been compiled.

$ find . -name zynq_spi.o

> ./build/tmp/work/zynq_generic-xilinx-linux-gnueabi/u-boot-xlnx/v2020.01-xilinx-v2020.2+git999-r0/u-boot-xlnx-v2020.01-xilinx-v2020.2+git999/drivers/spi/zynq_spi.o
$ find . -name ubi.o

> ./build/tmp/work/zynq_generic-xilinx-linux-gnueabi/u-boot-xlnx/v2020.01-xilinx-v2020.2+git999-r0/u-boot-xlnx-v2020.01-xilinx-v2020.2+git999/cmd/ubi.o

$ find . -name ubifs.o

> ./build/tmp/work/zynq_generic-xilinx-linux-gnueabi/u-boot-xlnx/v2020.01-xilinx-v2020.2+git999-r0/u-boot-xlnx-v2020.01-xilinx-v2020.2+git999/cmd/ubifs.o
> ...

And you can do the same for other ".o" binary files related to other U-Boot configuration settings.

Creation of the basic image of the U-Boot environment

The image content can be produced by using the mkenvimage command.

$ echo -e "custom_board_name=\"Zynq Scalp Board\"\ncustom_board_version=\"RevB 2008\"\ncustom_board_vendor=\"Hepia CoRES - LSN\"" > images/linux/uenv-vol.env
$ /tools/u-boot-tools/mkenvimage -s 0x100000 -o images/linux/uenv-vol.env.bin images/linux/uenv-vol.env

In my case, I copied the tools produced by U-Boot into the /tools/u-boot-tools/ folder.

Create UBIFS images

Documentation about the UBI/UBIFS file system

First, check that the mtd-utils package (debian and ubuntu) is installed on your host machine.

From the root directory of the PetaLinux project...

Extract the root file system to the previously created directory.

$ cd images/linux
$ mkdir rootfs-vol
$ cd rootfs-vol/
$ cat ../rootfs.cpio | cpio -idvm --no-absolute-filenames
$ cd ..
$ sudo chown -R root:root rootfs-vol/

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 datafs-vol

Copy Linux kernel FIT image into datafs-vol.

$ cp image.ub datafs-vol/

Then, rootfs-vol, datafs-vol and uenv-vol UBI/UBIFS volumes must be created respecting the geometrical configuration of the flash memory.

SF: Detected s25fl256s1 with page size 256 Bytes, erase size 64 KiB, total 32 MiB

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

This information alone is not sufficient. Please refer to subsection Geometric organisation.

$ sudo mkfs.ubifs -r ./rootfs-vol -m 1 -e 65408 -c 260 -o rootfs-vol.ubifs
$ sudo chown -R ${USER}:${USER} rootfs-vol/
$ sudo mkfs.ubifs -r ./datafs-vol -m 1 -e 65408 -c 130 -o datafs-vol.ubifs

Next, a configuration file must be created to define the UBI layout volume.

$ echo \
"[uenv-volume]
mode=ubi
image=uenv-vol.env.bin
vol_id=0
vol_size=2048KiB
vol_type=static
vol_name=uenv-vol

[datafs-volume]
mode=ubi
image=datafs-vol.ubifs
vol_id=1
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
vol_flags=autoresize
" \
> ubi-image.ini

Next, the UBI layout volume must be created.

$ sudo ubinize -p 65536 -m 1 -s 1 -O 64 -o ubi-image.ubi ubi-image.ini
$ cd ../..

Howto obtain information about the geometric organisation of the SPI NOR memory

For information purposes only

From U-Boot source files.

{ INFO("s25fl256s0", 0x010219, 0x4d00, 256 * 1024, 128, USE_CLSR) },
{ INFO("s25fl256s1", 0x010219, 0x4d01,  64 * 1024, 512, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) },

From old U-Boot source files.

{
    .idcode1 = 0x0219,
    .idcode2 = 0x4d01,
    .page_size = 256,
    .pages_per_sector = 256,
    .nr_sectors = 512,
    .name = "S25FL256S1",
}

From U-Boot ... but only if you already have a properly configured and working UBI/UBIFS file system. Otherwise, just hope that the engineers who chose the QSPI memory will find out if it is used on other boards and if the geometry configuration is already documented. Otherwise pray... ;D

ScalpZynq> ubi part ubi
ubi0: detaching mtd2
ubi0: mtd2 is detached
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                               <----- -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: 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
ScalpZynq> ubi info l
Volume information dump:
	vol_id          0
	reserved_pebs   33
	alignment       1
	data_pad        0
	vol_type        4
	name_len        8
	usable_leb_size 65408
	used_ebs        17
	used_bytes      1048576
	last_eb_bytes   2048
	corrupted       0
	upd_marker      0
	skip_check      0
	name            uenv-vol
Volume information dump:
	vol_id          1
	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        10
	usable_leb_size 65408
	used_ebs        264
	used_bytes      17267712
	last_eb_bytes   65408
	corrupted       0
	upd_marker      0
	skip_check      0
	name            rootfs-vol
Volume information dump:
	vol_id          2147479551
	reserved_pebs   2
	alignment       1
	data_pad        0
	vol_type        3
	name_len        13
	usable_leb_size 65408
	used_ebs        2
	used_bytes      130816
	last_eb_bytes   2
	corrupted       0
	upd_marker      0
	skip_check      0
	name            layout volume
ScalpZynq> ubi info
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:        432
UBI: number of bad PEBs:         0
UBI: smallest flash I/O unit:    1
UBI: VID header offset:          64 (aligned 64)
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:     3
UBI: available PEBs:             0
UBI: total number of reserved PEBs: 432
UBI: number of PEBs reserved for bad PEB handling: 0
UBI: max/mean erase counter: 2/0

QSPI firmware packaging

$ 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

Zeros are added at the end of the BOOT.BIN file up to the size of the SPI NOR memory.

$ 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 in the datafs-vol UBI volume.

For information purposes only, below is the partitioning of the flash memory.

List of MTD devices:
* nor0
  - type: NOR flash
  - block size: 0x10000 bytes
  - min I/O: 0x1 bytes
  - 0x000000000000-0x000002000000 : "nor0"
	  - 0x000000000000-0x000000500000 : "boot"
	  - 0x000000500000-0x000002000000 : "ubi"
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)
/* 5242880 Bytes */
partition@boot {
    label = "boot";
    reg = <0x0 0x500000>;
};

/* 28311552 Bytes */
partition@ubi {
    label = "ubi";
    reg = <0x500000 0x1B00000>;
};

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

If you use several JTAG probes.

$ program_flash -jtagtarget

> Available targets and devices:
> JTAG chain configuration
> --------------------------------------------------
> 1 Digilent 210299AFC175
> 	2    jsn-JTAG-HS3-210299AFC175-4ba00477-0  (name arm_dap  idcode 4ba00477) <-- target id 2
> 	3    jsn-JTAG-HS3-210299AFC175-0373b093-0  (name xc7z015  idcode 0373b093)
> 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

Or, without a check of the written blocks...

$ 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.

The image content can be viewed using the dumpimage command.

$ /tools/u-boot-tools/dumpimage -l image.ub

In my case, I copied the tools produced by U-Boot into the /tools/u-boot-tools/ folder.

HOWTO

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.

How to use the U-Boot environment in a UBI/UBIFS file system

ScalpZynq> sf probe 0 0 0
SF: Detected s25fl256s1 with page size 256 Bytes, erase size 64 KiB, total 32 MiB
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: 4/0, WL threshold: 4096, image sequence number: 1995518755
ubi0: available PEBs: 0, total reserved PEBs: 432, PEBs reserved for bad PEB handling: 0
ScalpZynq> env default -f -a
## Resetting to default environment
ScalpZynq> setenv envtest "UBI env. test"
ScalpZynq> printenv envtest
envtest=UBI env. test
ScalpZynq> saveenv 
Saving Environment to UBI... ubi0: detaching mtd2
ubi0: mtd2 is detached
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: 4/0, WL threshold: 4096, image sequence number: 1995518755
ubi0: available PEBs: 0, total reserved PEBs: 432, PEBs reserved for bad PEB handling: 0
done
OK
ScalpZynq> env default -f -a
## Resetting to default environment
ScalpZynq> printenv envtest
## Error: "envtest" not defined
ScalpZynq> ubi read 0x10000000 uenv-vol 0x100000
Read 1048576 bytes from volume uenv-vol to 10000000
ScalpZynq> md.b 0x10000000 10 
10000000: f2 22 9c eb 53 43 41 4c 50 5f 42 4f 4f 54 5f 50    ."..SCALP_BOOT_P
ScalpZynq> env import -c 0x10000000 0x100000
ScalpZynq> printenv envtest
envtest=UBI env. test

Howto create a patch for U-Boot

Retrieve the desired version of the U-Boot GIT deposit.

$ git clone https://github.com/Xilinx/u-boot-xlnx.git
$ cd u-boot-xlnx
$ git checkout xilinx-v2020.2

Make the necessary modifications and commit the changes.

$ git add *
$ git commit -m "Doing something."

Produce the new patch.

$ git diff -p xilinx-v2020.2 HEAD > my-u-boot.patch

Solution in case of problems with whitespaces.

$ emacs my-u-boot.patch -f delete-trailing-whitespace -f save-buffer -f kill-emacs

Apply the new patch to a clean version of the U-Boot GIT deposit.

$ git clone https://github.com/Xilinx/u-boot-xlnx.git
$ cd u-boot-xlnx
$ git checkout xilinx-v2020.2
$ git apply u-boot-scalp-sja1105.patch

And that's it.

Howto create a init script (example with the init script for the configuration of the ethernet switch sja1105)

First, we start by creating the new sja1105-init PetaLinux application.

$ petalinux-create -t apps --template install -n sja1105-init --enable

Then we edit the BitBake file corresponding to the new application.

$ emacs project-spec/meta-user/recipes-apps/sja1105-init/sja1105-init.bb

You can use another text editor than Emacs.

Edit the file like this...

#
# This file is the sja1105-init recipe.
#

SUMMARY = "Simple sja1105-init application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://sja1105-init \
	"

S = "${WORKDIR}"

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

inherit update-rc.d

INITSCRIPT_NAME = "sja1105-init"

INITSCRIPT_PARAMS = "start 02 S ."

do_install() {
    install -d ${D}${sysconfdir}/init.d
    install -m 0755 ${S}/sja1105-init ${D}${sysconfdir}/init.d/sja1105-init
    install -d ${D}${sysconfdir}/rc2.d
    install -m 0755 ${S}/sja1105-init ${D}${sysconfdir}/rc2.d/S02sja1105-init
    install -d ${D}${sysconfdir}/rc3.d
    install -m 0755 ${S}/sja1105-init ${D}${sysconfdir}/rc3.d/S02sja1105-init
    install -d ${D}${sysconfdir}/rc4.d
    install -m 0755 ${S}/sja1105-init ${D}${sysconfdir}/rc4.d/S02sja1105-init
    install -d ${D}${sysconfdir}/rc5.d
    install -m 0755 ${S}/sja1105-init ${D}${sysconfdir}/rc5.d/S02sja1105-init
}

FILES_${PN} += "${sysconfdir}/*"

Open the init script file.

$ emacs project-spec/meta-user/recipes-apps/sja1105-init/files/sja1105-init

Then, edit the init script file like this...

#!/bin/sh
### BEGIN INIT INFO
# Provides:          sja1105-init
# Required-Start:    $local_fs $network $named $time $syslog
# Required-Stop:     $local_fs $network $named $time $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Description:       sja1105 init.d script configuration.
### END INIT INFO

SCRIPT=sja1105-conf
RUNAS=root

PIDFILE=/var/run/sja1105-init.pid
LOGFILE=/var/log/sja1105-init.log

start() {
    if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then
        echo 'Service already running' >&2
        return 1
    fi

    echo 'Starting service…' >&2
    local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
    su -c "$CMD" $RUNAS > "$PIDFILE"
    echo 'Service started' >&2
}

stop() {
    if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
        echo 'Service not running' >&2
        return 1
    fi

    echo 'Stopping service…' >&2
    echo 'Log files /var/log/sja1105-init.log and /var/log/sja1105-conf.log' >&2
    kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
    echo 'Service stopped' >&2
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    retart)
        stop
        start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
esac

Next, we continue by creating the new sja1105-conf PetaLinux application.

$ petalinux-create -t apps --template install -n sja1105-conf --enable

Then we edit the BitBake file corresponding to the new application.

$ emacs project-spec/meta-user/recipes-apps/sja1105-conf/sja1105-conf.bb

Edit the file like this...

#
# This file is the sja1105-conf recipe.
#

SUMMARY = "Simple sja1105-conf application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://sja1105-conf \
	"

S = "${WORKDIR}"

do_install() {
    install -d ${D}/${bindir}
    install -m 0755 ${S}/sja1105-conf ${D}/${bindir}
}

Open the init script file.

$ emacs project-spec/meta-user/recipes-apps/sja1105-conf/files/sja1105-conf

Then, edit the init script file like this...

#!/bin/sh

sja1105_ports_link_up()
{
    echo "[INFO] sja1105-conf : sja1105 ports linking up..."

    ip link set swp0_east up

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : swp0_east port is up."
    else
        exit 1
    fi

    ip link set swp2_bottom up

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : swp2_bottom port is up."
    else
        exit 1
    fi

    ip link set swp3_top up

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : swp3_top port is up."
    else
        exit 1
    fi

    ip link set swp4_west up

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : swp4_west port is up."
    else
        exit 1
    fi

    echo "[INFO] sja1105-conf : sja1105 ports linked up."
}

sja1105_creat_bridge()
{
    echo "[INFO] sja1105-conf : Creation and configuration of the bridge in progress..."

    ip link add name br0 type bridge

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : Added a new bridge-like interface."
    else
        exit 1
    fi

    ip link set dev br0 type bridge vlan_filtering 1

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : Configuration of the bridge interface in VLAN filtering mode."
    else
        exit 1
    fi

    echo "[INFO] sja1105-conf : Creation and configuration of the bridge is done."
}

sja1105_link_ports_to_bridge()
{
    echo "[INFO] sja1105-conf : sja1105 ports are being attached to the bridge..."

    ip link set dev swp0_east master br0

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : Addition of the swp0_east interface to the bridge interface."
    else
        exit 1
    fi

    ip link set dev swp2_bottom master br0

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : Addition of the swp2_bottom interface to the bridge interface."
    else
        exit 1
    fi

    ip link set dev swp3_top master br0

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : Addition of the swp3_top interface to the bridge interface."
    else
        exit 1
    fi

    ip link set dev swp4_west master br0

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : Addition of the swp4_west interface to the bridge interface."
    else
        exit 1
    fi

    echo "[INFO] sja1105-conf : sja1105 ports are attached to the bridge."
}

sja1105_ports_vlan_conf()
{
    echo "[INFO] sja1105-conf : sja1105 ports VLAN configuration in progress..."

    bridge vlan add dev swp0_east vid 1 pvid untagged

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : Configuration of the swp0_east interface in untagged VLAN mode."
    else
        exit 1
    fi

    bridge vlan add dev swp2_bottom vid 1 pvid untagged

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : Configuration of the swp2_bottom interface in untagged VLAN mode."
    else
        exit 1
    fi

    bridge vlan add dev swp3_top vid 1 pvid untagged

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : Configuration of the swp3_top interface in untagged VLAN mode."
    else
        exit 1
    fi

    bridge vlan add dev swp4_west vid 1 pvid untagged

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : Configuration of the swp4_west interface in untagged VLAN mode."
    else
        exit 1
    fi

    echo "[INFO] sja1105-conf : sja1105 ports VLAN configuration is done."
}

sja1105_bridge_link_up()
{
    echo "[INFO] sja1105-conf : sja1105 bridge linking up..."

    ip link set br0 up

    if [ "$?" -eq "0" ] ; then
        echo "[INFO] sja1105-conf : bridge-like interface is up."
    else
        exit 1
    fi

    echo "[INFO] sja1105-conf : sja1105 bridge linked up."
}

sja1105_ports_link_up
sja1105_creat_bridge
sja1105_link_ports_to_bridge
sja1105_ports_vlan_conf
sja1105_bridge_link_up

Finaly build them...

$ petalinux-build -c sja1105-init -x do_cleanall
$ petalinux-build -c sja1105-init
$ petalinux-build -c sja1105-init -x do_install -f
$ petalinux-build -c sja1105-conf -x do_cleanall
$ petalinux-build -c sja1105-conf
$ petalinux-build -c sja1105-conf -x do_install -f

And build the root file system and the firmware...

$ petalinux-build -c rootfs
$ petalinux-build

If you prefer to start by cleaning up your project, don't forget to add the ZYNQ_SPI driver and the CMD_UBI and CMD_UBIFS commands again in the U-Boot configuration. And yes, the bug is still there.

Howto create a new BSP

TODO

$ petalinux-package --bsp -p /home/jo/Documents/Projets/Hepia/scalp_project/scalp_petalinux/scalp_safe_petalinux --hwsource=/home/jo/Documents/Projets/Hepia/scalp_project/scalp_firmware/designs/vivado/scalp_safe_firmware/2020.2/lin64/scalp_safe_firmware --output SCALP-SAFE-FIRMWARE-BSP-V0.N --force