Hi all,
I apologise in advance, this might be long-winded as I am fairly new to CheriBSD and Morello. I have an AWS machine running Ubuntu 18 on an Intel x64 system.
My aim is to have a CheriBSD instance running the Arm Morello FVP, and to then compile, debug and run various pieces of software. Obviously, some of the source code will have to be amended to account for the CHERI changes to pointers and accepted data types.
A quick read of the CheriBSD GitHub tells me that ./cheribuild.py is my go-to for building all things CheriBSD. I've cloned the cheribuild GitHub repo so that I can use the script to install what I need.
At the moment, I'm running:
./cheribuild.py run-morello-purecap -d
...but my questions are:
What is that coming with? Do I already have everything I need as part of the development toolchain to compile (Clang/LLVM), debug (gdb)? Does that create a disk image? How do I find everything that is being included when running that command?
How do I find the dependencies that are being included and built when using -d?
When running ./cheribuild.py --list-targets, it displays multiple of what look like closely similar options. How do I know which one I need to specify? What is the difference between llvm-native, llvm-morello-purecap, morello-llvm-morello-purecap and llvm, for example? Are some of these simply aliases and mean the same thing? Are some being added to the host machine, and some being added to the CheriBSD instance?
How do the disk-images work with ./cheribuild disk-image-<architecture>? Can I boot from this to save the machine state? How can I save the state of the machine so that I can reboot, and pick back up from where I left off? This would be nice to know so I don't have to build every time I exit or have to use a command like screen, or is this simply not possible.
What is the difference between ./cheribuild.py run-morello-purecap -d and ./cheribuild.py cheribsd-morello-purecap -d?
If I build using ./cheribuild run-morello-purecap -d and then realise I would like to build another target such as Nginx for example and add it to the instance already built, do I simply run: ./cheribuild nginx-morello-purecap, and it will "amend" the CheriBSD instance, or is there another method I should be using instead?
Does all compilation, debugging etc. take place on the host machine, rather than CheriBSD itself?
--------------------------
I appreciate there are a lot of questions here and a lot to go through, so I appreciate anyone offering help to somebody new to the area!
If there is any documentation, guides or tutorials that answers my questions, please post the link as I am trying to be a self-learner as much as possible :)
Thanks!
samDobson said:Any ideas why I don't have this? Do I have to place it there myself? I get this message when using ./cheribuild.py: Warning: Configuration file /home/ubuntu/.config/cheribuild.json does not exist, using only command line arguments.
Any ideas why I don't have this? Do I have to place it there myself?
I get this message when using ./cheribuild.py:
Warning: Configuration file /home/ubuntu/.config/cheribuild.json does not exist, using only command line arguments.
The config file will not be created automatically, so if you want to override some defaults persistently you need to create it manually.
This warning message should not be a warning, just an information message. I didn't notice that it is warning since I have a config file set up everywhere I use cheribuild. I just pushed a fix and this should no longer say "warning".
samDobson said:....... qemu go ninja ....... How do I know which platform these are to be installed on? Are they purecap, hybrid, native? Are they for MIPS, RISC-V, Morello? Are they for the host machine or CheriBSD?
.......
qemu
go
ninja
How do I know which platform these are to be installed on? Are they purecap, hybrid, native? Are they for MIPS, RISC-V, Morello? Are they for the host machine or CheriBSD?
If there is no target suffix, this (almost) always means that cross-compilation is not supported yet so it will be a host binary.
samDobson said:Taking this into account, what is the recommended way to close down the CheriBSD session (I am using PuTTY) so that I can return to the host machine to build Nginx with cheribuild before overwriting the disk image with ./cheribuild.py nginx-morello-purecap disk-image-morello-purecap? And then after this, what is the best way to quickly get CheriBSD booted again so I can continue my work? If I shut down CheriBSD without overwriting the disk, will all my work be lost? Also, seeing as running ./cheribuild.py run-fvp-morello-purecap executes the disk-image-morello-purecap target, if I want to boot CheriBSD without overwriting the disk, should I run ./cheribuild.py cheribsd-morello-purecap?
Taking this into account, what is the recommended way to close down the CheriBSD session (I am using PuTTY) so that I can return to the host machine to build Nginx with cheribuild before overwriting the disk image with ./cheribuild.py nginx-morello-purecap disk-image-morello-purecap? And then after this, what is the best way to quickly get CheriBSD booted again so I can continue my work? If I shut down CheriBSD without overwriting the disk, will all my work be lost?
Also, seeing as running ./cheribuild.py run-fvp-morello-purecap executes the disk-image-morello-purecap target, if I want to boot CheriBSD without overwriting the disk, should I run ./cheribuild.py cheribsd-morello-purecap?
CheriBSD will write back all changes to the disk image regularly. However, if you kill the emulator, you might lose some in-flight changes or corrupt the image. I would recommend using the `poweroff` command to shut down cleanly. But if you are rebuilding the disk image anyway to include new files you can just kill the emulator (CTRL+A followed by X for QEMU and CTRL+] followed by q<ENTER> for the FVP).
If you want to boot without overwriting the disk image you can run `cheribuild.py run-fvp-morello-purecap` without "-d" - in that case dependencies such as disk-image-morello-purecap are skipped.
samDobson said:When cross-compiling from the host machine to CheriBSD, is the recommended workflow to have two sessions running, one for the host machine, and one for CheriBSD? Does the CheriBSD instance have to be up and running when cross-compilation occurs?
Yes, I would absolutely recommend using multiple sessions. There is no need to have CheriBSD running when you cross-compile since this does not affect the running CheriBSD instance (unless you have the installation directory mounted in the CheriBSD VM - for QEMU this can be done by running the `qemu-mount-rootfs.sh` script).
Thanks so much for this!
I've got it all up and running now with ./cheribuild.py run-fvp-morello-purecap -d. I have all the required dependencies installed on my host machine stated here: https://github.com/CTSRD-CHERI/cheribuild#:~:text=the%20following%20packages%3A-,apt%20install,-autoconf%20automake%20libtool
I have a hello-world.c program I'd like to cross-compile across to the CheriBSD OS. What does this process look like? Is there a guide I can follow?
Also, how does the cheribsd-sdk-<architecture> come into play during this whole process?
samDobson said:I have a hello-world.c program I'd like to cross-compile across to the CheriBSD OS. What does this process look like? Is there a guide I can follow?
If you want to compile a simple C/C++ file, cheribuild installs some helper scripts in output/morello-sdk/utils/cheribsd-morello-purecap-clang(++) that will add the necessary compiler flags to select right ABI and CheriBSD sysroot (the flags are defined in output/morello-sdk/bin/cheribsd-morello-purecap.cfg). If you want to compile something more complicated, I would recommend adding a new target to cheribuild. I've added a short wiki page that shows how to add new targets, I hope it is helpful: https://github.com/CTSRD-CHERI/cheribuild/wiki/Adding-a-new-cheribuild-target.
We also have a few CHERI exercises here: https://ctsrd-cheri.github.io/cheri-exercises/introduction/index.html . The guide mostly talks about CHERI-RISC-V but applies equally to Morello.
samDobson said:Also, how does the cheribsd-sdk-<architecture> come into play during this whole process?
This target is effectively and alias to build a compiler and a sysroot. If you already booted CheriBSD, you will have both of these so you won't need to run cheribsd-sdk-<foo>.