-
Notifications
You must be signed in to change notification settings - Fork 7
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
Building cheriot-safe for Artix-A7 100T #3
Comments
We need to update the build instructions in the RTOS repo, because the CHERIoT compiler is now maintained here. The easiest way of making sure that you have an up-to-date developer environment is to use the dev container, which includes the latest toolchain and the Sail and Ibex simulators. The RTOS includes a board description file (ibex-safe-simulator.json) that is tested with the Verilator simulator (see: https://cheriot.org/jekyll/update/2023/10/17/ibex-now-in-dev-container.html). The FPGA build should have the same memory layout, so firmware images built with that should work on the FPGA as well (I have not yet tested this). @kliuMsft can hopefully explain how to load it. It's possible that the clock speed will be different and so you may need to tweak this line. |
Hello, Thanks for the reply! |
@Thingybob8055 I updated a couple more scripts and a simple README under build/. However it looks like you are ahead of me - which is great. I believe just by putting firmware images in the right place during synthesis, they are included in the bitfile. Please give it a try. You can also use openocd/jtag to load image but that would require some scripting (to talk to the backdoor memory access port in FPGA through JTAG). |
Thanks! I will try it out. I assume the compiler produces the firmware images. |
Here's the answer to your earlier questions,
I will try to work out a software build example. Meanwhile if you can try the cheri_sanity or coremark example in the sim/verilator directory it would be good. The examples don't drive LEDs but they do print to UART, which is connected to the USB port on A7 and if things work out you should be able to see printouts on a serial terminal like PuTTY or TeraTerm |
@Thingybob8055 I have added an (hopefully complete) example under sim/verilator/examples/hello_world. The example simply prints out a message on uart and blinks 2 LEDs, however it contains all the necessary startup code that you can use to start developing bare-metal the CHERIoT way.. Please let me know how it works out. |
Hello, |
Yes the vhx in veriator/examples should work - I'd suggest trying the hello_world first since it also should blink LED. You can use either the dev container or locally installed toolchain (in which case the build_fpga_test.sh in hello_world can serve as an example) |
Hello, |
I followed the build instructions for the compiler (the same one linked above)
I managed to get a
Is this the correct way to convert the EDIT: I used the objcopy binary provided here, and it worked: https://github.com/lowRISC/lowrisc-toolchains/releases |
Yes you will have to massage the file paths in build_fpga_test.sh a little bit to get things to work. you can use either the obj_copy comes with the LLVM or GCC toos. Your steps look good - great job. cpu0_irom0.vhx just jumps to iram, so it can be reused. |
I tried manually compiling a firmware hex file using my steps and it did work! |
This might take a little time, as I need to remember how JTAG loading works for this board. Also this way you may not be able to use the same usb/jtag connection to load both bitfile and firmware image. Possibly another usb2jtag (FH232) is needed. |
The other approach that I’ve been pondering is to provide an IROM loader that reads the firmware into IRAM over the UART and then jumps to it. That might be easier than using JTAG. Writing 256 KiBs at 115,200 baud will be a lot quicker than reprogramming the FPGA. |
That's definitely a valid approach. Either way you probably want to program the bit file to flash or micro SD, so that you can reboot/reload bit file by just resetting the board. |
Generating the bit file from Vivado takes quite a long time actually and can be a bit of a wait, if I change just one line in the C programs for example. Which is why I was wondering if I can use |
I managed to make the hello_world example in Edit: fix my brainfart |
@atrieu, just to confirm, if you use the firmware image in sim/verilator/examples/hello_world/firmwrare on FPGA board (not in sim), do you see the correct UART printout? |
Yes, this one works. That's what I meant by build/ initially, but I brainfarted. |
In this case I suspect the example in cheri-rtos may need an update. @davidchisnall, I recall that you had to tweak the uart settings to get it work in rtos? |
Hi, I have a BSP for the A7 that I hope works, but have not got an A7 to test it with. I will post it to a branch this morning for feedback. |
Try this branch: https://github.com/microsoft/cheriot-rtos/tree/arty-a7 You will need to set board to ibex-arty-a7-100 during the configure step when building. This should work with the UART and exposes an LED driver for two of the LEDs. |
Note: Resetting still doesn't work, but if someone can confirm that the UART driver works then I will add something to load firmware over the UART that can run in IROM. |
@davidchisnall Thanks, it worked on my board !
For the record, I executed the following commands in the dev container in VSCode: $ cd cheriot-rtos/examples/01.hello_world/
$ xmake config --sdk=/cheriot-tools/ --board=ibex-arty-a7-100
[...]
$ xmake
[...]
$ cd build/cheriot/cheriot/release/
$ ../../../../../../scripts/run-ibex-safe-sim.sh hello_world Then I copied the produced |
Hurray! That is what should happen. Can you try adding this to the example: Somewhere at the top: #include <platform-leds.hh> Somewhere around the hello world line: auto leds = MMIO_CAPABILITY(LEDs, gpio_led0);
leds->enable_all();
bool on = true;
while (true)
{
if (on)
{
leds->led_off(0);
leds->led_on(1);
}
else
{
leds->led_on(0);
leds->led_off(1);
}
on = !on;
Timeout t{100};
thread_sleep(&t);
} This should make two of the LEDs alternate on/off states. |
I had to include a bit more, but it works ! LD5 and LD6 are alternating and LD4 is flickering. Complete #include <platform-gpio-leds.hh>
#include <thread.h>
#include <compartment.h>
#include <debug.hh>
#include <fail-simulator-on-error.h>
/// Expose debugging features unconditionally for this compartment.
using Debug = ConditionalDebug<true, "Hello world compartment">;
/// Thread entry point.
void __cheri_compartment("hello") say_hello()
{
auto leds = MMIO_CAPABILITY(LEDs, gpio_led0);
leds->enable_all();
bool on = true;
Debug::log("Hello world");
while (true)
{
if (on)
{
leds->led_off(0);
leds->led_on(1);
}
else
{
leds->led_on(0);
leds->led_off(1);
}
on = !on;
Timeout t{100};
thread_sleep(&t);
}
// Print hello world, along with the compartment's name to the default UART.
} |
@davidchisnall Hi |
Hi, I wrote a few instructions here. Basically, rerun the build_arty_a7 script with the committed vhx (if you don't like running random binaries, rebuild the vhx from here). When it boots, it will then ask for firmware. I use minicom for talking to the board. Minicom ( If you are building CHERIoT RTOS, I've added a little bit of board support code there. Use David |
Not sure if this is the right place to ask, but are CHERI exception causes fully implemented ? I have tried playing around with it for testing. Basically, I have set up void exn_handler() {
volatile unsigned int mcause;
volatile unsigned int mtval;
char buf[11];
__asm__ __volatile__("csrr %0, mcause": "=r" (mcause));
__asm__ __volatile__("csrr %0, mtval": "=r" (mtval));
uart_puts("Hello from the exception handler!");
uart_print_string("Exception cause: 0x");
write_nibbles(mcause, buf);
uart_puts(buf);
if (mcause == 0x1C) {
unsigned int cap_exn_cause = mtval & 0x1F;
uart_print_string("Capability exception cause: 0x");
write_nibbles(cap_exn_cause, buf);
uart_puts(buf);
}
while (1);
return;
} Then, I trigger an exception with
I get the following
while I would expect to find a tag violation with code This happens on both the simulator and my Arty A7. |
Hi @atrieu, There is currently a bug in exception priorities in Ibex. See this comment for the work-around that we use in the software stack. You should still get CHERI exceptions at the right point, but they will be the wrong numbers. This is tracked in microsoft/cheriot-ibex#11 and will hopefully be fixed soon. We're currently not using the CHERI exception causes for anything other than debugging, so it hasn't been a high priority. You might be interested in talking to Tom Melham at Oxford. His students have been working on verifying the Ibex. |
Hi @atrieu, Any way you can attach your ibex trace for the exception handler execution? As David pointed we haven't fully implemented exception causes yet, but even the existing RTL is supposed to report code 2 in this case (I have a very similar test case). So I am a little bit puzzled as why you are seeing this. Thanks. |
Hi @kliuMsft, Sorry for the late answer, I was traveling. You can find the full simulator trace here: https://gist.github.com/atrieu/16ef5aa869676d37c79174068ee70453 I'm guessing the interesting part is here https://gist.github.com/atrieu/16ef5aa869676d37c79174068ee70453#file-cheriot_cap_exn_trace-log-L4586-L4596
It shows that reading |
Hi @atrieu, Thanks! There is indeed a bug in the cheriot-ibex reporting which caused mtval not updating for a rv32 load/stores. I pushed a fix in the cheriot-ibex repo, would really appreciate if you can give it a try. |
Hi @kliuMsft, Can confirm it works, both in simulator in a locally built devcontainer, and on the fpga board! |
@atrieu, that's great, thanks for confirming! |
Thanks. I've kicked off a rebuild of the devcontainer, which should pick up this fix. |
I believe this can be closed, we now have some getting started instructions for the A7 and it all seems to be working again after the recent breakage. |
Hello,
I have been attempting to build the core for the Arty-A7 100T. I did get it to build but I wanted to point something out and also would like some guidance for getting CHERIot compiled software running on the core.
Software
I am using Vivado 2022.2
Commit used
31ddb47
Steps I used to build
a. All directories from
src
excludingmsft_cheri_tb
b.
rtl/
from cheriot-ibex folderc.
vendor/lowrisc_ip
from cheriot-ibexmsftDvIp_cheri_arty7_fpga.sv
During synthesis and implementatin
When I was synthesising using the Vivado (running as a GUI), I encountered this error:
So I added this line to the constraint file in the repo:
After adding the line, I managed to build and generate the bitstream.
My questions
alive_o
, is this a watchdog LED and does it indicate the system is working correctly?Thanks!
The text was updated successfully, but these errors were encountered: