Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source code for generating fip.bin? #74

Open
silvanshade opened this issue Mar 7, 2024 · 7 comments
Open

Source code for generating fip.bin? #74

silvanshade opened this issue Mar 7, 2024 · 7 comments

Comments

@silvanshade
Copy link

Is the source code available for generating the firmware/fip.bin?

I am trying to put together a custom bootloader and would like to be able to reproduce this file from source if possible.

I also created an issue asking for more information about fip.bin in the sophgo-doc repository:

sophgo/sophgo-doc#69

The closest thing I have been able to find regarding the fip.bin is from the cv18xx documentation:

Section 3.3.1 Generate Image:

Please refer to <U-boot Porting Development Guide> to generate FIP.bin image.
Section 3.3 Compile U-boot

Since the native u-boot compiled u-boot.bin cannot be burned directly into FLASH, we adopt
the Firmware Image Package (FIP) method in ARM Trusted Firmware Design to encapsulate
uboot.bin in fip.bin. fip_spl.bin contains several images that need to be loaded during the fast
boot process.

I notice that there is a u-boot repository with an sg2042-dev branch:

https://github.com/sophgo/u-boot/tree/sg2042-dev

But I'm not sure if this is where the firmware/fip.bin in this repository is being generated from.

Any information would be appreciated.

@michaelrommel
Copy link

michaelrommel commented Mar 25, 2024

For what it's worth, if you have a look at the github actions workflow, there are artifacts generated by those steps. If you download e.g. sophgo-bootloader-single-sg2042-master (https://github.com/sophgo/bootloader-riscv/actions/runs/8414100858) you will find an .img therein. If you mount that, there is an actual fip.bin file contained. Maybe that is what you are looking for, if yes, then the steps in the workflow tell you, how it's been created. If you have already figured that out, I'm sorry, I am very new to this risc-v businees and just try to get my own Pioneer board running...

@silvanshade
Copy link
Author

Yeah, I've looked at that.

In fact, I created from scratch a Nix flake for building the BSP and bootloader which follows the similar procedure, and copies the fip.bin at this step here.

Unfortunately I just have to take the fip.bin as the binary blob from this repository because, even if you dig into the build scripts here, there's no mention of how it's generated.

Looking at efforts to run NixOS on the MilkV Duo show something similar, where they have to package the fip.bin as a prebuilt artifact here.

Anyway, still hoping the sources for this can be provided although I'm not sure how likely that is to happen.

@zamaudio
Copy link

zamaudio commented Jun 16, 2024

@xingxg2022 : Can you guys please provide the source code to build the riscv fip.bin binary from this commit: 3f75067

I found some related code in this tree https://github.com/sophgo/bootloader-arm64/tree/master/trusted-firmware-a/drivers/sophgo but I'm not sure if it is 100% compatible.

If you can provide the true source, I may buy a board and help write a port for milkv/pioneer for coreboot.

(It would be a pity if the community was unable to create alternative bootloaders that gave extra flexibility, eg booting from SATA disk from a pure SPI flash image due to missing multi-processor, pcie, or RAM bringup details)

@zamaudio
Copy link

@silvanshade I was able to compile a (possibly old) version of fip.bin for mango using the following repo and commands:

git clone https://github.com/sophgo/bootloader-arm64
CHIP=mango CROSS_COMPILE_64=aarch64-linux-gnu- source bootloader-arm64/scripts/envsetup.sh
CHIP=mango build_fip

But I get an error near the end: undefined reference to 'invalidate_icache_all'

So I copied a different board's implementation in trusted-firmware-a/plat/sophgo/mango/plat_helpers.S :

    .globl  invalidate_icache_all
...

func invalidate_icache_all
  ic   ialluis
  isb  sy
  ret
endfunc invalidate_icache_all

This compiled a fip.bin but I don't have hardware to test yet.

@silvanshade
Copy link
Author

silvanshade commented Jun 18, 2024

@zamaudio I was also eventually able to compile the fip.bin with a similar approach.

The problem that remains is that the board will not boot the fip.bin unless the build procedure uses the correct certificates (the boot fails with an error about certificate mismatch), which I assume nobody has access to except for the vendor. This may be why there hasn't been a response to requests for information about fip.bin.

There may be a way to turn off certificate validation with a jumper or commands issued to the ARM mcu over serial or something like that but I haven't put much effort into investigating that. This would also of course defeat the purpose of the trusted firmware bootflow, but alas it doesn't help the user that wants to build everything themselves anyway.

@ParkerTenBroeck
Copy link

@silvanshade @zamaudio

I am trying to do something similar to silvanshade with a custom bootloader and needed to generate the fip.bin file as well. I have found what looks to be the script responsible for generating it, as well as related scripts for signing. I'm not able to test it yet but the magic number matches and hopefully this is what you're looking for.

fiptool.py

I also found potentially relevant documentation on the secure boot process they use

SecureBootUserGuide_en.pdf

@197788
Copy link

197788 commented Jul 21, 2024

Also found here: https://github.com/sophgo/fiptool
You may also be able to build the whole bootloader yourself; I'm not sure with this: https://github.com/sophgo/bootloader-riscv/blob/master/scripts/envsetup.sh
Sophgo has made more pre-built images for Pioneer boards: https://github.com/sophgo/sophgo-doc/blob/main/SG2042/HowTo/FAQ.rst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants