Skip to content
Draft
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
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@
path = src/dtc
url = https://github.com/dgibson/dtc
shallow = true
[submodule "tests/system/br_pkgs/doom_riscv"]
path = tests/system/br_pkgs/doom_riscv
url = https://github.com/sysprog21/doom_riscv
shallow = true
[submodule "tests/system/br_pkgs/quake"]
path = tests/system/br_pkgs/quake
url = https://github.com/sysprog21/quake-embedded/
shallow = true
2 changes: 2 additions & 0 deletions assets/system/configs/buildroot.config
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ BR2_PACKAGE_UTIL_LINUX_HWCLOCK=y

BR2_PACKAGE_RTC_ALARM=y
BR2_PACKAGE_RTC_SETTIME=y
BR2_PACKAGE_DOOM=y
BR2_PACKAGE_QUAKE=y
1 change: 1 addition & 0 deletions tests/system/br_pkgs/doom_riscv
Submodule doom_riscv added at f34854
1 change: 1 addition & 0 deletions tests/system/br_pkgs/quake
Submodule quake added at da5c5a
85 changes: 81 additions & 4 deletions tools/build-linux-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ mkdir -p $OUTPUT_DIR

BR_PKG_RTC_DIR=./tests/system/br_pkgs/rtc

# RTC
BR_RTC_PKG_DIR=./tests/system/br_pkgs/rtc

# Doom
BR_DOOM_PKG_DIR=./tests/system/br_pkgs/doom_riscv

# Quake
BR_QUAKE_PKG_DIR=./tests/system/br_pkgs/quake

function create_br_pkg_config()
{
local pkg_name=$1
Expand All @@ -43,6 +52,9 @@ function create_br_pkg_makefile()
{
local pkg_name=$1
local output_path=$2
local output_bin_prefix=${3-}
local makefile_prefix=${4-}
local artifact=${5-}

cat << EOF > "${output_path}"
################################################################################
Expand All @@ -56,11 +68,12 @@ ${pkg_name^^}_SITE = package/${pkg_name}/src
${pkg_name^^}_SITE_METHOD = local

define ${pkg_name^^}_BUILD_CMDS
\$(MAKE) CC="\$(TARGET_CC)" LD="\$(TARGET_LD)" -C \$(@D)
\$(MAKE) CROSS="\$(TARGET_CROSS)" CC="\$(TARGET_CC)" LD="\$(TARGET_LD)" -C \$(@D)/${makefile_prefix}
endef

define ${pkg_name^^}_INSTALL_TARGET_CMDS
\$(INSTALL) -D -m 0755 \$(@D)/${pkg_name} \$(TARGET_DIR)/usr/bin
\$(INSTALL) -D -m 0755 \$(@D)/${output_bin_prefix}/${pkg_name} \$(TARGET_DIR)/usr/bin
cp -a \$(@D)/${artifact} \$(TARGET_DIR)/root
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: When artifact is empty (as it is for RTC packages called without the 5th argument), this line becomes cp -a $(@D)/ $(TARGET_DIR)/root, which copies the entire build directory to /root. This should be conditional on artifact being non-empty.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tools/build-linux-image.sh, line 76:

<comment>When `artifact` is empty (as it is for RTC packages called without the 5th argument), this line becomes `cp -a $(@D)/ $(TARGET_DIR)/root`, which copies the entire build directory to `/root`. This should be conditional on artifact being non-empty.</comment>

<file context>
@@ -56,11 +68,12 @@ ${pkg_name^^}_SITE = package/${pkg_name}/src
 define ${pkg_name^^}_INSTALL_TARGET_CMDS
-	\$(INSTALL) -D -m 0755 \$(@D)/${pkg_name} \$(TARGET_DIR)/usr/bin
+	\$(INSTALL) -D -m 0755 \$(@D)/${output_bin_prefix}/${pkg_name} \$(TARGET_DIR)/usr/bin
+	cp -a \$(@D)/${artifact} \$(TARGET_DIR)/root
 endef
 
</file context>
Fix with Cubic

endef

\$(eval \$(generic-package))
Expand Down Expand Up @@ -96,14 +109,73 @@ function update_br_pkg_config()
local source_line=" source \"package/${pkg_name}/Config.in\""

# Only append if this package's isn't already present in the menu
if ! grep -q "${pkg_name}" "${br_pkg_config_file}"; then
if ! grep -q "/${pkg_name}/" "${br_pkg_config_file}"; then
sed -i '/^menu "Custom packages"/,/^endmenu$/{
/^endmenu$/i\
'"${source_line}"'
}' "${br_pkg_config_file}"
fi
}

