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

[pull] master from firesim:master #7

Merged
merged 14 commits into from
Feb 19, 2024
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ wlutil/_command.sh
*__pycache__
.doit.db*
marshal-config.yaml
boards/default/distros/ubuntu/rootfs.img*
.ropeproject
*~
*#
*#
2 changes: 2 additions & 0 deletions boards/chipyard/base-workloads/br-base/linux-config
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ CONFIG_RISCV_ROCC=y
CONFIG_STACKPROTECTOR_PER_TASK=y
CONFIG_TOOLCHAIN_HAS_ZICBOM=y
CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE=y
CONFIG_OVERRIDE_RNG_ENTROPY=y
CONFIG_OVERRIDE_RNG_ENTROPY_VALUE=256

14 changes: 14 additions & 0 deletions boards/default/distros/ubuntu/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
RAWURL=https://cdimage.ubuntu.com/releases/20.04.5/release/ubuntu-20.04.5-preinstalled-server-riscv64+unmatched.img.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=235554

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

clean:
rm -f $(COMPIMG) $(RAWIMG) $(NEWIMG)
1 change: 1 addition & 0 deletions boards/default/distros/ubuntu/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .ubuntu import * # NOQA
1 change: 1 addition & 0 deletions boards/default/distros/ubuntu/overlay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
etc/systemd/system/firesim.service
2 changes: 2 additions & 0 deletions boards/default/distros/ubuntu/overlay/etc/firesim/.gitignore
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/ubuntu/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/ubuntu/resize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# Usage: ./resize.sh UBUNTU_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
110 changes: 110 additions & 0 deletions boards/default/distros/ubuntu/ubuntu.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)
ubuntu_dir = pathlib.Path(__file__).resolve().parent

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


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


# Ubuntu 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': 'ubuntu-base',
'isDistro': True,
'distro': {
'name': 'ubuntu',
'opts': {}
},
'workdir': ubuntu_dir,
'builder': self,
'img': ubuntu_dir / "rootfs.img"
}

def buildBaseImage(self, task, changed):
wlutil.run(['make', "rootfs.img"], cwd=ubuntu_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=ubuntu_dir)
if retcode == 0:
return True
else:
return False
return [(checkMake, ())]

def generateBootScriptOverlay(self, script, args):
# How this works:
# The ubuntu 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
2 changes: 1 addition & 1 deletion boards/default/linux
2 changes: 2 additions & 0 deletions boards/firechip/base-workloads/br-base/linux-config
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ CONFIG_STACKPROTECTOR_PER_TASK=y
CONFIG_TOOLCHAIN_HAS_ZICBOM=y
CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE=y
# CONFIG_RISCV_PMU is not set
CONFIG_OVERRIDE_RNG_ENTROPY=y
CONFIG_OVERRIDE_RNG_ENTROPY_VALUE=256

4 changes: 3 additions & 1 deletion boards/firechip/base-workloads/fedora-base/linux-config
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ CONFIG_INITRAMFS_COMPRESSION_NONE=y
CONFIG_INITRAMFS_ROOT_GID=0
CONFIG_INITRAMFS_ROOT_UID=0
CONFIG_RISCV_DMA_NONCOHERENT=y
CONFIG_RISCV_ISA_ZICBOM=y
CONFIG_RISCV_ISA_ZICBOM=0
CONFIG_RISCV_ROCC=y
CONFIG_STACKPROTECTOR_PER_TASK=y
CONFIG_TOOLCHAIN_HAS_ZICBOM=y
CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE=y
CONFIG_OVERRIDE_RNG_ENTROPY=y
CONFIG_OVERRIDE_RNG_ENTROPY_VALUE=256

21 changes: 21 additions & 0 deletions boards/firechip/base-workloads/ubuntu-base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name" : "ubuntu-base",
"guest-init": "initRepos.sh",
"rootfs-size": "8GB",
"distro" : {
"name" : "ubuntu",
"opts" : {}
},
"overlay" : "overlay",
"linux" : {
"source" : "../../linux",
"config" : "linux-config",
"modules" : {
"icenet" : "../../drivers/icenet-driver",
"iceblk" : "../../drivers/iceblk-driver"
}
},
"firmware" : {
"opensbi-src" : "../../firmware/opensbi"
}
}
5 changes: 5 additions & 0 deletions boards/firechip/base-workloads/ubuntu-base/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Ubuntu 20.04 support in Firesim

