Skip to content

Commit 3af2ba5

Browse files
Persistent shared dirs
1 parent fb10cdc commit 3af2ba5

File tree

6 files changed

+129
-14
lines changed

6 files changed

+129
-14
lines changed

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,57 @@ jobs:
144144
git+https://github.com/antmicro/tuttest.git@c44309e0365c54759fb36864fb77bf8b347bd647
145145
repos: https://github.com/antmicro/pyrav4l2.git pyrav4l2
146146

147+
riscv64-shared-dirs-test:
148+
runs-on: ubuntu-latest
149+
needs: send-to-releases
150+
if: ${{ !failure() && !github.event.act }}
151+
steps:
152+
- uses: actions/checkout@v3
153+
154+
- name: test
155+
uses: ./
156+
with:
157+
rootfs-size: +128M
158+
shared-dirs: |
159+
shared_dir /home/shared_dir
160+
shared_dir2 /home/shared_dir2
161+
renode-run: |
162+
echo "shared-dirs-test" > shared_dir/f.txt
163+
echo "shared-dirs-test2" > shared_dir2/f.txt
164+
165+
- name: read shared_dirs
166+
run: |
167+
ls shared_dir
168+
cat shared_dir/f.txt
169+
ls shared_dir2
170+
cat shared_dir2/f.txt
171+
172+
arm32-shared-dirs-test:
173+
runs-on: ubuntu-latest
174+
needs: send-to-releases
175+
if: ${{ !failure() && !github.event.act }}
176+
steps:
177+
- uses: actions/checkout@v3
178+
179+
- name: test
180+
uses: ./
181+
with:
182+
arch: arm32
183+
rootfs-size: +128M
184+
shared-dirs: |
185+
shared_dir /home/shared_dir
186+
shared_dir2 /home/shared_dir2
187+
renode-run: |
188+
echo "shared-dirs-test" > shared_dir/f.txt
189+
echo "shared-dirs-test2" > shared_dir2/f.txt
190+
191+
- name: read shared_dirs
192+
run: |
193+
ls shared_dir
194+
cat shared_dir/f.txt
195+
ls shared_dir2
196+
cat shared_dir2/f.txt
197+
147198
arm32-test:
148199
runs-on: ubuntu-latest
149200
needs: send-to-releases

action/device/hifive_unleashed/init.resc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ machine LoadPlatformDescription @action/device/hifive_unleashed/platform.repl
66

77
# rootfs
88
machine LoadPlatformDescriptionFromString 'virtio: Storage.VirtIOBlockDevice @ sysbus 0x100d0000 { IRQ -> plic@50 }'
9-
virtio LoadImage @images/rootfs.img
9+
virtio LoadImage @images/rootfs.img true
10+
11+
# machine LoadPlatformDescriptionFromString 'virtio2: Storage.VirtIOBlockDevice @ sysbus 0x100e0000 { IRQ -> plic@51 }'
12+
# virtio2 LoadImage @images/persistent.img true
1013

1114
showAnalyzer uart0
1215
e51 LogFunctionNames true

action/images.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,35 @@ def prepare_kernel_and_initramfs(kernel: str):
104104
if not os.path.exists("images/Image") and not os.path.exists("images/vmlinux"):
105105
error("Kernel not found! Action expects Image or vmlinux file.")
106106

107+
def rootfs_size(size_str: str) -> int:
108+
"""
109+
Returns rootfs size
110+
111+
Parameters
112+
----------
113+
size_str: str
114+
rootfs-size action parameter value
115+
"""
116+
117+
units = {
118+
"B": 1,
119+
"K": 1024,
120+
"M": 1024**2,
121+
"G": 1024**3
122+
}
123+
124+
if size_str == "auto" or size_str.startswith("+"):
125+
size = 0
126+
for path, _, files in os.walk("images/rootfs"):
127+
for f in files:
128+
fp = os.path.join(path, f)
129+
if not os.path.islink(fp):
130+
size += os.path.getsize(fp)
131+
132+
additional_size = int(size_str[:-1]) * units[size_str[-1]] if size_str.startswith("+") and size_str[-1] in units else 0
133+
print(f"additional_size: {additional_size}")
134+
return max(size * 2, 5 * 10**7) + additional_size
135+
return int(size_str)
107136

