From 4f54bd34382bb6313c1faaf5503b8bfb1e684019 Mon Sep 17 00:00:00 2001 From: Jakub Michalski Date: Thu, 1 Feb 2024 12:38:28 +0100 Subject: [PATCH] Persistent shared dirs --- .github/workflows/release.yml | 30 +++++++++++++++++++ action/device/hifive_unleashed/init.resc | 5 +++- action/images.py | 6 +++- action/run-in-renode.py | 16 +++++++++- action/tasks/chroot.yml | 1 + action/tasks/save_shared_dirs.yml | 18 +++++++++++ .../linux/0001-linux-dts-patches.patch | 8 ++++- 7 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 action/tasks/save_shared_dirs.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1d519e9..8c9b4dd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -144,6 +144,36 @@ jobs: git+https://github.com/antmicro/tuttest.git@c44309e0365c54759fb36864fb77bf8b347bd647 repos: https://github.com/antmicro/pyrav4l2.git pyrav4l2 + riscv64-shared-dirs-test: + runs-on: ubuntu-latest + needs: send-to-releases + if: ${{ !failure() && !github.event.act }} + steps: + - uses: actions/checkout@v3 + + - name: prepare dir + run: mkdir shared_dir + + - name: test + uses: ./ + with: + shared-dirs: | + tests + shared_dir /home/shared_dir + renode-run: | + echo "riscv64-shared-dirs-test" > f.txt + echo "riscv64-shared-dirs-test2" > shared_dir/f.txt + - name: read + run: | + # ls ./shared + # cat shared/test.txt + ls shared_dir + echo "sep" + ls ./rootfs/home/shared_dir + ls ./rootfs/home + cat ./rootfs/home/test.txt + cat ./rootfs/home/f.txt + arm32-test: runs-on: ubuntu-latest needs: send-to-releases diff --git a/action/device/hifive_unleashed/init.resc b/action/device/hifive_unleashed/init.resc index 94a77cf..0a380d1 100644 --- a/action/device/hifive_unleashed/init.resc +++ b/action/device/hifive_unleashed/init.resc @@ -6,7 +6,10 @@ machine LoadPlatformDescription @action/device/hifive_unleashed/platform.repl # rootfs machine LoadPlatformDescriptionFromString 'virtio: Storage.VirtIOBlockDevice @ sysbus 0x100d0000 { IRQ -> plic@50 }' -virtio LoadImage @images/rootfs.img +virtio LoadImage @images/rootfs.img true + +machine LoadPlatformDescriptionFromString 'virtio2: Storage.VirtIOBlockDevice @ sysbus 0x100e0000 { IRQ -> plic@51 }' +virtio2 LoadImage @images/persistent.img true showAnalyzer uart0 e51 LogFunctionNames true diff --git a/action/images.py b/action/images.py index 85a3faa..63dcc05 100644 --- a/action/images.py +++ b/action/images.py @@ -193,12 +193,16 @@ def burn_rootfs_image( if not os.path.islink(fp): size += os.path.getsize(fp) - image_size = f'{max(size * 2, 5 * 10**7)}' + image_size = f'{max(size * 2, 5 * 10**7)*2}' try: run(["truncate", "images/rootfs.img", "-s", image_size], check=True) run(["mkfs.ext4", "-d", "images/rootfs", "images/rootfs.img"], check=True, stdout=DEVNULL) + run(["truncate", "images/persistent.img", "-s", "128MB"], check=True) + run(["mkfs.ext4", "images/persistent.img"], + check=True, + stdout=DEVNULL) except CalledProcessError as e: sys.exit(e.returncode) diff --git a/action/run-in-renode.py b/action/run-in-renode.py index b0e0a8d..f571dda 100644 --- a/action/run-in-renode.py +++ b/action/run-in-renode.py @@ -16,14 +16,16 @@ from common import get_file, error, archs from devices import add_devices from dependencies import add_repos, add_packages -from images import prepare_shared_directories, prepare_kernel_and_initramfs, burn_rootfs_image +from images import prepare_shared_directories, prepare_kernel_and_initramfs, burn_rootfs_image, shared_directories_actions from dispatcher import CommandDispatcher +from subprocess import run from datetime import datetime import sys import json import yaml +import shutil DEFAULT_IMAGE_PATH = "https://github.com/{}/releases/download/{}/image-{}-default.tar.xz" @@ -146,3 +148,15 @@ def test_task(test_task_str: str): dispatcher.add_task(test_task(args.get("renode-run", ""))) dispatcher.evaluate() + + run(["mkdir", "shared"], check=True) + run(["sudo", "mount", "images/persistent.img", "shared"], check=True) + run(["mkdir", "rootfs"], check=True) + run(["sudo", "mount", "images/rootfs.img", "rootfs"], check=True) + + for dir in shared_directories_actions: + shutil.copytree( + f"images/rootfs/{dir.target}", + f"{user_directory}/{dir.host}" if not dir.host.startswith('/') else dir.host, + dirs_exist_ok=True + ) \ No newline at end of file diff --git a/action/tasks/chroot.yml b/action/tasks/chroot.yml index c4d6395..331e007 100644 --- a/action/tasks/chroot.yml +++ b/action/tasks/chroot.yml @@ -6,6 +6,7 @@ timeout: 5 fail-fast: true commands: - mount /dev/vda /mnt + # - echo "test" > /mnt/home/t.txt - cd /mnt - mount -t proc /proc proc/ - mount -t sysfs /sys sys/ diff --git a/action/tasks/save_shared_dirs.yml b/action/tasks/save_shared_dirs.yml new file mode 100644 index 0000000..6919538 --- /dev/null +++ b/action/tasks/save_shared_dirs.yml @@ -0,0 +1,18 @@ +name: save_shared_dirs +shell: target +requires: [action_test] +echo: true +timeout: 5 +fail-fast: false +check-exit-code: false +commands: + # - echo "TEST" + # - mkdir -p host_dir + # - mount /dev/vdb host_dir + # - ls host_dir + # - echo "file from Renode" > host_dir/test.txt + # - umount host_dir + - pwd + - echo "second file" > test.txt + - ls + - umount /dev/vda \ No newline at end of file diff --git a/kernel/riscv64-hifive_unleashed/patches/linux/0001-linux-dts-patches.patch b/kernel/riscv64-hifive_unleashed/patches/linux/0001-linux-dts-patches.patch index d151de9..f63e979 100644 --- a/kernel/riscv64-hifive_unleashed/patches/linux/0001-linux-dts-patches.patch +++ b/kernel/riscv64-hifive_unleashed/patches/linux/0001-linux-dts-patches.patch @@ -15,7 +15,7 @@ diff --git a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts b/arch/riscv/bo index dddabfbbc7a9..15e528335102 100644 --- a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts +++ b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts -@@ -29,6 +29,12 @@ memory@80000000 { +@@ -29,6 +29,18 @@ memory@80000000 { }; soc { @@ -24,6 +24,12 @@ index dddabfbbc7a9..15e528335102 100644 + reg = <0x00 0x100d0000 0x00 0x150>; + interrupt-parent = <&plic0>; + interrupts = <50>; ++ }; ++ virtio@100e0000 { ++ compatible = "virtio,mmio"; ++ reg = <0x00 0x100e0000 0x00 0x150>; ++ interrupt-parent = <&plic0>; ++ interrupts = <51>; + }; };