function do_patch_doom
{
# Need to sed -i --specs=nano.spec to avoid nanolibc and -Bstatic to avoid static linking
sed -i 's/--specs=nano\.specs//g' ${BR_DOOM_PKG_DIR}/src/riscv/Makefile
sed -i 's/-Bstatic//g' ${BR_DOOM_PKG_DIR}/src/riscv/Makefile
# rename output binary from doom-riscv.elf to doom
sed -i 's/doom-riscv\.elf/doom/g' ${BR_DOOM_PKG_DIR}/src/riscv/Makefile

local pkg_name="doom"

mkdir -p ${SRC_DIR}/buildroot/package/${pkg_name}

# download and unzip Doom artifact(DOOM1.WAD) to buildroot Doom package src
if [[ ! -f shareware_doom_iwad.zip ]]; then
wget \
--user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0" \
--referer="https://www.doomworld.com/" \
--show-progress \
--continue \
http://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Using HTTP instead of HTTPS for downloading files is a security risk. Consider using https:// if the server supports it, or verify the file integrity with a checksum after download.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tools/build-linux-image.sh, line 139:

<comment>Using HTTP instead of HTTPS for downloading files is a security risk. Consider using `https://` if the server supports it, or verify the file integrity with a checksum after download.</comment>

<file context>
@@ -96,14 +109,73 @@ function update_br_pkg_config()
+            --referer="https://www.doomworld.com/" \
+            --show-progress \
+            --continue \
+            http://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip
+        unzip -d ${SRC_DIR}/buildroot/package/${pkg_name}/src shareware_doom_iwad.zip
+    fi
</file context>
Suggested change
http://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip
https://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip
Fix with Cubic

unzip -d ${SRC_DIR}/buildroot/package/${pkg_name}/src shareware_doom_iwad.zip
fi

create_br_pkg_config ${pkg_name} ${SRC_DIR}/buildroot/package/${pkg_name}/Config.in
create_br_pkg_makefile ${pkg_name} ${SRC_DIR}/buildroot/package/${pkg_name}/${pkg_name}.mk "riscv" "riscv" "DOOM1.WAD"
# cp Doom submodule's src to buildroot Doom package src
mkdir -p ${SRC_DIR}/buildroot/package/${pkg_name}/src
cp -rf ${BR_DOOM_PKG_DIR}/src ${SRC_DIR}/buildroot/package/${pkg_name}/

update_br_pkg_config ${pkg_name}
}

function do_patch_quake
{
local pkg_name="quake"

mkdir -p ${SRC_DIR}/buildroot/package/${pkg_name}

# download and unzip Quake artifact(id1/pak0.pak) to buildroot Quake package src
if [[ ! -f quakesw-1.0.6.zip ]]; then
wget -q --show-progress --continue https://www.libsdl.org/projects/quake/data/quakesw-1.0.6.zip
unzip -d ${SRC_DIR}/buildroot/package/${pkg_name}/src quakesw-1.0.6.zip
fi

create_br_pkg_config ${pkg_name} ${SRC_DIR}/buildroot/package/${pkg_name}/Config.in
create_br_pkg_makefile ${pkg_name} ${SRC_DIR}/buildroot/package/${pkg_name}/${pkg_name}.mk "port/boards/rv32emu" "" "id1/"
# cmake to generate Makefile
cd ${BR_QUAKE_PKG_DIR}
cmake -DCMAKE_TOOLCHAIN_FILE=./port/boards/rv32emu/toolchain.cmake \
-DCROSS_COMPILE=riscv32-buildroot-linux-gnu- \
-DCMAKE_BUILD_TYPE=RELEASE -DBOARD_NAME=rv32emu .
cd -
# cp Quake submodule's src to buildroot Quake package src
mkdir -p ${SRC_DIR}/buildroot/package/${pkg_name}/src
cp -rf ${BR_QUAKE_PKG_DIR}/* ${SRC_DIR}/buildroot/package/${pkg_name}/src

update_br_pkg_config ${pkg_name}
}

# This function patches the packages when building the rootfs.cpio from scratch
function do_patch_buildroot
{
Expand All @@ -117,7 +189,8 @@ endmenu
EOF
fi

for c in $(find ${BR_PKG_RTC_DIR} -type f); do
# RTC self-contained C files
for c in $(find ${BR_RTC_PKG_DIR} -type f); do
local basename="$(basename ${c})"
local pkg_name="${basename%.*}"

Expand All @@ -129,6 +202,10 @@ EOF

update_br_pkg_config ${pkg_name}
done

do_patch_doom

do_patch_quake
}

function do_buildroot
Expand Down
Loading