My guess is that part of the document you are probably following is out of date. That the current partition table for the QSPI NOR FLASH was changed to be this:
Offset |
Length |
Description |
0x0 |
0x80000 |
SPL |
0xF0000 |
0x10000 |
U-Boot environment variables |
0x100000 |
0x400000 |
fw_payload.img (OpenSBI + U-Boot) |
0x600000 |
0x1000000 |
Reseved |
I did a quick sanity check to conform this:
offset 0xF0000 is where the U-Boot environment variables are stored, and
offset 0x100000 is where the fw_payload.img is stored. Both of which match the above table.
I would make a backup copy of the existing 16MiB QSPI NOR FLASH partition table, deleted the current partitions and create three new ones with the start offset and length shown above. One for “SPL”, one for “U-Boot environment variables”, and one for “fw_payload.img (OpenSBI + U-Boot)”.
Or I could bypass creating new partitions by writing u-boot-spl.bin.normal.out, since “u-boot-spl.bin.normal.out” starts at sector 0, it must actually contain the partition table, a nice little shortcut. But you would need to do a # partprobe /dev/mtd
to avoid a reboot, to inform the OS that the partition table has changed if you did it that way. Otherwise what the OS though it knew about the partition table would be out of sync with the partition table on flash. I just checked and it does not appear to have a partition table, which confused me.
To have a backup copy of the information in the existing table, I would probably use a command like the following (always handy to have in case anything goes wrong, but should not be needed):
# sfdisk -l /dev/mtd
or
# sfdisk -J /dev/mtd
or
# fdisk -l /dev/mtd
(Done mostly to have a record of the existing partition types used, so that the new partitions can have the same type)
Looks like you need to use “mtdpart” to delete the existing partitions and create 3 new ones. e.g.
# apt install mtd-utils
# mtdpart del /dev/mtd 2
# mtdpart del /dev/mtd 1
# mtdpart del /dev/mtd 0
# mtdpart add /dev/mtd "spl" 0x0 0x80000"
# mtdpart add /dev/mtd "data" 0xF0000 0x10000"
# mtdpart add /dev/mtd "uboot" 0x100000 0x400000"
# wget https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v2.11.5/u-boot-spl.bin.normal.out
# wget https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v2.11.5/visionfive2_fw_payload.img
# flashcp -v u-boot-spl.bin.normal.out /dev/mtd0
# flashcp -v visionfive2_fw_payload.img /dev/mtd2
Note the “/dev/mtd2” and not “/dev/mtd1”
ref: http://git.infradead.org/mtd-utils.git/blob/HEAD:/misc-utils/mtdpart.c or http://www.linux-mtd.infradead.org/
EDIT:
I just found what I initially thought was a contradiction in the source code, but it just looks like no partition is actually created for where the U-Boot environment variables are stored. There are 3 partitions created on the flash:
https://github.com/starfive-tech/u-boot/blob/…/include/configs/starfive-visionfive2.h#L264-L267
"type_guid_gpt_loader1=" TYPE_GUID_LOADER1 "\0" \
"type_guid_gpt_loader2=" TYPE_GUID_LOADER2 "\0" \
"type_guid_gpt_system=" TYPE_GUID_SYSTEM "\0" \
"partitions=" PARTS_DEFAULT "\0" \
https://github.com/starfive-tech/u-boot/blob/…/include/configs/starfive-visionfive2.h#L97-L99
#define TYPE_GUID_LOADER1 "5B193300-FC78-40CD-8002-E86C45580B47"
#define TYPE_GUID_LOADER2 "2E54B353-1271-4842-806F-E436D6AF6985"
#define TYPE_GUID_SYSTEM "0FC63DAF-8483-4772-8E79-3D69D8477DE4"
Which correspond to “HiFive Unleashed FSBL”, “HiFive Unleashed BBL” and “Linux filesystem data” respectively. Or u-boot-spl.bin.normal.out , visionfive2_fw_payload.img and Linux filesystem respectively.
Oh and:
https://github.com/starfive-tech/u-boot/blob/…/include/configs/starfive-visionfive2.h#L165-L168
#define PARTS_DEFAULT \
"name=loader1,start=17K,size=1M,type=${type_guid_gpt_loader1};" \
"name=loader2,size=4MB,type=${type_guid_gpt_loader2};" \
"name=system,size=-,bootable,type=${type_guid_gpt_system};"
So from 17KiB to 1MiB and 17 KiB is for storing u-boot-spl.bin.normal.out
From 1MiB and 17KiB to 5MiB and 17KiB is for storing visionfive2_fw_payload.img
From 5MiB and 17KiB to the end of the FLASH, ‘-’ to denote all remaining space, is a bootable partition of 11247KiB for files.
so:
Offset |
Length |
Description |
Partition |
GUID |
0x0 |
0x4400 |
GUID Partition Table |
not applicable |
not applicable |
0x4400 |
0x100000 |
SPL |
/dev/mtd0 |
5B193300-FC78-40CD-8002-E86C45580B47 |
0xF0000 |
0x10000 |
U-Boot environment variables |
first 64KiB of last 81KiB of /dev/mtd0 |
shared with SPL |
0x104400 |
0x400000 |
fw_payload.img (OpenSBI + U-Boot) |
/dev/mtd1 |
2E54B353-1271-4842-806F-E436D6AF6985 |
0x504400 |
0x1000000 |
Linux Filesystem |
/dev/mtd2 |
0FC63DAF-8483-4772-8E79-3D69D8477DE4 |
I was expecting to see a partition of GUID of “3DE21764-95BD-54BD-A5C3-4ABE786F38A8” AKA “U-Boot environment” but one does not exist the data is hidden in 64KiB of the last 81KiB of the “5B193300-FC78-40CD-8002-E86C45580B47” AKA “HiFive Unleashed FSBL” just 17KiB before the start of the GUID “0FC63DAF-8483-4772-8E79-3D69D8477DE4” AKA “HiFive Unleashed BBL”.
So it looks like both documents are out of date.