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

resources: Add doc for riscv-fs-busybox-opensbi-nodisk resource #61

Open
wants to merge 7 commits into
base: stable
Choose a base branch
from

Conversation

teloecho
Copy link

Inspired by riscv-fs-nodisk however, replacing legacy Berkeley bootloader (bbl) with OpenSBI FW_PAYLOAD bootloader, additionally just using default Linux and Busybox configurations instead of not up-to-date UCanLinux configs.

I was missing an up-to-date guide for fully self-build simple linux environment for Gem5 RISC-V full system simulations.
Therefore i compiled this guide from other guide here and online together.
The use case could be playing around with custom RISC-V instructions and custom toolchain.

Btw: i tried to use pre-commit, but i got the error No .pre-commit-config.yaml file was found on commit.

Inspired by riscv-fs-nodisk however, replacing legacy Berkeley
bootloader (bbl) with OpenSBI FW_PAYLOAD bootloader, additionally
just using default Linux and Busybox configurations instead of not
up-to-date UCanLinux configs.
@teloecho teloecho marked this pull request as ready for review December 2, 2024 08:40
@teloecho
Copy link
Author

teloecho commented Dec 2, 2024

@powerjg or @BobbyRBruce i would like to add you as reviewers, but i am not sure, if i am authorized.

Copy link
Contributor

@powerjg powerjg left a comment

Choose a reason for hiding this comment

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

First, thanks for the contribution! I think this information is great to get out to the broader community.

However, I'm not sure the appropriate place is gem5-resources. This repo is for the sources to build resources that are available on resources.gem5.org. Are you proposing that we (the gem5 community) distribute this kernel/bootloader/filesystem? If so, who are the users of this?

Maybe a better place for this document would be the gem5 blog: https://www.gem5.org/blog/

I'm open to a conversation, though :)

One last thing, if you could run a markdown linter, it would improve the formatting. E.g., https://github.com/markdownlint/markdownlint or https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint if you're using vscode.

