2020-03-10 04:04:17 +00:00
# Xous Core
Core files for the Xous microkernel operating system.
2021-10-30 16:29:08 +00:00
You might find this [wiki ](https://github.com/betrusted-io/betrusted-wiki/wiki ) handy, as well as the [Xous Book ](https://betrusted.io/xous-book/ ).
2021-01-21 17:53:57 +00:00
2020-03-10 04:04:17 +00:00
This repository contains everything necessary to build the Xous kernel
from source. It consists of the following projects:
* **kernel**: core memory manager, irq manager, and syscallhandler
* **loader**: initial loader used to start the kernel
* **tools**: programs used to construct a final boot image
* **docs**: documentation on various aspects of Xous
* **emulation**: Renode scripts used to emulate Xous
* **xous-rs**: userspace library
2020-03-10 06:45:18 +00:00
2021-07-10 20:35:36 +00:00
## Dependencies
2021-08-20 09:52:18 +00:00
2021-10-27 05:52:03 +00:00
- Xous requires its own Rust target, `riscv32imac-unknown-xous-elf` . If you run `cargo xtask` from the command line, you should be prompted to install the target automatically if it does not already exist.
2021-10-27 16:34:10 +00:00
- You may need to remove the `target/` directory before building, if `rustc` continues to behave like it can't find the `xous` target even after it is installed.
2021-08-20 09:52:18 +00:00
- If you plan on doing USB firmware updates, you'll need `progressbar2` (updates) and `pyusb` (updates). Note that `pyusb` has name space conflicts with similarly named packages, so if updates aren't working you may need to create a `venv` or uninstall conflicting packages.
- If you are doing development on the digital signatures with the Python helper scripts, you will need: `pycryptodome` (signing - PEM read), `cryptography` (signing - x509 read), `pynacl` (signing - ed25519 signatures) (most users won't need this).
2021-12-14 17:55:45 +00:00
- Some system packages are needed, which can be installed with `sudo apt install libssl-dev libxkbcommon-dev` or similar
- If you receive an error about `feature resolver is required` , try installing a newer version of `rustc` and `cargo` via [rustup ](https://rustup.rs )
2021-07-10 20:35:36 +00:00
2020-11-03 12:41:37 +00:00
## Quickstart using Hosted Mode
2020-03-10 06:45:18 +00:00
2020-11-03 12:41:37 +00:00
You can try out Xous in a "hosted mode" wherein programs are compiled
for your native platform and are run locally as processes within your
current operating system. System calls are replaced with network calls
to a kernel that simply shuffles messages around.
Xous uses the [xtask ](https://github.com/matklad/cargo-xtask/ ) convention,
where various complex build commands are stored under `cargo xtask` .
This allows for us to create arbitrarily complex build sequences
without resorting to `make` (which is platform-dependent),
`sh` (which requires a lot of external tooling), or another build
system.
To build a set of sample programs and run them all using the
kernel for communication, clone this repository and run:
2020-03-10 06:45:18 +00:00
```sh
2020-11-03 12:41:37 +00:00
cargo xtask run
2020-03-10 06:45:18 +00:00
```
2020-11-03 12:41:37 +00:00
This will build several servers and a "shell" program to control them
all. Most notably, a `graphics-server` will appear and kernel messages
will begin scrolling in your terminal.
## Quickstart using an emulator
Xous uses [Renode ](https://renode.io/ ) as the preferred emulator, because
it is easy to extend the hardware peripherals without recompiling the
entire emulator.
2020-03-10 06:45:18 +00:00
2020-11-03 12:41:37 +00:00
[Download Renode ](https://renode.io/#downloads ) and ensure it is in your path.
2022-04-03 05:10:56 +00:00
For now, you need to [download the nightly build ](https://dl.antmicro.com/projects/renode/builds/ ),
until `DecodedOperation` is included in the release.
2020-11-03 12:41:37 +00:00
Then, build Xous:
2020-03-10 06:45:18 +00:00
```sh
2020-11-03 12:41:37 +00:00
cargo xtask renode-image
2020-03-10 06:45:18 +00:00
```
2020-09-22 15:54:32 +00:00
2020-11-03 12:41:37 +00:00
This will compile everything in `release` mode for RISC-V, compile the tools
require to package it all up, then create an image file.
2020-09-25 09:11:52 +00:00
2020-11-03 12:41:37 +00:00
Finally, run Renode and specify the `xous-release.resc` REnode SCript:
2020-09-25 09:11:52 +00:00
2020-11-03 12:41:37 +00:00
```sh
renode emulation/xous-release.resc
```
2020-09-25 09:11:52 +00:00
2020-11-03 12:41:37 +00:00
Renode will start emulation automatically, and will run the same set of programs
as in "Hosted mode".
2020-09-25 09:16:44 +00:00
2020-11-03 12:41:37 +00:00
## Generating a hardware image
To build for real hardware, you must specify an `.svd` file. This
file is generated by the SoC build process and describes a single
Betrusted core. These addresses will change as hardware is modified,
so if you distribute a modified Betrusted core, you should be sure
to distribute the `.svd` file.
2021-08-20 09:52:18 +00:00
We have included a reference version of the gateware and its SVD
file in the `precursors` directory, so you can compile a gateware
for the reference image using this command:
2020-11-03 12:41:37 +00:00
```sh
2021-08-20 09:52:18 +00:00
cargo xtask hw-image precursors/soc.svd
2020-09-25 09:16:44 +00:00
```
2021-08-20 09:52:18 +00:00
The resulting images are in your target directory (typically `target/riscv32imac-unknown-xous-elf/release/` )
with the names `xous.img` (for the kernel) and `loader.bin` (for its bootloader). The corresponding
gateware is in `precursors/soc_csr.bin` . These can be written to your
2021-10-27 05:52:03 +00:00
device by following the [update guide ](https://github.com/betrusted-io/betrusted-wiki/wiki/Updating-Your-Device ).