Skip to content

Commit fa9181b

Browse files
committed
Tweak build linux image rules
- reuse mk/external.mk to verify integrity of the source - let build-system-image Makefile target can be reused in build-artifact CI
1 parent 3432824 commit fa9181b

File tree

5 files changed

+51
-26
lines changed

5 files changed

+51
-26
lines changed

.github/workflows/build-artifact.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
uses: tj-actions/changed-files@v45
3333
with:
3434
files: |
35-
.ci/buildroot_version.txt
36-
.ci/linux_version.txt
35+
# FIXME: detect only Linux image version changes
36+
mk/external.mk
3737
- name: Set alias
3838
id: has_changed_files
3939
run: |
@@ -67,6 +67,7 @@ jobs:
6767
sudo apt-get install -q -y build-essential git
6868
- name: Build Linux image
6969
run: |
70+
make build-linux-image
7071
make artifact ENABLE_PREBUILT=0 ENABLE_SYSTEM=1
7172
mkdir -p /tmp/rv32emu-linux-image-prebuilt
7273
mv build/Image /tmp/rv32emu-linux-image-prebuilt

mk/artifact.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ endif
8585
fi
8686
else
8787
ifeq ($(call has, SYSTEM), 1)
88-
$(Q)./tools/build-linux-image.sh
8988
$(Q)($(SHA1SUM) $(BIN_DIR)/Image) >> $(BIN_DIR)/sha1sum-linux-image
9089
$(Q)($(SHA1SUM) $(BIN_DIR)/rootfs.cpio) >> $(BIN_DIR)/sha1sum-linux-image
9190
else

mk/external.mk

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,32 @@ define epilogue
2121
endef
2222

2323
# $(1): compressed source URL
24+
# if URL contains git command, then use git
2425
define download
25-
$(eval _ := $(shell wget -q --show-progress --continue "$(strip $(1))"))
26+
$(eval _ := \
27+
$(if $(findstring git,$(1)), \
28+
($(eval _ := $(shell $(1)))), \
29+
($(eval _ := $(shell wget -q --show-progress --continue "$(strip $(1))"))) \
30+
))
2631
endef
2732

