chipyard icon indicating copy to clipboard operation
chipyard copied to clipboard

Tutorial AWS F1 hello world: Linux and bare-metal ELF execution

Open taqtiqa-mark opened this issue 1 year ago • 6 comments

Background Work

Feature Description

Thanks for all the effort put in to this tooling. The docs for onboarding new users are far superior to those from AWS themselves.

Would be great to have a tutorial showing how to:

  • run Linux on a AWS F1 FPGA, and then run an ELF file in linux?
  • run riscv elf on the F1 FPGA?

Something like this (atamaran/ARIFIC) tutorial

https://github.com/rsnikhil/Tutorial_at_HPCA-29/blob/main/Slides.pdf

which uses their own custom commands:

  • ./UART_Console for uart connection
  • ./exe_Host_AWSF1 to run assert_reset load_elf ../C_Examples/hello/hello.RV64.bare.elf deassert_reset - ./exe_Host_AWSF1. --elf ./Elfs/Linux.elf --blockdev ./disk.img --tundev tap0

Motivating Example

  • ./UART_Console for uart connection
  • ./exe_Host_AWSF1 to run assert_reset load_elf ../C_Examples/hello/hello.RV64.bare.elf deassert_reset - ./exe_Host_AWSF1. --elf ./Elfs/Linux.elf --blockdev ./disk.img --tundev tap0

taqtiqa-mark avatar Apr 26 '25 12:04 taqtiqa-mark

Hello! :D Regarding tutorials and baremetal, we have been attempting to write some here for the Chipyard ecosystem: https://ucb-ee290c.github.io/tutorials. I just moved over a write-up on building Linux (credit: Michael).

Specifically, if you're using Chipyard, you can read the Communicating with a DUT part of the documentation to get started, build Linux using FireMarshal or write baremetal firmware directly with Baremetal IDE, etc.

I admit your post confuses me a bit - I'm not sure what you're referring to - are you using Chipyard (for RTL?)? FireSim? (I will close this for now as I'm not sure the request is within the Chipyard scope, but feel free to reopen if I misunderstood!)

Fi50 avatar May 31 '25 04:05 Fi50

I admit your post confuses me a bit - I'm not sure what you're referring to - are you using Chipyard (for RTL?)? FireSim?

Apologies for the ambiguity.

I'm trying to use chipyard to build existing soft-cpus and then explore using those on F1/F2 istances, rather than design or develop new designs. Ideally I'd like to get to the point of being able to add/remove a part/module of a design but right now that is some point in the future.

I'm getting up to speed on FPGA's and am trying (possibly improperly) to stay within the Chipyard tech stack for that journey. For example I was trying to find the chipyard equivalent of the UART_Console executable, and a tutorial on how to use it in the context of a chipyard built RISCV soft-cpu running on a F1/F2 instance.

As you indicate this is probably too basic starting point for chipyard.

Thanks for the pointer to the EE290C tutorials I'll dig into them.

taqtiqa-mark avatar May 31 '25 23:05 taqtiqa-mark

we have been attempting to write some here for the Chipyard ecosystem: https://ucb-ee290c.github.io/tutorials

That looks very useful, in particular the "Linux Installation with Firemarshal". Sounds like the sort of getting started basics I was after.

However that link is broken, but it seems to be intended to point to the same page as the side bar link....

I'll dig into reporting that there.

taqtiqa-mark avatar May 31 '25 23:05 taqtiqa-mark

Ah, that's on me! I pushed an update and tested - the page should now load. (There's no separate reporting for that site, it's just a student-run add-on for our classes..)

You can find a more general getting started here: https://chipyard.readthedocs.io/en/stable/Prototyping/VCU118.html#building-linux-with-firemarshal

And the actual FireMarshal (the tool you can use for building the Linux image) documentation here: https://firemarshal.readthedocs.io/en/latest/index.html

Thanks for the clarification! Sorry for misunderstanding initially. What you're saying makes sense to me. Based on the tutorial you linked, using these F1/F2 instances is the same as ssh-ing into a regular machine with an FPGA connected, is that correct?

If we can abstract away the AWS detail that easily, then maybe you can use the existing bring-up docs and simply run the commands while ssh'ed. Specifically, you can try looking at this tutorial: https://ucb-ee290c.github.io/tutorials/baremetal-ide/Baremetal-IDE-Lab.html

./uart_console might be similar to:

Our emulated chip has a UART-TSI port which is an interface that allows a computer to make TileLink read/writes by reading/writing to a UART. Normally, this would be on a separate FPGA when you are talking to a real chip but for simplicity, this lab only uses one FPGA. uart_tsi is a program that can read in an ELF binary, read the header, and issue the correct write commands to load the binary into the chip’s memory.

So the equivalent command to load_elf ../C_Examples/hello/hello.RV64.bare.elf would be something like:

uart_tsi +tty=[YOUR_TTY] +baudrate=921600 build/d01/blinky.elf

But you need to make sure this makes sense for your DUT. I think the "building a compatible Linux image" and "establishing communication with the DUT" can be treated as two separate problems, i.e. it might be worth to test with a simple Hello World first. And then "and then run an ELF file in linux" (if you need to do so, rather than running baremetal?) would be a third problem.

If you manage to get it to work and want to add some documentation, we'd be happy to upstream it! :D Might be helpful for folks who don't have physical FPGA access.

Fi50 avatar Jun 01 '25 00:06 Fi50

Based on the tutorial you linked, using these F1/F2 instances is the same as ssh-ing into a regular machine with an FPGA connected, is that correct?

It appears a little more convoluted than that.

There are simultaneous connections in play. See Slides 32 and 38-39.

I find the initial difficulty in porting "FPGA hardware present locally" tutorials or examples to the "FPGA present remotely" is the SDCard related steps. In addition, as you note, for remote cases there is also the addition of a remote VM in the mix, and the "FPGA shell" (AWS parlance) that is also involved.

Also, my initial expectation of a generic UART connection tool should reveal my naivete.... IIUC now, I believe each chip design build would be expected to provide this? Where and how is pretty much up to the authors of the chip/system.

If you manage to get it to work and want to add some documentation, we'd be happy to upstream it! :D Might be helpful for folks who don't have physical FPGA access.

Okay, I'll make notes and post as I can. I have several balls in the air so progress will be intermittent.

Thanks for the tips and pointers.

taqtiqa-mark avatar Jun 01 '25 03:06 taqtiqa-mark

Tutorials for firesim exist here, including archives: https://fires.im/blog/ This will help you run any existing soft CPUs [given it is ported to chipyard, if not, you want to probably look into blackboxing them in chipyard] or new RTL developed in Chipyard.

searching "firesim tutorials" on google also turns out a bunch from past conferences.

https://fires.im/asplos23-slides-pdf/09_running_firesim_simulation.pdf might help regarding getting started on AWS, it also has instructions to run an elf.

F1 has been deprecated by AWS. We will be releasing instructions for AWS F2 soon, but the gist to running on F2 is almost the same as F1, so the above should still be relevant.

In terms of running bare designs in F1/F2, we have found that AWS has built in abstractions (ie Amazon has built an FPGA shell with specific design parameters). While we have made it work with FireSim, it is probably out of scope for us to port a "chipyard fpga-shell" to be compatible with their shell. We usually let FireSim act as the layer of abstraction here between a Chipyard/RTL design and AWS FPGAs.

jimfangx avatar Jun 18 '26 02:06 jimfangx