Skip to content

Commit

Permalink
Merge pull request #1 from au-ts/nfs
Browse files Browse the repository at this point in the history
Add NFS client PD and MicroPython VFS support
  • Loading branch information
Ivan-Velickovic authored Dec 15, 2023
2 parents 31477bf + 329a996 commit 633280d
Show file tree
Hide file tree
Showing 36 changed files with 3,824 additions and 65 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ jobs:
shell: bash
- name: Extract Microkit SDK
run: unzip microkit-sdk.zip && tar -xf microkit-sdk-1.2.6.tar.gz
- name: Download and install AArch64 GCC toolchain
run: |
wget -O aarch64-toolchain.tar.gz https://trustworthy.systems/Downloads/microkit/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-elf.tar.xz%3Frev%3D73ff9780c12348b1b6772a1f54ab4bb3
tar xf aarch64-toolchain.tar.gz
echo "$(pwd)/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-elf/bin" >> $GITHUB_PATH
- name: Build Kitty example
run: nix-shell --pure --run "make -C examples/kitty MICROKIT_SDK=$(pwd)/microkit-sdk-1.2.6"

run: export LIBGCC=$(pwd)/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-elf/lib/gcc/aarch64-none-elf/11.3.1 && make -C examples/kitty MICROKIT_SDK=$(pwd)/microkit-sdk-1.2.6
env:
NFS_SERVER: 0.0.0.0
NFS_DIRECTORY: test/
13 changes: 10 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
[submodule "libvmm"]
path = vmm
url = https://github.com/au-ts/libvmm.git
branch = main
branch = main
[submodule "sddf"]
path = sddf
url = https://github.com/au-ts/sddf.git
branch = kiss
branch = lionsos
[submodule "micropython"]
path = micropython
url = https://github.com/Ivan-Velickovic/micropython.git
branch = kiss
branch = kiss
[submodule "musllibc"]
path = musllibc
url = [email protected]:au-ts/musllibc.git
branch = sel4
[submodule "libnfs"]
path = libnfs
url = [email protected]:au-ts/libnfs.git
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ On Nix/NixOS:
nix-shell --pure
```

You will also need an aarch64 GCC toolchain. The system has been tested with this toolchain: (https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz?revision=79f65c42-1a1b-43f2-acb7-a795c8427085&hash=61BBFB526E785D234C5D8718D9BA8E61). Put the bin directory of the GCC toolchain in your PATH.


### Getting the Microkit SDK

There are a lot of changes to Microkit that have been made over the past year which means
Expand Down Expand Up @@ -68,6 +71,11 @@ cd LionsOS
git submodule update --init
# Enter the Kitty demo directory
cd examples/kitty
# Define NFS server to be used by the NFS client
export NFS_SERVER=0.0.0.0 # IP adddress of NFS server
export NFS_DIRECTORY=/path/to/dir
# Define path to libgcc, where $GCC is the GCC toolchain downloaded above
export LIBGCC=$GCC/lib/gcc/aarch64-none-elf/11.3.1
# Now compile the demo
make MICROKIT_SDK=/path/to/sdk
```
Expand All @@ -92,6 +100,31 @@ MQ with the `-a` flag to automatically get a connection where you can also input
mq.sh run -c "MicroPython" -a -l mqlog -s odroidc4_pool -f build/kitty.img
```

### Testing MicroPython's NFS support

The Kitty system includes an NFS client which MicroPython uses as its filesystem. Most (but not all) of MicroPython's standard file IO operations are supported (importing modules, the file object's methods and functions from the `os` module).

```python
>>> os.listdir()
[]
>>> with open('hello.py') as f:
... f.write('print("hello world")\n')
...
21
>>> os.listdir()
['hello.py']
>>> with open('hello.py') as f:
... print(f.read())
...
print("hello world")