2833
# $(1): destination directory
2934
# $(2): compressed source(.zip or.gz)
35+
# For Buildroot and Linux kernel, no need to extract
3036
define extract
3137
$(eval COMPRESSED_SUFFIX := $(suffix $(2)))
3238
$(eval COMPRESSED_IS_ZIP := $(filter $(COMPRESSED_SUFFIX),.zip))
33-
$(eval _ := \
34-
$(if $(COMPRESSED_IS_ZIP), \
35-
($(eval EXTRACTOR := unzip -d $(1) $(2))), \
36-
($(eval EXTRACTOR := tar -xf $(2) -C $(1))) \
37-
))
38-
$(eval _ := $(shell $(EXTRACTOR)))
39+
$(eval _ := \
40+
$(if $(findstring git,$(2)), \
41+
(# git is used, do nothing),
42+
($(eval _ := \
43+
$(if $(COMPRESSED_IS_ZIP), \
44+
($(eval EXTRACTOR := unzip -d $(1) $(2))), \
45+
($(eval EXTRACTOR := tar -xf $(2) -C $(1))) \
46+
))
47+
$(eval _ := $(shell $(EXTRACTOR))))
48+
) \
49+
)
3950
endef
4051

4152
# $(1): correct SHA1 value
@@ -51,7 +62,7 @@ define verify
5162
$(if $(filter 1,$(COMPRESSED_IS_DIR)), \
5263
($(eval VERIFIER := \
5364
echo $(1) > $(SHA1_FILE1) \
54-
| find $(2) -type f -print0 \
65+
| find $(2) -type f -not -path '*/.git/*' -print0 \
5566
| sort -z \
5667
| xargs -0 $(SHA1SUM) \
5768
| sort \
@@ -78,19 +89,31 @@ endef
7889
# Doom
7990
# https://tipsmake.com/how-to-run-doom-on-raspberry-pi-without-emulator
8091
DOOM_DATA_URL = http://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip
81-
DOOM_DATA = $(OUT)/DOOM1.WAD
92+
DOOM_DATA = $(DOOM_OUT)/DOOM1.WAD
8293
DOOM_DATA_SHA1 = 5b2e249b9c5133ec987b3ea77596381dc0d6bc1d
8394

8495
# Quake
8596
QUAKE_DATA_URL = https://www.libsdl.org/projects/quake/data/quakesw-1.0.6.zip
86-
QUAKE_DATA = $(OUT)/id1/pak0.pak
97+
QUAKE_DATA = $(QUAKE_OUT)/id1/pak0.pak
8798
QUAKE_DATA_SHA1 = 36b42dc7b6313fd9cabc0be8b9e9864840929735
8899

89100
# Timidity software synthesizer configuration for SDL2_mixer
90101
TIMIDITY_DATA_URL = http://www.libsdl.org/projects/mixer/timidity/timidity.tar.gz
91-
TIMIDITY_DATA = $(OUT)/timidity
102+
TIMIDITY_DATA = $(TIMIDITY_OUT)/timidity
92103
TIMIDITY_DATA_SHA1 = cf6217a5d824b717ec4a07e15e6c129a4657ca25
93104

105+
# Buildroot
106+
BUILDROOT_VERSION = 2024.05.2
107+
BUILDROOT_DATA = /tmp/buildroot
108+
BUILDROOT_DATA_URL = git clone https://github.com/buildroot/buildroot $(BUILDROOT_DATA) -b $(BUILDROOT_VERSION) --depth=1
109+
BUILDROOT_DATA_SHA1 = e6677825313cdb47f6e62e4dc09a22ae30699b69
110+
111+
# Linux kernel
112+
LINUX_VERSION = linux-6.1.y
113+
LINUX_DATA = /tmp/linux
114+
LINUX_DATA_URL = git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git $(LINUX_DATA) -b $(LINUX_VERSION) --depth=1
115+
LINUX_DATA_SHA1 = 30e95c62e8264aba948bb52d75af57d435bb6b8e
116+
94117
define download-extract-verify
95118
$($(T)_DATA):
96119
$(Q)$$(call prologue,$$@)
@@ -100,5 +123,5 @@ $($(T)_DATA):
100123
$(Q)$$(call epilogue,$(notdir $($(T)_DATA_URL)),$(SHA1_FILE1),$(SHA1_FILE2))
101124
endef
102125

103-
EXTERNAL_DATA = DOOM QUAKE TIMIDITY
126+
EXTERNAL_DATA = DOOM QUAKE TIMIDITY BUILDROOT LINUX
104127
$(foreach T,$(EXTERNAL_DATA),$(eval $(download-extract-verify)))

mk/tools.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ $(HIST_BIN): $(HIST_OBJS)
2626
TOOLS_BIN += $(HIST_BIN)
2727

2828
# Build Linux image
29-
build-linux-img:
30-
tools/build-linux-image.sh
29+
LINUX_IMAGE_SRC = $(BUILDROOT_DATA) $(LINUX_DATA)
30+
build-linux-image: $(LINUX_IMAGE_SRC)
31+
$(Q)./tools/build-linux-image.sh
32+
$(Q)$(PRINTF) "Build done."

tools/build-linux-image.sh

100755100644
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,36 @@ function OK
1717
printf " [ ${PASS_COLOR} OK ${NO_COLOR} ]\n"
1818
}
1919

20+
SRC_DIR=/tmp
21+
2022
PARALLEL="-j$(nproc)"
2123

2224
function do_buildroot
2325
{
24-
ASSERT git clone https://github.com/buildroot/buildroot -b 2024.05.2 --depth=1
25-
cp -f assets/system/configs/buildroot.config buildroot/.config
26-
cp -f assets/system/configs/busybox.config buildroot/busybox.config
26+
cp -f assets/system/configs/buildroot.config $SRC_DIR/buildroot/.config
27+
cp -f assets/system/configs/busybox.config $SRC_DIR/buildroot/busybox.config
2728
# Otherwise, the error below raises:
2829
# You seem to have the current working directory in your
2930
# LD_LIBRARY_PATH environment variable. This doesn't work.
3031
unset LD_LIBRARY_PATH
31-
pushd buildroot
32+
pushd $SRC_DIR/buildroot
3233
ASSERT make olddefconfig
3334
ASSERT make $PARALLEL
3435
popd
35-
cp -f buildroot/output/images/rootfs.cpio ./build/
36+
cp -f $SRC_DIR/buildroot/output/images/rootfs.cpio ./build/
3637
}
3738

3839
function do_linux
3940
{
40-
ASSERT git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git -b linux-6.1.y --depth=1
41-
cp -f assets/system/configs/linux.config linux/.config
42-
export PATH="$PWD/buildroot/output/host/bin:$PATH"
41+
cp -f assets/system/configs/linux.config $SRC_DIR/linux/.config
42+
export PATH="$SRC_DIR/buildroot/output/host/bin:$PATH"
4343
export CROSS_COMPILE=riscv32-buildroot-linux-gnu-
4444
export ARCH=riscv
4545
pushd linux
4646
ASSERT make olddefconfig
4747
ASSERT make $PARALLEL
4848
popd
49-
cp -f linux/arch/riscv/boot/Image ./build/
49+
cp -f $SRC_DIR/linux/arch/riscv/boot/Image ./build/
5050
}
5151

5252
do_buildroot && OK

0 commit comments

Comments
 (0)