this are my steps on a debian box to build u-boot and obensbi
You have to clone all the required source and then adapt the path and it should work
cd u-boot/
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j8
cd ../Tools/spl_tool/
./create_sbl /home/admin/u-boot/spl/u-boot-spl.bin 0x01010101
cd /home/admin/opensbi
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PAYLOAD_PATH=/home/admin/u-boot/u-boot.bin FW_FDT_PATH=/home/admin/u-boot/arch/riscv/dts/starfive_visionfive2.dtb FW_TEXT_START=0x40000000
cd ../Tools/uboot_its/
cp /home/admin/opensbi/build/platform/generic/firmware/fw_payload.bin ./
/home/admin/u-boot/tools/mkimage -f visionfive2-uboot-fit-image.its -A riscv -O u-boot -T firmware visionfive2_fw_payload.img
The format of the file has changed from JH7100’s. As far as I can tell, the entrypoint is at 0x400, and if the file is modified above 0x400, it gets refused with a CRC Error.
But that wasn’t going to stop me from trying.
The length of the checksum would be from 0x400 to the end of the file, or the same thing, the file length minus 0x400.
That value comes up twice in the file, at 0x288 and 0x2d4. The former is interesting, because it is followed by what looks like a checksum. It happens to match crc32 of 0x400 to end of file. Bingo.
#!/usr/bin/env python3
from Crc import Crc
import struct
cksumofft = 0x290
def main():
path = "rescue.bin"
crc = Crc(model="CRC-32/ISO-HDLC")
with open(path, "rb") as fh:
data=fh.read()
cksum = crc.crc(data[0x400:])
print(f'checksum is {hex(cksum)} {cksum}')
stsum = struct.unpack("<I", data[cksumofft:cksumofft+4])[0]
print(f'stored is {hex(stsum)} {stsum}')
if cksum != stsum:
print("Checksum does not match. Patching file...")
with open(path, "r+b") as fh:
fh.seek(cksumofft)
fh.write(struct.pack("<I", cksum))
return
if __name__ == "__main__":
main()
This much is sufficient to get past the checksum problem. Enabling this: