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

Add scripts to auto-configure Linux builds based on system configuration. #73

Merged
merged 4 commits into from
Jan 11, 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
18 changes: 11 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
run: nix-shell --run "make -C ../iob_soc_o* sim-run SIMULATOR=verilator"


cyclonev-baremetal:
cyclonev:
runs-on: self-hosted
timeout-minutes: 60
# run even if previous job failed
Expand All @@ -83,10 +83,12 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: cyclonev test
run: make fpga-run RUN_LINUX=0 INIT_MEM=0 BOARD=CYCLONEV-GT-DK
- name: test baremetal
run: make fpga-run RUN_LINUX=0 BOARD=CYCLONEV-GT-DK
# - name: test linux
# run: make fpga-linux-test RUN_LINUX=1 BOARD=CYCLONEV-GT-DK

aes-ku040-baremetal:
aes-ku040:
runs-on: self-hosted
timeout-minutes: 90
# run even if previous job failed
Expand All @@ -98,14 +100,16 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: ku040 test
run: make fpga-run RUN_LINUX=0 INIT_MEM=0 BOARD=AES-KU040-DB-G
- name: test baremetal
run: make fpga-run RUN_LINUX=0 BOARD=AES-KU040-DB-G
# - name: test linux
# run: make fpga-linux-test RUN_LINUX=1 BOARD=AES-KU040-DB-G

## doc:
## runs-on: self-hosted
## timeout-minutes: 60
## if: ${{ !cancelled() }}
## needs: [ cyclonev-baremetal, aes-ku040-baremetal ]
## needs: [ cyclonev, aes-ku040 ]
##
## steps:
## - uses: actions/checkout@v3
Expand Down
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ ifeq ($(INIT_MEM),1)
SETUP_ARGS += INIT_MEM
endif

ifeq ($(RUN_LINUX),1)
SETUP_ARGS += RUN_LINUX
endif

setup:
make build-setup SETUP_ARGS="$(SETUP_ARGS)"

Expand Down Expand Up @@ -51,10 +47,16 @@ fpga-test:
# IOb-SoC-Opencryptolinux always uses external memory
make clean setup fpga-run INIT_MEM=0

fpga-linux-test:
cat | make fpga-connect | tee test.log & program_pid=$$! && \
while true; do grep --quiet login: test.log && break; done && \
echo -e "root\nuname -a\n" > /proc/$$program_pid/fd/0 && \
sleep 10 && grep --quiet "Linux buildroot" test.log && echo Test passed! || echo Test failed!; kill $$program_pid

test-all:
make sim-test
make fpga-test BOARD=CYCLONEV-GT-DK
make fpga-test BOARD=AES-KU040-DB-G
make clean && make setup && make -C ../iob_soc_opencryptolinux_V*/ doc-test

.PHONY: sim-test fpga-test test-all
.PHONY: sim-test fpga-test fpga-linux-test test-all
Binary file added hardware/fpga/quartus/CYCLONEV-GT-DK/fw_jump.bin
Binary file not shown.
Binary file added hardware/fpga/quartus/CYCLONEV-GT-DK/iob_soc.dtb
Binary file not shown.
6 changes: 6 additions & 0 deletions hardware/fpga/quartus/CYCLONEV-GT-DK/linux_build_macros.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UART0_ADDR f2000000
ETH0_ADDR f4000000
CLINT0_ADDR f6000000
PLIC0_ADDR f8000000
FREQ 50000000
BAUD 115200
Binary file added hardware/fpga/vivado/AES-KU040-DB-G/fw_jump.bin
Binary file not shown.
Binary file added hardware/fpga/vivado/AES-KU040-DB-G/iob_soc.dtb
Binary file not shown.
6 changes: 6 additions & 0 deletions hardware/fpga/vivado/AES-KU040-DB-G/linux_build_macros.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UART0_ADDR f2000000
ETH0_ADDR f4000000
CLINT0_ADDR f6000000
PLIC0_ADDR f8000000
FREQ 100000000
BAUD 115200
Binary file added hardware/simulation/fw_jump.bin
Binary file not shown.
Binary file added hardware/simulation/iob_soc.dtb
Binary file not shown.
6 changes: 6 additions & 0 deletions hardware/simulation/linux_build_macros.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UART0_ADDR f2000000
ETH0_ADDR f4000000
CLINT0_ADDR f6000000
PLIC0_ADDR f8000000
FREQ 100000000
BAUD 3000000
36 changes: 6 additions & 30 deletions iob_soc_opencryptolinux.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python3
import os
import sys
import shutil
import math

from mk_configuration import update_define
from verilog_tools import inplace_change
from iob_soc_opencryptolinux_create_periphs_tmp import create_periphs_tmp
from iob_soc_opencryptolinux_create_periphs_tmp import (
create_periphs_tmp,
check_linux_build_macros,
)
from mk_configuration import append_str_config_build_mk

from iob_soc import iob_soc
Expand Down Expand Up @@ -123,7 +123,7 @@ def _post_setup(cls):
super()._post_setup()
dst = f"{cls.build_dir}/software/src"
src = f"{__class__.setup_dir}/submodules/OS/software/OS_build"
files = os.listdir(src)
files = ["rootfs.cpio.gz", "Image"]
for fname in files:
src_file = os.path.join(src, fname)
if os.path.isfile(src_file):
Expand All @@ -143,6 +143,7 @@ def _post_setup(cls):
cls.peripherals,
f"{cls.build_dir}/software/{cls.name}_periphs.h",
)
check_linux_build_macros(cls, f"{__class__.setup_dir}/submodules/OS")

