u-boot-starfive does not contain a postinst script to update the board after package installation

Bug #2052693 reported by scottfk
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
u-boot (Ubuntu)
New
Undecided
Unassigned

Bug Description

u-boot-starfive distributes updates to SPL and U-Boot, but it does not flash them to the board. I think it would be useful if it followed the pattern of u-boot-sifive and included a postinst script to update the board.

The script could look something like this. NB: I only have access to a StarFive VisionFive 2 v1.3B board. Not sure if the other revisions are compatible with the SPL and U-Boot images in the u-boot-starfive package:

#!/bin/sh

##

set -e

case "$1" in
    configure)
        target=""
        if grep -q '^StarFive VisionFive 2 v1.3B$' /sys/firmware/devicetree/base/model; then
            target="starfive_visionfive2"
        fi
        if [ -n "$target" ] && [ -e /dev/mtd/by-name/spl ] && [ -e /dev/mtd/by-name/uboot ]; then
            flashcp -v /usr/lib/u-boot/$target/u-boot-spl.bin.normal.out /dev/mtd/by-name/spl
            flashcp -v /usr/lib/u-boot/$target/u-boot.itb /dev/mtd/by-name/uboot
        fi
        ;;
esac

exit 0

Revision history for this message
Heinrich Schuchardt (xypron) wrote (last edit ):

Hello Scott,

thanks for taking a look at the u-boot-starfive.

The StarFive board has multiple boot options. The vendor U-Boot is typically installed on SPI-flash. But you could also have U-Boot on the eMMC or on the SD-card. I would assume that the GPIOs determining the boot source could also be read in Linux.

When booting into Ubuntu 24.04 I see no /dev/mtd/by-name/ directory. We don't have a udev rule for it.

In /proc/dev I find:

$ cat /proc/mtd
dev: size erasesize name
mtd0: 00080000 00001000 "spl"
mtd1: 00010000 00001000 "uboot-env"
mtd2: 00400000 00001000 "uboot"
mtd3: 00a00000 00001000 "reserved-data"

These partitions seem to be derived from the device-tree (cf. arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi).

Best regards

Heinrich

Revision history for this message
scottfk (scottfk) wrote :

Heya, Heinrich.

That device in the by-name seems to get created by /usr/lib/udev/rules.d/60-persistent-storage-mtd.rules (from package udev):

# do not edit this file, it will be overwritten on update

# persistent storage links: /dev/mtd/by-name

ACTION=="remove", GOTO="persistent_storage_mtd_end"
SUBSYSTEM!="mtd", GOTO="persistent_storage_mtd_end"
KERNEL!="mtd[0-9]*", GOTO="persistent_storage_mtd_end"
KERNEL=="mtd[0-9]*ro", GOTO="persistent_storage_mtd_end"

ATTR{name}=="?*", SYMLINK+="mtd/by-name/$attr{name}"

LABEL="persistent_storage_mtd_end"

 udevadm info /dev/mtd/by-name/uboot
P: /devices/platform/soc/13010000.spi/spi_master/spi0/spi0.0/mtd/mtd2
M: mtd2
R: 2
U: mtd
T: mtd
D: c 90:4
N: mtd2
L: 0
S: mtd/by-name/uboot
E: DEVPATH=/devices/platform/soc/13010000.spi/spi_master/spi0/spi0.0/mtd/mtd2
E: DEVNAME=/dev/mtd2
E: DEVTYPE=mtd
E: OF_NAME=uboot
E: OF_FULLNAME=/soc/spi@13010000/flash@0/partitions/uboot@100000
E: OF_COMPATIBLE_N=0
E: MAJOR=90
E: MINOR=4
E: SUBSYSTEM=mtd
E: USEC_INITIALIZED=19728429
E: DEVLINKS=/dev/mtd/by-name/uboot

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu Noble Numbat (development branch)
Release: 24.04
Codename: noble

$ apt policy udev
udev:
  Installed: 255.2-3ubuntu2
  Candidate: 255.2-3ubuntu2
  Version table:
 *** 255.2-3ubuntu2 500
        500 http://ports.ubuntu.com/ubuntu-ports noble-proposed/main riscv64 Packages
        100 /var/lib/dpkg/status
     253.5-1ubuntu7 500
        500 http://ports.ubuntu.com/ubuntu-ports noble/main riscv64 Packages

