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

Tutorial docs #283

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions docs/source/Tutorials/custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,76 @@ known good output of "Hello World!".

.. todo:: Add (or link to) more detailed examples of bare-metal and rocc workloads.


Using the same directory structure for both bare-metal and buildroot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the other tutorials here (https://firemarshal.readthedocs.io/en/latest/Tutorials/custom.html), it looks like we really just need to add one on BuildRoot and not baremetal. Even then, the Fedora tutorial describes much of what you want... so I think if the docs really want to get fixed I would do the following:

  1. Re-order the "Custom Workloads" tutorials to be 1. BuildRoot Linux Hello World (w/ descriptions of parameters probably taken from the existing Fedora tutorial), 2. Baremetal Hello World 3. Fedora Hello World.

  2. For sharing, I think the test/bare.yaml workload already implements the baremetal hello world... instead of copying that we should repurpose it for the tutorial (I think that workload compile could be simplified). OR we can symlink the example from the test area (or vice version).

-----------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Newline after this.

In this step, we will see how we can use the same directory structure for both
baremetal and buildroot.


First, we will build a "Hello World" binary for buildroot.
Lets take a look at ``example-workloads/example-br.json``.

.. include:: example-workloads/example-br.json
:code: json

First you will see the ``name`` field set to ``example-br``. This indicates that
the directory that we will be working on. Next, you will see that our
base workload is set to buildroot by setting ``base`` to ``br-base.json``.

The ``overlay`` field indicates the directory to overlay on the rootfs
which is under ``example-br/overlay``. That is, you will see a ``/root/hello-world``
directory once you boot linux with this built workload. The files under ``overlay/root/hello-world/``
are also copied into the file system. One caveat is that the overlay directory structure
has to match the rootfs directory structure.

The ``host-init`` field indicates the script to run while building the workload.
If you look into ``example-br/host-init.sh`` you can see that it runs a ``make``
command to cross-compile our "Hello World" binary.

.. include:: example-workloads/example-br/host-init.sh
:code: bash

Finally the workload consists of individual ``jobs``. The ``outputs`` field
specifies the files that you want to copy out from the file system after the
simulation has ended. ``run`` sets the script to run on the target once the
simulation starts. If you take a look into ``example-br/run.sh``, you can see
that it is executing our "Hello World" binary and terminating the simulation by
runnint ``poweroff``.

.. include:: example-workloads/example-br/run.sh
:code: bash

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Consistent newlines (use 2 or 1 between paragraphs)


We are ready to build and install the workload for FireSim!

::

./marshal -v build example-workloads/example-br.json
./marshal -v install example-workloads/example-br.json
Comment on lines +154 to +159
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add this as a .. note:: since FireMarshal is separate from FireSim in the documentation.



Now lets see how we can reuse this directory structure to run a baremetal simulation.

.. include:: example-workloads/example-baremetal.json
:code: json

As the buildroot case, you will see that the ``name`` field is set to ``example-br``.
Now, we configure our ``base`` to ``bare-base.json`` to indicate that we will building
a baremetal workload. In addition, we can reuse the ``host-init.sh`` script as before
to compile our "Hello World" binary. Last but not least, we set the boot binary
by the ``bin`` field. The path to the file should be relative to the ``example-br`` directory.
Hence it is ``overlay/root/hello-world/hello-world.riscv`` in our example.


Now we can build and install our baremetal workload for FireSim!

::

./marshal -v build example-workloads/example-baremetal.json
./marshal -v install example-workloads/example-baremetal.json


Next Steps
-------------------
For more examples, you can look in the ``test/`` directory. The full set of
Expand Down
6 changes: 6 additions & 0 deletions example-workloads/example-baremetal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name" : "example-br",
"base" : "bare-base.json",
"host-init" : "host-init.sh",
"bin" : "overlay/root/hello-world/hello-world.riscv"
}
13 changes: 13 additions & 0 deletions example-workloads/example-br.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name" : "example-br",
"base" : "br-base.json",
"overlay" : "overlay",
"host-init" : "host-init.sh",
"jobs" : [
{
"name" : "hello-world",
"outputs" : [ "/root/hello-world/target.out" ],
"run" : "run.sh"
}
]
}
5 changes: 5 additions & 0 deletions example-workloads/example-br/host-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo "Build Hello World"
cd overlay/root/hello-world
make
13 changes: 13 additions & 0 deletions example-workloads/example-br/overlay/root/hello-world/Makefile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Makefile only works for baremetal not Linux since you are using the unknown-elf compiler.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
RISCV_PFX=riscv64-unknown-elf-
RISCV_GCC=$(RISCV_PFX)g++

BINARY_OPT=-static -specs=htif_nano.specs

TARGET=hello-world

$(TARGET).riscv : $(TARGET).c
$(RISCV_GCC) $(BINARY_OPT) -o $@ $^

.PHONY: clean
clean:
rm -f *.riscv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

int main() {
printf("hello charles\n");
return 0;
}
5 changes: 5 additions & 0 deletions example-workloads/example-br/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cd root/hello-world
./hello-world.riscv > target.out
poweroff