if cls.is_top_module:
# Set ethernet MAC address
Expand Down Expand Up @@ -171,14 +172,6 @@ def _setup_confs(cls, extra_confs=[]):
# Append confs or override them if they exist
super()._setup_confs(
[
{
"name": "RUN_LINUX",
"type": "M",
"val": False,
"min": "0",
"max": "1",
"descr": "Used to select running linux.",
},
{
"name": "INIT_MEM",
"type": "M",
Expand Down Expand Up @@ -211,14 +204,6 @@ def _setup_confs(cls, extra_confs=[]):
"max": "32",
"descr": "Boot ROM address width",
},
{
"name": "SRAM_ADDR_W",
"type": "P",
"val": "15",
"min": "1",
"max": "32",
"descr": "SRAM address width",
},
{
"name": "MEM_ADDR_W",
"type": "P",
Expand Down Expand Up @@ -526,12 +511,3 @@ def _setup_portmap(cls):
},
),
]

@classmethod
def _custom_setup(cls):
super()._custom_setup()
# Add the following arguments:
# "RUN_LINUX": if should setup with init_mem or not
for arg in sys.argv[1:]:
if arg == "RUN_LINUX":
update_define(cls.confs, "RUN_LINUX", True)
65 changes: 43 additions & 22 deletions scripts/check_if_run_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
else:
RUN_LINUX = "0"


# If line contains "line_content", replace entire line with "new_line_content"
# If "line_content" is empty, append "new_line_content" to end of file
def replace_line(filename, line_content, new_line_content):
with open(filename, "r") as file:
lines = file.readlines()
if line_content:
for i in range(len(lines)):
if line_content in lines[i]:
lines[i] = new_line_content
else:
lines.append(new_line_content)

with open(filename, "w") as file:
file.writelines(lines)


# Generate "iob_mem.config" according to which binary firmware the SoC should load to RAM

iob_mem_file = f"{ROOT_DIR}/hardware/{SOC_NAME}_mem.config"
Expand All @@ -29,26 +46,30 @@

if "define SIMULATION 1" in content:
if RUN_LINUX == "1":
bsp_file = f"{ROOT_DIR}/hardware/simulation/src/bsp.vh"
with open(bsp_file, "w") as file:
file.write(
"`define BAUD 115200\n`define FREQ 100000000\n`define DDR_DATA_W 32\n`define DDR_ADDR_W 26\n`define SIMULATION 1"
)

bsp_file = f"{ROOT_DIR}/software/src/bsp.h"
with open(bsp_file, "w") as file:
file.write(
"#define BAUD 115200\n#define FREQ 100000000\n#define DDR_DATA_W 32\n#define DDR_ADDR_W 26\n#define SIMULATION 1"
)
# bsp_file = f"{ROOT_DIR}/hardware/simulation/src/bsp.vh"
# replace_line(bsp_file, "`define BAUD", "`define BAUD 115200\n")

# bsp_file = f"{ROOT_DIR}/software/src/bsp.h"
# replace_line(bsp_file, "#define BAUD", "#define BAUD 115200\n")

conf_file = f"{ROOT_DIR}/hardware/src/{SOC_NAME}_conf.vh"
replace_line(conf_file, "", "`define IOB_SOC_OPENCRYPTOLINUX_RUN_LINUX 1\n")

conf_file = f"{ROOT_DIR}/software/src/{SOC_NAME}_conf.h"
replace_line(
conf_file,
"#define H_IOB_SOC_OPENCRYPTOLINUX_CONF_H",
"#define H_IOB_SOC_OPENCRYPTOLINUX_CONF_H\n#define IOB_SOC_OPENCRYPTOLINUX_RUN_LINUX 1\n",
)
else:
bsp_file = f"{ROOT_DIR}/hardware/simulation/src/bsp.vh"
with open(bsp_file, "w") as file:
file.write(
"`define BAUD 3000000\n`define FREQ 100000000\n`define DDR_DATA_W 32\n`define DDR_ADDR_W 26\n`define SIMULATION 1"
)

bsp_file = f"{ROOT_DIR}/software/src/bsp.h"
with open(bsp_file, "w") as file:
file.write(
"#define BAUD 3000000\n#define FREQ 100000000\n#define DDR_DATA_W 32\n#define DDR_ADDR_W 26\n#define SIMULATION 1"
)
# bsp_file = f"{ROOT_DIR}/hardware/simulation/src/bsp.vh"
# replace_line(bsp_file, "`define BAUD", "`define BAUD 3000000\n")

# bsp_file = f"{ROOT_DIR}/software/src/bsp.h"
# replace_line(bsp_file, "#define BAUD", "#define BAUD 3000000\n")

conf_file = f"{ROOT_DIR}/hardware/src/{SOC_NAME}_conf.vh"
replace_line(conf_file, "`define IOB_SOC_OPENCRYPTOLINUX_RUN_LINUX", "")

conf_file = f"{ROOT_DIR}/software/src/{SOC_NAME}_conf.h"
replace_line(conf_file, "#define IOB_SOC_OPENCRYPTOLINUX_RUN_LINUX", "")
Loading