Skip to content

Commit

Permalink
Persistent shared dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
jmichalski-ant committed Feb 5, 2024
1 parent fb10cdc commit 4af18cd
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 14 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,65 @@ 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 shared directiories
run: mkdir shared_dir shared_dir2

- name: test
uses: ./
with:
rootfs-size: +128M
shared-dirs: |
shared_dir /home/shared_dir
shared_dir2 /home/shared_dir2
renode-run: |
echo "shared-dirs-test" > shared_dir/f.txt
echo "shared-dirs-test2" > shared_dir2/f.txt
- name: read shared directories
run: |
ls shared_dir
cat shared_dir/f.txt
ls shared_dir2
cat shared_dir2/f.txt
arm32-shared-dirs-test:
runs-on: ubuntu-latest
needs: send-to-releases
if: ${{ !failure() && !github.event.act }}
steps:
- uses: actions/checkout@v3

- name: prepare shared directiories
run: mkdir shared_dir shared_dir2

- name: test
uses: ./
with:
arch: arm32
rootfs-size: +128M
shared-dirs: |
shared_dir /home/shared_dir
shared_dir2 /home/shared_dir2
renode-run: |
echo "shared-dirs-test" > shared_dir/f.txt
echo "shared-dirs-test2" > shared_dir2/f.txt
ls shared_dir
ls shared_dir2
- name: read shared directories
run: |
ls shared_dir
cat shared_dir/f.txt
ls shared_dir2
cat shared_dir2/f.txt
arm32-test:
runs-on: ubuntu-latest
needs: send-to-releases
Expand Down
5 changes: 4 additions & 1 deletion action/device/hifive_unleashed/init.resc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 34 additions & 11 deletions action/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,35 @@ def prepare_kernel_and_initramfs(kernel: str):
if not os.path.exists("images/Image") and not os.path.exists("images/vmlinux"):
error("Kernel not found! Action expects Image or vmlinux file.")

def rootfs_size(size_str: str) -> int:
"""
Returns rootfs size
Parameters
----------
size_str: str
rootfs-size action parameter value
"""

units = {
"B": 1,
"K": 1024,
"M": 1024**2,
"G": 1024**3
}

if size_str == "auto" or size_str.startswith("+"):
size = 0
for path, _, files in os.walk("images/rootfs"):
for f in files:
fp = os.path.join(path, f)
if not os.path.islink(fp):
size += os.path.getsize(fp)

additional_size = int(size_str[:-1]) * units[size_str[-1]] if size_str.startswith("+") and size_str[-1] in units else 0
print(f"additional_size: {additional_size}")
return max(size * 2, 5 * 10**7) + additional_size
return int(size_str)

def burn_rootfs_image(
user_directory: str,
Expand Down Expand Up @@ -185,20 +214,14 @@ def burn_rootfs_image(
dirs_exist_ok=True
)

if image_size == "auto":
size = 0
for path, _, files in os.walk("images/rootfs"):
for f in files:
fp = os.path.join(path, f)
if not os.path.islink(fp):
size += os.path.getsize(fp)

image_size = f'{max(size * 2, 5 * 10**7)}'
try:

run(["truncate", "images/rootfs.img", "-s", image_size], check=True)
run(["truncate", "images/rootfs.img", "-s", f"{rootfs_size(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)
16 changes: 15 additions & 1 deletion action/run-in-renode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
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
import os


DEFAULT_IMAGE_PATH = "https://github.com/{}/releases/download/{}/image-{}-default.tar.xz"
Expand Down Expand Up @@ -146,3 +149,14 @@ 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:
src = f"rootfs/{dir.target}"
dst = f"{user_directory}/{dir.host}" if not dir.host.startswith('/') else dir.host
if os.path.exists(src):
shutil.copytree(src, dst, dirs_exist_ok=True)
8 changes: 8 additions & 0 deletions action/tasks/save_shared_dirs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: save_shared_dirs
shell: target
requires: [action_test]
echo: true
timeout: 5
fail-fast: false
commands:
- umount /dev/vda
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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>;
+ };
};

Expand Down

0 comments on commit 4af18cd

Please sign in to comment.