Maybe I am getting the device mapping because I am running a 6.8.0-rc3 kernel I compiled myself? I will reboot into the Ubuntu 6.5.0.14.14.1 kernel and check.

Revision history for this message
Heinrich Schuchardt (xypron) wrote :

We have no control over the kernel or device-tree that the user uses. The definitions of the MTD partitions might not match our device-tree.

/sys/class/mtd/mtd*/offset has the offsets of the MTD partitions. This would need to be checked before flashing.

Revision history for this message
scottfk (scottfk) wrote :

Still there.

$ uname -a
Linux venus3 6.5.0-14-generic #14.1-Ubuntu SMP Fri Nov 24 06:09:26 UTC 2023 riscv64 riscv64 riscv64 GNU/Linux

/dev/mtd/by-name$ ls -l
total 0
lrwxrwxrwx 1 root root 10 Jan 24 20:53 reserved-data -> ../../mtd3
lrwxrwxrwx 1 root root 10 Jan 24 20:53 spl -> ../../mtd0
lrwxrwxrwx 1 root root 10 Jan 24 20:53 uboot -> ../../mtd2
lrwxrwxrwx 1 root root 10 Jan 24 20:53 uboot-env -> ../../mtd1

(time/date are always wrong until systemd-timesyncd starts and puts things right:

$ last -1 reboot
reboot system boot 6.5.0-14-generic Wed Jan 24 20:53 still running

wtmp begins Tue Sep 19 17:54:34 2023

$ timedatectl
               Local time: Thu 2024-02-08 13:41:50 CET
           Universal time: Thu 2024-02-08 12:41:50 UTC
                 RTC time: n/a
                Time zone: Europe/Zurich (CET, +0100)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
)

Revision history for this message
Heinrich Schuchardt (xypron) wrote :

Hello Scott,

The by-name directory is not created by the kernel.

Could you, please, find out which udev rule file provides the directory on your system by running

grep -GHrn by-name /lib/udev
grep -GHrn by-name /etc/udev

With

apt-file search

you should be able to identify the package providing the file.

Best regards

Heinrich

Revision history for this message
scottfk (scottfk) wrote :

Heya, Heinrich... sorry, I thought I'd shown the rule in https://bugs.launchpad.net/ubuntu/+source/u-boot/+bug/2052693/comments/2

Here we go:

$ grep -GHrn by-name /lib/udev
/lib/udev/rules.d/60-persistent-storage-mtd.rules:3:# persistent storage links: /dev/mtd/by-name
/lib/udev/rules.d/60-persistent-storage-mtd.rules:10:ATTR{name}=="?*", SYMLINK+="mtd/by-name/$attr{name}"

$ apt-file search /lib/udev/rules.d/60-persistent-storage-mtd.rules
udev: /usr/lib/udev/rules.d/60-persistent-storage-mtd.rules

$ apt policy udev
udev:
  Installed: 255.2-3ubuntu2
  Candidate: 255.2-3ubuntu2
  Version table:
 *** 255.2-3ubuntu2 500
        500 http://ports.ubuntu.com/ubuntu-ports noble-proposed/main riscv64 Packages
        100 /var/lib/dpkg/status
     253.5-1ubuntu7 500
        500 http://ports.ubuntu.com/ubuntu-ports noble/main riscv64 Packages

Revision history for this message
Heinrich Schuchardt (xypron) wrote (last edit ):

File 60-persistent-storage-mtd.rules is missing in package udev_253.5-1ubuntu7_riscv64.deb which was released to Ubuntu 24.04 (Noble).

udev_255.2-3ubuntu2_riscv64.deb has a file 60-persistent-storage-mtd.rules but that package version is still in proposed.

Revision history for this message
Heinrich Schuchardt (xypron) wrote :

The current boot source can be discovered by commands
gpioget 1 0; gpioget 1 1.

For SPI flash both commands return 0.

Revision history for this message
scottfk (scottfk) wrote :

Thanks, Heinrich!

I'll take a whack at making a better/more robust script when I have some cycles.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.