>>> import hello
hello world
>>> os.remove('hello.py')
>>> os.listdir()
[]
```

## Working on Kitty components

For now, all experimentation is to be done in the respective repository.
Expand Down Expand Up @@ -129,4 +162,3 @@ mdbook serve --open
* [Microkit development source code](https://github.com/Ivan-Velickovic/microkit)
* [Odroid-C4 wiki](https://wiki.odroid.com/odroid-c4/odroid-c4)
* [Odroid-C4 SoC Techincal Reference Manual](https://dn.odroid.com/S905X3/ODROID-C4/Docs/S905X3_Public_Datasheet_Hardkernel.pdf)

145 changes: 138 additions & 7 deletions examples/kitty/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ ifeq ($(strip $(MICROKIT_SDK)),)
$(error MICROKIT_SDK must be specified)
endif

ifeq ($(strip $(LIBGCC)),)
$(error LIBGCC must be specified: this should be the directory where libgcc.a can be found)
endif

MICROKIT_CONFIG ?= debug
BUILD_DIR ?= $(abspath build)
MICROKIT_BOARD := odroidc4
Expand All @@ -30,10 +34,28 @@ INITRD := $(VMM_IMAGE_DIR)/rootfs.cpio.gz
DTS := $(VMM_IMAGE_DIR)/linux.dts
DTB := $(BUILD_DIR)/linux.dtb

IMAGES := main.elf micropython.elf timer.elf vmm.elf
CFLAGS := -mtune=$(CPU) -mstrict-align -ffreestanding -g3 -O3 -Wall -Wno-unused-function -I$(BOARD_DIR)/include -target $(TARGET) \
-I$(LIBVMM)/src/arch/aarch64 -I$(LIBVMM)/src -I$(LIBVMM)/src/util -DBOARD_$(MICROKIT_BOARD)
LDFLAGS := -L$(BOARD_DIR)/lib
LWIP=$(SDDF)/network/ipstacks/lwip/src
LIBNFS=../../libnfs
NFS=../../fs/nfs
MUSL=../../musllibc

IMAGES := main.elf timer.elf vmm.elf ethernet.elf micropython.elf nfs.elf copy.elf mux_rx.elf mux_tx.elf arp.elf
CFLAGS := \
-mtune=$(CPU) \
-mstrict-align \
-ffreestanding \
-g \
-O0 \
-Wall \
-Wno-unused-function \
-I$(BOARD_DIR)/include \
-target $(TARGET) \
-I$(LIBVMM)/src/arch/aarch64 \
-I$(LIBVMM)/src \
-I$(LIBVMM)/src/util \
-DBOARD_$(MICROKIT_BOARD) \
-I$(SDDF)/include
LDFLAGS := -L$(BOARD_DIR)/lib
LIBS := -lmicrokit -Tmicrokit.ld

IMAGE_FILE := $(BUILD_DIR)/kitty.img
Expand All @@ -50,7 +72,7 @@ TIMER_DRIVER := $(SDDF)/drivers/clock/meson

PACKAGE_PYTHON_SCRIPTS := src/package_python_scripts.S

all: $(BUILD_DIR) $(IMAGE_FILE)
all: $(DIRECTORIES) $(BUILD_DIR) $(IMAGE_FILE)

$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
Expand Down Expand Up @@ -102,13 +124,122 @@ $(BUILD_DIR)/package_python_scripts.o: $(PACKAGE_PYTHON_SCRIPTS) src/kitty.py
-target $(TARGET) \
$< -o $@

$(BUILD_DIR)/micropython.elf:$(BUILD_DIR)/package_python_scripts.o
$(BUILD_DIR)/micropython.elf: FORCE $(BUILD_DIR)/package_python_scripts.o $(BUILD_DIR)/sddf_timer_client.o $(BUILD_DIR)/sddf_fs_protocol.o
make -C src/micropython -j$(nproc) \
MICROKIT_SDK=$(MICROKIT_SDK) \
MICROKIT_BOARD=$(MICROKIT_BOARD) \
MICROKIT_CONFIG=$(MICROKIT_CONFIG) \
BUILD=$(BUILD_DIR) \
BUILD=$(abspath $(BUILD_DIR)) \
PACKAGE_PYTHON_SCRIPTS=package_python_scripts.o

ETHERNET=$(SDDF)/drivers/network/meson/
$(BUILD_DIR)/meson_ethernet.o: FORCE
BUILD_DIR=$(abspath $(BUILD_DIR)) MICROKIT_INCLUDE=$(BOARD_DIR)/include make -C $(ETHERNET)

LIBSHAREDRINGBUFFER=$(SDDF)/network/libethsharedringbuffer/
$(BUILD_DIR)/sddf_network_sharedringbuffer.o: FORCE
BUILD_DIR=$(abspath $(BUILD_DIR)) MICROKIT_INCLUDE=$(BOARD_DIR)/include make -C $(LIBSHAREDRINGBUFFER)

$(BUILD_DIR)/sddf_timer_client.o: FORCE
BUILD_DIR=$(abspath $(BUILD_DIR)) MICROKIT_INCLUDE=$(BOARD_DIR)/include TIMER_CHANNEL=9 make -C $(SDDF)/timer/client

SDDF_FS_PROTOCOL=../../fs/protocol/
$(BUILD_DIR)/sddf_fs_protocol.o: FORCE
BUILD_DIR=$(abspath $(BUILD_DIR)) make -C $(SDDF_FS_PROTOCOL)

$(BUILD_DIR)/musllibc/lib/libc.a:
make -C $(MUSL) \
C_COMPILER=aarch64-none-elf-gcc \
TOOLPREFIX=aarch64-none-elf- \
CONFIG_ARCH_AARCH64=y \
STAGE_DIR=$(abspath $(BUILD_DIR)/musllibc) \
SOURCE_DIR=.

$(BUILD_DIR)/libnfs/lib/libnfs.a: $(BUILD_DIR)/musllibc/lib/libc.a
MUSL=$(abspath $(BUILD_DIR)/musllibc) cmake -S ../../libnfs -B $(BUILD_DIR)/libnfs
cmake --build $(BUILD_DIR)/libnfs

$(BUILD_DIR)/nfs/nfs.a: FORCE $(BUILD_DIR)/musllibc/lib/libc.a
make -C $(NFS) \
BUILD_DIR=$(abspath $(BUILD_DIR)/nfs) \
MICROKIT_INCLUDE=$(BOARD_DIR)/include \
MUSLLIBC_INCLUDE=$(abspath $(BUILD_DIR)/musllibc/include) \
LIBNFS_INCLUDE=$(abspath ../..//libnfs/include)

$(BUILD_DIR)/nfs.elf: $(BUILD_DIR)/nfs/nfs.a $(BUILD_DIR)/sddf_network_sharedringbuffer.o $(BUILD_DIR)/sddf_timer_client.o $(BUILD_DIR)/sddf_fs_protocol.o $(BUILD_DIR)/libnfs/lib/libnfs.a $(BUILD_DIR)/musllibc/lib/libc.a
$(LD) \
$(LDFLAGS) \
$(BUILD_DIR)/nfs/nfs.a \
$(BUILD_DIR)/sddf_network_sharedringbuffer.o \
$(BUILD_DIR)/sddf_timer_client.o \
$(BUILD_DIR)/sddf_fs_protocol.o \
-L$(BUILD_DIR)/libnfs/lib \
-L$(BUILD_DIR)/musllibc/lib \
-L$(LIBGCC) \
-lgcc \
-lc \
$(LIBS) \
-lnfs \
-o $(BUILD_DIR)/nfs.elf

$(BUILD_DIR)/ethernet.elf: $(BUILD_DIR)/meson_ethernet.o $(BUILD_DIR)/sddf_network_sharedringbuffer.o
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@

NETWORK_COMPONENTS := $(SDDF)/network/components
NETWORK_COMPONENTS_INCLUDE := \
-I$(SDDF)/include \
-I$(SDDF)/util/include \
-I$(BOARD_DIR)/include \
-I$(LWIP)/include \
-I$(LWIP)/include/ipv4
NETWORK_COMPONENT_CFLAGS := \
$(NETWORK_COMPONENTS_INCLUDE) \
-mstrict-align \
-ffreestanding \
-g \
-O0 \
-Wall \
-Wno-unused-function \
-DNO_ASSERT \
-DBOARD_$(MICROKIT_BOARD) \
-MD \
-MP

NETWORK_COMPONENTS_LDFLAGS := -L$(BOARD_DIR)/lib -L$(SDDF)/lib -L$(LIBGCC)
NETWORK_COMPONENTS_LIBS := -lmicrokit -Tmicrokit.ld -lc -lgcc

$(BUILD_DIR)/copy.o: $(NETWORK_COMPONENTS)/copy.c
aarch64-none-elf-gcc -c $(NETWORK_COMPONENT_CFLAGS) $< -o $@

$(BUILD_DIR)/mux_rx.o: $(NETWORK_COMPONENTS)/mux_rx.c
aarch64-none-elf-gcc -c $(NETWORK_COMPONENT_CFLAGS) $< -o $@

$(BUILD_DIR)/mux_tx.o: $(NETWORK_COMPONENTS)/mux_tx.c
aarch64-none-elf-gcc -c $(NETWORK_COMPONENT_CFLAGS) $< -o $@

$(BUILD_DIR)/arp.o: $(NETWORK_COMPONENTS)/arp.c
aarch64-none-elf-gcc -c $(NETWORK_COMPONENT_CFLAGS) $< -o $@

$(BUILD_DIR)/copy.elf: $(BUILD_DIR)/copy.o $(BUILD_DIR)/sddf_network_sharedringbuffer.o
aarch64-none-elf-ld $(NETWORK_COMPONENTS_LDFLAGS) $(BUILD_DIR)/sddf_network_sharedringbuffer.o $(BUILD_DIR)/copy.o $(NETWORK_COMPONENTS_LIBS) -o $(BUILD_DIR)/copy.elf

$(BUILD_DIR)/mux_rx.elf: $(BUILD_DIR)/mux_rx.o $(BUILD_DIR)/sddf_network_sharedringbuffer.o
aarch64-none-elf-ld $(NETWORK_COMPONENTS_LDFLAGS) $(BUILD_DIR)/sddf_network_sharedringbuffer.o $(BUILD_DIR)/mux_rx.o $(NETWORK_COMPONENTS_LIBS) -o $(BUILD_DIR)/mux_rx.elf

$(BUILD_DIR)/mux_tx.elf: $(BUILD_DIR)/mux_tx.o $(BUILD_DIR)/sddf_network_sharedringbuffer.o
aarch64-none-elf-ld $(NETWORK_COMPONENTS_LDFLAGS) $(BUILD_DIR)/sddf_network_sharedringbuffer.o $(BUILD_DIR)/mux_tx.o $(NETWORK_COMPONENTS_LIBS) -o $(BUILD_DIR)/mux_tx.elf

$(BUILD_DIR)/arp.elf: $(BUILD_DIR)/arp.o $(BUILD_DIR)/sddf_network_sharedringbuffer.o $(BUILD_DIR)/nfs/nfs.a
aarch64-none-elf-ld $(NETWORK_COMPONENTS_LDFLAGS) $(BUILD_DIR)/sddf_network_sharedringbuffer.o $(BUILD_DIR)/arp.o $(BUILD_DIR)/nfs/lwip/core/inet_chksum.o $(BUILD_DIR)/nfs/lwip/core/def.o $(NETWORK_COMPONENTS_LIBS) -o $(BUILD_DIR)/arp.elf

directories:
$(info $(shell mkdir -p $(BUILD_DIR)/lwip/src)) \
$(info $(shell mkdir -p $(BUILD_DIR)/lwip/src/core)) \
$(info $(shell mkdir -p $(BUILD_DIR)/lwip/src/netif)) \
$(info $(shell mkdir -p $(BUILD_DIR)/lwip/src/core/ipv4)) \
$(info $(shell mkdir -p $(BUILD_DIR)/nfs))

$(IMAGE_FILE) $(REPORT_FILE): $(addprefix $(BUILD_DIR)/, $(IMAGES)) kitty.system
$(MICROKIT_TOOL) kitty.system --search-path $(BUILD_DIR) --board $(MICROKIT_BOARD) --config $(MICROKIT_CONFIG) -o $(IMAGE_FILE) -r $(REPORT_FILE)

FORCE: ;
Loading

0 comments on commit 633280d

Please sign in to comment.