Comment on lines 41 to 62
[GNU toolchain for RISC-V](https://github.com/riscv-collab/riscv-gnu-toolchain).

This step is necessary if you do not have basic libraries built for RISCV or
if you're cross-compiling RISCV.

```sh
cd riscv-all-in-one/
git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git
cd riscv-gnu-toolchain
git switch --detach 20f615317e2ce888dfc11b29ccde4a649494b654 # for reproducability, newer versions should work either
mkdir build
cd build
# --prefix parameter specifying the installation location
# --enable-multilib build either cross-compiler with support for both 32-bit and 64-bit
../configure --prefix=/path/to/rvtoolchain --enable-multilib
make linux -j$(nproc)
```
To update the PATH environment variable so that the RISCV compilers can be
found,
```sh
export PATH=/path/to/rvtoolchain/bin/:$PATH
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to compile the toolchain? If there's a good reason not to use the precompiled toolchain from Ubuntu, then this step is OK, but if it's possible to use the precompiled toolchain, then we should do that.

Copy link
Author

Choose a reason for hiding this comment

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

It might be helpful if you modify the toolchain itself, however in the default case for this resource the shipped toolchain is faily enough, so i changed it to use Debian's g++-12-riscv64-linux-gnu package. See lines 43-74.

git clone --branch 1_36_stable https://git.busybox.net/busybox.git # choose a stable branch

# alternatively downloading tar
wget https://git.busybox.net/busybox/snapshot/busybox-1_36_1.tar.bz2
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we do have to compile busybox (unlike gcc above). But can you confirm this?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, Busybox is not distributing for the required RISCV platform (see their download page). Also i configure it to use no shared libraries in order to simplify the guide.

Comment on lines 216 to 217
make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- menuconfig
Copy link
Contributor

Choose a reason for hiding this comment

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

riscv64-unknown-linux-gnu-? Above you used riscv64-linux-gnu-.

We should use just one cross compiler, and, unless there's a really good reason, it should be a precompiled toolchain, not one that we compile ourselves.

Copy link
Author

Choose a reason for hiding this comment

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

In the initial commit the lines that referred to riscv64-linux-gnu- just mentioned an alternative usage if the toolchain was not prefixed by the default riscv64-unknown-linux-gnu-. Sorry for the confusion.

As i use the Debian shipped compilers now, i have to specify the toolchain prefix for scons anyways. See line 109.

Comment on lines 237 to 240
You can run the created bootloader with Linux and Busybox payload using the example riscv `fs_linux.py` config,
```sh
cd gem5
./build/RISCV/gem5.opt configs/example/riscv/fs_linux.py --kernel="../gem5-resources/src/riscv-fs/riscv-all-in-one/opensbi/build/platform/generic/firmware/fw_payload.elf"
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 prefer all examples to use the stdlib. If you could describe how to turn this into a Workload it would improve the description.

Copy link
Author

Choose a reason for hiding this comment

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

This is the hard part for me. As far as i see, only specifying a bootloader without kernel and disk image is not intended by the boards, e.g. RiscvBoard or RISCVMatchedBoard.

Therefore i just show how to slightly modify the riscv-fs.py by obtaining the new kernel or bootloader resource and leaving the disk_image (and kernel) parameter of the set_kernel_disk_workload call unmodified (as dummy resource). See lines 266-282

In the end it might look like

# Set the Full System workload.
board.set_kernel_disk_workload(
    kernel=obtain_resource(
        "riscv-bootloader-vmlinux-5.10", resource_version="1.0.0"
    ), # dummy resource
    disk_image=obtain_resource("riscv-disk-img", resource_version="1.0.0"),  # dummy resource
    bootloader=obtain_resource(
        "riscv-fs-busybox-opensbi-nodisk", resource_version="1.0.0"
    ),
)

following suggestion of review on PR gem5#61 to use the more convinient
precompiled toolchain. self-compiled is useful for modified toolchain,
but not required for reproducibility of the standard resource though
improvements for PR gem5#61
- fix markdown formatting (blank lines, links, etc.)
- clarify comment alternative initramfs.cpio archive generation
- change permalink and add a tag to highlight nodisk charakter
- reorder tags to align with other resource READMEs
- describe how to use the resource within the gem5 stdlib framework
  as a bootloader or kernel passed to set_kernel_disk_workload()
- add licensing notes for OpenSBI, Linux and Busybox
@teloecho
Copy link
Author

teloecho commented Jan 2, 2025

Thank you very much for the thorough review and the hints for improvement!

I should have incorporated your suggestions somehow (see comments on your comments :).

However, I'm not sure the appropriate place is gem5-resources. This repo is for the sources to build resources that are available on resources.gem5.org. Are you proposing that we (the gem5 community) distribute this kernel/bootloader/filesystem? If so, who are the users of this?

Maybe a better place for this document would be the gem5 blog: https://www.gem5.org/blog/

I'm open to a conversation, though :)

Regarding the appropriate place.
Well, i would propose that you distribute this bootloader resource indeed.
Although i was/am not sure either.
The advantage of this resource is its straight forward reproducibility, usability for many cases and small size.
It might be useful if you like to craft a workload utilizing systemcalls or run several user programs and if you like to observe the whole boot process.
Utilizing custom instructions relevant for the boot process usually requires to rebuild a lot from toolchain via bootloader and kernel up to the user binaries. These instructions might guide you very well through all the steps then.

So why to distribute via gem5-resources? -- It might be a good starting point for people to check whether this type of "nodisk resource" already fits their needs.
Would this convince you? If not, i would also be fine with a blog post.

@teloecho teloecho requested a review from powerjg January 2, 2025 17:26
- move m5 exit to beginning of script and extract shell setup into
  extra script for better readability
- swap setsid,hotplug lines (script doesn't proceed after setsid line)
- fix version in busybox docs link
@teloecho teloecho changed the title resources: Add guide for riscv-fs OpenSBI bootloader, Linux and Busybox nodisk resource resources: Add doc for riscv-fs-busybox-opensbi-nodisk resource Jan 28, 2025
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

Successfully merging this pull request may close these issues.

2 participants