First time setup notes:
- When running "./marshal build ubuntu-base.json" for the first time, the process MAY end in a login prompt for Ubuntu. Login with "root:firesim", and upon login, exit Qemu with CTRL-A+X
- Login with "root:firesim" when launching with Firemarshal/Firesim
3 changes: 3 additions & 0 deletions boards/firechip/base-workloads/ubuntu-base/initRepos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
dnf makecache
poweroff
65 changes: 65 additions & 0 deletions boards/firechip/base-workloads/ubuntu-base/linux-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
CONFIG_AS_VERSION=23900
# CONFIG_ATA is not set
# CONFIG_BACKLIGHT_CLASS_DEVICE is not set
CONFIG_CMDLINE="console=ttyS0 console=ttySIF0,3686400 earlycon"
CONFIG_DEBUG_SECTION_MISMATCH=y
CONFIG_DEFAULT_HOSTNAME="ucb"
# CONFIG_DRM is not set
CONFIG_EXT2_FS=y
# CONFIG_FB is not set
# CONFIG_HID_GENERIC is not set
# CONFIG_HWMON is not set
# CONFIG_I2C_ALGOBIT is not set
# CONFIG_I2C_COMPAT is not set
# CONFIG_I2C_HELPER_AUTO is not set
# CONFIG_INPUT_MOUSE is not set
# CONFIG_INPUT_MOUSEDEV is not set
CONFIG_LD_VERSION=23900
# CONFIG_MMC is not set
CONFIG_NR_CPUS=32
# CONFIG_NVMEM_SYSFS is not set
# CONFIG_PCI is not set
# CONFIG_POWER_SUPPLY is not set
# CONFIG_SCSI is not set
CONFIG_SERIAL_SIFIVE=y
# CONFIG_SOC_SIFIVE is not set
# CONFIG_SPI is not set
# CONFIG_USB_SUPPORT is not set
# CONFIG_VHOST_MENU is not set
CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
CONFIG_ARCH_HAS_DMA_PREP_COHERENT=y
CONFIG_ARCH_HAS_SETUP_DMA_OPS=y
CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU=y
CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE=y
CONFIG_AS_HAS_INSN=y
CONFIG_CC_HAVE_STACKPROTECTOR_TLS=y
# CONFIG_CMDLINE_EXTEND is not set
# CONFIG_CMDLINE_FALLBACK is not set
CONFIG_CMDLINE_FORCE=y
CONFIG_DMA_COHERENT_POOL=y
CONFIG_DMA_DIRECT_REMAP=y
CONFIG_DMA_NONCOHERENT_MMAP=y
# CONFIG_EXT2_FS_XATTR is not set
CONFIG_FONT_AUTOSELECT=y
# CONFIG_I2C_ALGOPCA is not set
# CONFIG_I2C_ALGOPCF is not set
# CONFIG_I2C_SMBUS is not set
# CONFIG_INITRAMFS_COMPRESSION_BZIP2 is not set
# CONFIG_INITRAMFS_COMPRESSION_GZIP is not set
# CONFIG_INITRAMFS_COMPRESSION_LZ4 is not set
# CONFIG_INITRAMFS_COMPRESSION_LZMA is not set
# CONFIG_INITRAMFS_COMPRESSION_LZO is not set
CONFIG_INITRAMFS_COMPRESSION_NONE=y
# CONFIG_INITRAMFS_COMPRESSION_XZ is not set
# CONFIG_INITRAMFS_COMPRESSION_ZSTD is not set
# CONFIG_INITRAMFS_FORCE is not set
CONFIG_INITRAMFS_ROOT_GID=0
CONFIG_INITRAMFS_ROOT_UID=0
CONFIG_RISCV_DMA_NONCOHERENT=y
CONFIG_RISCV_ISA_ZICBOM=0
CONFIG_RISCV_ROCC=y
CONFIG_STACKPROTECTOR_PER_TASK=y
CONFIG_TOOLCHAIN_HAS_ZICBOM=y
CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE=y
CONFIG_BLK_DEV_DM=y
CONFIG_DM_MULTIPATH=y
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
network:
ethernets:
zz-all-en:
dhcp4: true
match:
name: en*
optional: true
zz-all-eth:
dhcp4: true
match:
name: eth*
optional: true
version: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
network:
ethernets:
zz-all-en:
match:
name:
en*
addresses: [172.16.52.86/24]
dhcp4: false
gateway4: [172.16.1.1]
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
zz-all-eth:
match:
name:
eth*
addresses: [172.16.52.86/24]
dhcp4: false
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
version: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

#mac=$(ifconfig | grep -o "..:..:..:..:..:..")
mac=$(cat /sys/class/net/eth0/address)
macpref=$(echo $mac | cut -c 1-8 -)
echo "mac prefix:"
echo $macpref
case "$macpref" in
"00:12:6d")
echo "this looks like FireSim. starting network"
machigh=$(echo $mac | cut -c 13-14 -)
maclow=$(echo $mac | cut -c 16-17 -)
# python3 ip.py /etc/firesim/50-cloud-init-static.yaml $((16#$machigh)) $((16#$maclow))
cp /etc/firesim/50-cloud-init-static.yaml /etc/netplan/50-cloud-init.yaml
#echo IPADDR=172.16.$((16#$machigh)).$((16#$maclow)) >> /etc/sysconfig/network-scripts/ifcfg-eth0
;;
"52:54:00")
echo "this looks like not FireSim. exiting"
cp /etc/firesim/50-cloud-init-dhcp.yaml /etc/netplan/50-cloud-init.yaml
;;
esac
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ubuntu on Firesim
26 changes: 26 additions & 0 deletions boards/firechip/base-workloads/ubuntu-base/overlay/etc/shadow
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
root:$6$soQup5SHA01WBVl8$Ky6UdkSnYBXuW7HEbz0YPWy1/TwU.5BTq.zxrwJbL/su81Q7hCDSOFvMawnYoroWxqqHglPDbm0pUT15E/jWo.:17869:0:99999:7:::
bin:*:17725:0:99999:7:::
daemon:*:17725:0:99999:7:::
adm:*:17725:0:99999:7:::
lp:*:17725:0:99999:7:::
sync:*:17725:0:99999:7:::
shutdown:*:17725:0:99999:7:::
halt:*:17725:0:99999:7:::
mail:*:17725:0:99999:7:::
operator:*:17725:0:99999:7:::
games:*:17725:0:99999:7:::
ftp:*:17725:0:99999:7:::
nobody:*:17725:0:99999:7:::
dbus:!!:17819::::::
systemd-coredump:!!:17819::::::
systemd-network:!!:17819::::::
systemd-resolve:!!:17819::::::
tss:!!:17819::::::
polkitd:!!:17819::::::
rpc:!!:17819:0:99999:7:::
geoclue:!!:17819::::::
kojibuilder:!!:17819::::::
rpcuser:!!:17819::::::
chrony:!!:17819::::::
sshd:!!:17819::::::
pesign:!!:17819::::::
Loading
Loading