Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fedoradev-base.json #247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions boards/default/distros/fedoradev/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootfs.img
rootfs.img.xz
15 changes: 15 additions & 0 deletions boards/default/distros/fedoradev/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
RAWURL=http://fedora.riscv.rocks/kojifiles/work/tasks/944/320944/Fedora-Developer-Rawhide-20200108.n.0-sda.raw.xz
COMPIMG=rootfs.img.xz
NEWIMG=rootfs.img

# Extract root partition without partition table
# NOTE: Offset must be adjusted for different base image
$(NEWIMG): $(COMPIMG)
xzcat -k $(COMPIMG) | dd of=$(NEWIMG) bs=512 skip=1007616

$(COMPIMG):
curl $(RAWURL) -o $(COMPIMG)

clean:
rm -f $(COMPIMG) $(RAWIMG) $(NEWIMG)

1 change: 1 addition & 0 deletions boards/default/distros/fedoradev/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .fedoradev import * # NOQA
110 changes: 110 additions & 0 deletions boards/default/distros/fedoradev/fedoradev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import subprocess as sp
import shutil
import pathlib
import wlutil
import re

serviceTemplate = """[Unit]
Requires=multi-user.target
After=multi-user.target
Before=firesim.target
Wants=firesim.target

[Service]
ExecStart=/etc/firesim/{scriptName} {scriptArgs}
StandardOutput=journal+console"""

# Some common directories for this module (all absolute paths)
feddev_dir = pathlib.Path(__file__).resolve().parent

# Temporary overlay used for applying init scripts
overlay = feddev_dir / 'overlay'


# Fedora doesn't support any options
def hashOpts(opts):
return None


# Fedora doesn't support any options
def mergeOpts(base, new):
return base


def initOpts(cfg):
return


class Builder:
def __init__(self, opts):
return

def getWorkload(self):
return {
'name': 'fedoradev-base',
'isDistro': True,
'distro': {
'name': 'fedoradev',
'opts': {}
},
'workdir': feddev_dir,
'builder': self,
'img': feddev_dir / "rootfs.img"
}

def buildBaseImage(self):
wlutil.run(['make', "rootfs.img"], cwd=feddev_dir)

def fileDeps(self):
return []

# Return True if the base image is up to date, or False if it needs to be
# rebuilt.
def upToDate(self):
def checkMake():
retcode = sp.call('make -q rootfs.img', shell=True, cwd=feddev_dir)
if retcode == 0:
return True
else:
return False
return [(checkMake, ())]

def generateBootScriptOverlay(self, script, args):
# How this works:
# The fedora repo has a pre-built overlay with all the systemd paths
# filled in and a custom boot target (firesim.target) that loads a
# custom service (firesim.service) that runs a script (/init.sh). We
# can change the default boot behavior by changing this script.
scriptDst = overlay / 'etc/firesim/firesim.sh'
if script is not None:
print("applying script: " + str(scriptDst))
shutil.copy(script, scriptDst)
else:
scriptDst.unlink()
# Create a blank init script because overlays won't let us delete stuff
# Alternatively: we could consider replacing the default.target
# symlink to disable the firesim target entirely
scriptDst.touch()

scriptDst.chmod(0o755)

# Create the service script
if args is None:
serviceScript = serviceTemplate.format(scriptName='firesim.sh', scriptArgs='')
else:
serviceScript = serviceTemplate.format(scriptName='firesim.sh', scriptArgs=' '.join(args))

with open(overlay / 'etc/systemd/system/firesim.service', 'w') as f:
f.write(serviceScript)

return overlay

def stripUart(self, lines):
stripped = []
pat = re.compile(r".*firesim.sh\[\d*\]: (.*\n)")
for line in lines:
match = pat.match(line)
if match:
stripped.append(match.group(1))

return stripped
1 change: 1 addition & 0 deletions boards/default/distros/fedoradev/overlay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
etc/systemd/system/firesim.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is auto-generated by the build system
firesim.sh
1 change: 1 addition & 0 deletions boards/default/distros/fedoradev/overlay/etc/fstab
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LABEL=_/ / ext4 defaults,noatime,x-systemd.device-timeout=300s,x-systemd.mount-timeout=300s 0 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Unit]
Requires=multi-user.target
After=multi-user.target
AllowIsolate=yes
15 changes: 15 additions & 0 deletions boards/default/distros/fedoradev/resize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# Usage: ./resize.sh FEDORA_IMAGE NEW_SIZE_IN_BYTES

IMG=$1
NEWSZ=$(numfmt --from=iec $2)
REALSZ=$(du --apparent-size -b $IMG | cut -f1)

if [ $NEWSZ -le $REALSZ ]; then
echo "Target size smaller than current size (shrinking images not currently supported)"
exit
fi

truncate -s $NEWSZ $IMG
e2fsck -f $IMG
resize2fs $IMG
22 changes: 22 additions & 0 deletions boards/firechip/base-workloads/fedoradev-base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "fedoradev-base",
"guest-init": "initRepos.sh",
"distro": {
"name": "fedoradev",
"opts": {}
},
"overlay": "overlay",
"linux": {
"source": "../../linux",
"config": "linux-config",
"modules": {
"icenet": "../../drivers/icenet-driver",
"iceblk": "../../drivers/iceblk-driver"
}
},
"firmware": {
"use-bbl": false,
"bbl-src": "../../firmware/riscv-pk",
"opensbi-src": "../../firmware/opensbi"
}
}
3 changes: 3 additions & 0 deletions boards/firechip/base-workloads/fedoradev-base/initRepos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
dnf makecache
poweroff
Loading