108137
def burn_rootfs_image(
109138
user_directory: str,
@@ -185,20 +214,14 @@ def burn_rootfs_image(
185214
dirs_exist_ok=True
186215
)
187216

188-
if image_size == "auto":
189-
size = 0
190-
for path, _, files in os.walk("images/rootfs"):
191-
for f in files:
192-
fp = os.path.join(path, f)
193-
if not os.path.islink(fp):
194-
size += os.path.getsize(fp)
195-
196-
image_size = f'{max(size * 2, 5 * 10**7)}'
197217
try:
198-
199-
run(["truncate", "images/rootfs.img", "-s", image_size], check=True)
218+
run(["truncate", "images/rootfs.img", "-s", f"{rootfs_size(image_size)}"], check=True)
200219
run(["mkfs.ext4", "-d", "images/rootfs", "images/rootfs.img"],
201220
check=True,
202221
stdout=DEVNULL)
222+
# run(["truncate", "images/persistent.img", "-s", "128MB"], check=True)
223+
# run(["mkfs.ext4", "images/persistent.img"],
224+
# check=True,
225+
# stdout=DEVNULL)
203226
except CalledProcessError as e:
204227
sys.exit(e.returncode)

action/run-in-renode.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616
from common import get_file, error, archs
1717
from devices import add_devices
1818
from dependencies import add_repos, add_packages
19-
from images import prepare_shared_directories, prepare_kernel_and_initramfs, burn_rootfs_image
19+
from images import prepare_shared_directories, prepare_kernel_and_initramfs, burn_rootfs_image, shared_directories_actions
2020
from dispatcher import CommandDispatcher
21+
from subprocess import run
2122

2223
from datetime import datetime
2324

2425
import sys
2526
import json
2627
import yaml
28+
import shutil
29+
import os
2730

2831

2932
DEFAULT_IMAGE_PATH = "https://github.com/{}/releases/download/{}/image-{}-default.tar.xz"
@@ -146,3 +149,14 @@ def test_task(test_task_str: str):
146149
dispatcher.add_task(test_task(args.get("renode-run", "")))
147150

148151
dispatcher.evaluate()
152+
153+
# run(["mkdir", "shared"], check=True)
154+
# run(["sudo", "mount", "images/persistent.img", "shared"], check=True)
155+
run(["mkdir", "rootfs"], check=True)
156+
run(["sudo", "mount", "images/rootfs.img", "rootfs"], check=True)
157+
158+
for dir in shared_directories_actions:
159+
src = f"rootfs/{dir.target}"
160+
dst = f"{user_directory}/{dir.host}" if not dir.host.startswith('/') else dir.host
161+
if os.path.exists(src):
162+
shutil.copytree(src, dst, dirs_exist_ok=True)

action/tasks/save_shared_dirs.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: save_shared_dirs
2+
shell: target
3+
requires: [action_test]
4+
echo: true
5+
timeout: 5
6+
fail-fast: false
7+
check-exit-code: false
8+
commands:
9+
# - echo "TEST"
10+
# - mkdir -p host_dir
11+
# - mount /dev/vdb host_dir
12+
# - ls host_dir
13+
# - echo "file from Renode" > host_dir/test.txt
14+
# - umount host_dir
15+
# - pwd
16+
# - echo "second file" > test.txt
17+
# - ls
18+
- umount /dev/vda

kernel/riscv64-hifive_unleashed/patches/linux/0001-linux-dts-patches.patch

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ diff --git a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts b/arch/riscv/bo
1515
index dddabfbbc7a9..15e528335102 100644
1616
--- a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts
1717
+++ b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts
18-
@@ -29,6 +29,12 @@ memory@80000000 {
18+
@@ -29,6 +29,18 @@ memory@80000000 {
1919
};
2020

2121
soc {
@@ -24,6 +24,12 @@ index dddabfbbc7a9..15e528335102 100644
2424
+ reg = <0x00 0x100d0000 0x00 0x150>;
2525
+ interrupt-parent = <&plic0>;
2626
+ interrupts = <50>;
27+
+ };
28+
+ virtio@100e0000 {
29+
+ compatible = "virtio,mmio";
30+
+ reg = <0x00 0x100e0000 0x00 0x150>;
31+
+ interrupt-parent = <&plic0>;
32+
+ interrupts = <51>;
2733
+ };
2834
};
2935

0 commit comments

Comments
 (0)