Skip to content

Commit 700ec2f

Browse files
committed
Add crete SD Card workflow
1 parent 709f276 commit 700ec2f

File tree

2 files changed

+224
-9
lines changed

2 files changed

+224
-9
lines changed

.github/workflows/build-image.yml

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
name: Create SD Card Images
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
board:
7+
description: 'Board to create image for'
8+
type: choice
9+
required: true
10+
options:
11+
- raspberry-pi-4
12+
default: 'raspberry-pi-4'
13+
use_latest_release:
14+
description: 'Use latest release artifacts instead of workflow artifacts'
15+
type: boolean
16+
default: false
17+
18+
jobs:
19+
create-image:
20+
name: Create SD Card Image for ${{ inputs.board }}
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
with:
26+
clean: true
27+
fetch-depth: 0
28+
submodules: recursive
29+
30+
- name: Install dependencies
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install -y \
34+
genimage \
35+
u-boot-tools \
36+
parted \
37+
gdisk \
38+
qemu-utils \
39+
dosfstools \
40+
e2fsprogs \
41+
genext2fs \
42+
mtools \
43+
jq
44+
45+
- name: Prepare build environment
46+
run: |
47+
# Set up directory structure similar to buildroot build
48+
mkdir -p output/images
49+
mkdir -p build
50+
51+
- name: Set bootloader and target based on board
52+
run: |
53+
case "${{ inputs.board }}" in
54+
raspberry-pi-4)
55+
echo "BOOTLOADER=rpi4_boot" >> $GITHUB_ENV
56+
echo "TARGET=aarch64" >> $GITHUB_ENV
57+
;;
58+
*)
59+
echo "Error: Unknown board ${{ inputs.board }}"
60+
exit 1
61+
;;
62+
esac
63+
echo "Using bootloader: $BOOTLOADER and target: $TARGET for board: ${{ inputs.board }}"
64+
65+
- name: Download bootloader artifacts
66+
if: ${{ !inputs.use_latest_release }}
67+
run: |
68+
# Download from latest bootloader build workflow on main branch
69+
gh run list --workflow=build-boot.yml --branch=main --limit=1 --status=success --json databaseId --jq '.[0].databaseId' > latest_boot_run_id
70+
BOOT_RUN_ID=$(cat latest_boot_run_id)
71+
72+
gh run download ${BOOT_RUN_ID} --name artifact-${BOOTLOADER} --dir temp_bootloader/
73+
74+
# Extract bootloader directly to output/images
75+
cd temp_bootloader/
76+
tar -xzf *.tar.gz --strip-components=1 -C ../output/images/
77+
cd ../
78+
rm -rf temp_bootloader/
79+
80+
echo "Bootloader files extracted to output/images:"
81+
ls -la output/images/
82+
env:
83+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- name: Download Infix artifacts
86+
if: ${{ !inputs.use_latest_release }}
87+
run: |
88+
# Download from latest Kernelkit Trigger workflow for main branch
89+
gh run list --workflow=164295764 --branch=main --limit=1 --status=success --json databaseId --jq '.[0].databaseId' > latest_infix_run_id
90+
INFIX_RUN_ID=$(cat latest_infix_run_id)
91+
92+
gh run download ${INFIX_RUN_ID} --name artifact-${TARGET} --dir temp_infix/
93+
94+
# Extract Infix directly to output/images
95+
cd temp_infix/
96+
tar -xzf *.tar.gz --strip-components=1 -C ../output/images/
97+
cd ../
98+
rm -rf temp_infix/
99+
100+
echo "Infix files extracted to output/images:"
101+
ls -la output/images/
102+
env:
103+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
105+
- name: Download from latest releases
106+
if: ${{ inputs.use_latest_release }}
107+
run: |
108+
# Download latest bootloader release
109+
gh release download latest-boot --pattern "*${BOOTLOADER}*" --dir temp_bootloader/
110+
cd temp_bootloader/
111+
tar -xzf *.tar.gz --strip-components=1 -C ../output/images/
112+
cd ../
113+
rm -rf temp_bootloader/
114+
115+
# Download latest Infix release
116+
gh release download latest --pattern "*${TARGET}*" --dir temp_infix/
117+
cd temp_infix/
118+
tar -xzf *.tar.gz --strip-components=1 -C ../output/images/
119+
cd ../
120+
rm -rf temp_infix/
121+
122+
echo "All files extracted to output/images:"
123+
ls -la output/images/
124+
env:
125+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126+
127+
- name: Verify extracted files
128+
run: |
129+
echo "Files available for mkimage.sh:"
130+
ls -la output/images/
131+
echo ""
132+
echo "File types:"
133+
file output/images/* || true
134+
135+
- name: Create SD card image
136+
run: |
137+
export BINARIES_DIR=$PWD/output/images
138+
export BUILD_DIR=$PWD/build
139+
export BR2_EXTERNAL_INFIX_PATH=$PWD
140+
export RELEASE=""
141+
export INFIX_ID="infix"
142+
143+
# Use the standardized mkimage.sh path for the selected board
144+
# BOARD_SCRIPT="src/board/${{ inputs.board }}/mkimage.sh"
145+
BOARD_SCRIPT="src/board/raspberry-pi-4/mkimage.sh"
146+
147+
if [ -f "$BOARD_SCRIPT" ]; then
148+
echo "Using board-specific image creation script: $BOARD_SCRIPT"
149+
chmod +x "$BOARD_SCRIPT"
150+
"$BOARD_SCRIPT"
151+
else
152+
echo "Error: Board script $BOARD_SCRIPT not found!"
153+
exit 1
154+
fi
155+
156+
- name: Verify created image
157+
run: |
158+
echo "Contents of output/images after mkimage.sh:"
159+
ls -lh output/images/
160+
161+
# Look for SD card image with pattern: *-sdcard.img
162+
if ls output/images/*-sdcard.img 1> /dev/null 2>&1; then
163+
echo "Found SD card image(s):"
164+
for img in output/images/*-sdcard.img; do
165+
echo "- $(basename $img)"
166+
file "$img"
167+
fdisk -l "$img" 2>/dev/null || true
168+
done
169+
else
170+
echo "No SD card image found matching pattern: *-sdcard.img"
171+
echo "Available files:"
172+
ls -la output/images/
173+
exit 1
174+
fi
175+
176+
- name: Upload SD card image
177+
uses: actions/upload-artifact@v4
178+
with:
179+
name: sdcard-image-${{ inputs.board }}-${{ env.BOOTLOADER }}
180+
path: |
181+
output/images/*-sdcard.img
182+
retention-days: 30
183+
184+
- name: Create checksums
185+
run: |
186+
cd output/images/
187+
for file in *-sdcard.img; do
188+
if [ -f "$file" ]; then
189+
sha256sum "$file" > "$file.sha256"
190+
fi
191+
done
192+
193+
- name: Upload to release
194+
uses: ncipollo/release-action@v1
195+
with:
196+
allowUpdates: true
197+
omitName: true
198+
omitBody: true
199+
omitBodyDuringUpdate: true
200+
prerelease: true
201+
tag: "latest-boot"
202+
token: ${{ secrets.GITHUB_TOKEN }}
203+
artifacts: "output/images/*-sdcard.img*"
204+
205+
- name: Generate summary
206+
run: |
207+
cat <<EOF >> $GITHUB_STEP_SUMMARY
208+
# SD Card Image Build Complete! 🚀
209+
210+
**Board:** ${{ inputs.board }}
211+
**Target:** ${{ env.TARGET }}
212+
**Bootloader:** ${{ env.BOOTLOADER }}
213+
**Artifact Source:** ${{ inputs.use_latest_release && 'Latest Release' || 'Latest Workflow Run' }}
214+
215+
## Created Images
216+
$(find output/images/ -name "*.img" -o -name "*.qcow2" -o -name "*.raw" | xargs ls -lh 2>/dev/null | sed 's/^/- /' || echo "- No images found")
217+
218+
## Download
219+
The SD card image is available as a workflow artifact above.
220+
EOF
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
#!/bin/sh
22
set -e
3-
#. "$BR2_CONFIG" 2>/dev/null
43

54
BOARD_DIR=$(dirname "$0")
65
GENIMAGE_CFG="${BUILD_DIR}/genimage.cfg"
76
GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
87

9-
# Device trees are installed for distro boot (syslinux.conf), but on RPi
10-
# we need them for the SPL, which feeds the TPL (U-Boot) for use instead
11-
# of the (built-in) control DT other platforms use.
12-
find "${TARGET_DIR}/boot" -type f -name '*.dtb' -exec cp '{}' "${BINARIES_DIR}/" \;
13-
148
# We've asked U-Boot previously to build overlays for us: Infix signing
159
# key and our ixboot scripts. Make sure here they are installed in the
1610
# proper directory so genimage can create the DOS partition the SPL
@@ -26,15 +20,16 @@ for f in "${BINARIES_DIR}"/rpi-firmware/*; do
2620
echo "${FILES}" | grep -q `basename $f` && continue # If already exist it has been added by us.
2721
FILES="${FILES}\t\t\t\"${f#"${BINARIES_DIR}/"}\",\n"
2822
done
29-
23+
FILES="${FILES}\t\t\t\"splash.bmp\",\n"
3024
echo $FILES
3125
KERNEL=$(sed -n 's/^kernel=//p' "${BINARIES_DIR}/rpi-firmware/config.txt")
3226
FILES="${FILES}\t\t\t\"${KERNEL}\""
3327

3428

3529
sed "s|#BOOT_FILES#|${FILES}|" "${BOARD_DIR}/genimage.cfg.in" | \
36-
sed "s|#VERSION#|${RELEASE}|" | \
37-
sed "s|#INFIX_ID#|${INFIX_ID}|" > "${GENIMAGE_CFG}"
30+
sed "s|#INFIX_ID#|${INFIX_ID}|" | \
31+
sed "s|#VERSION#|${RELEASE}|" > "${GENIMAGE_CFG}"
32+
3833

3934
ROOTPATH_TMP=$(mktemp -d)
4035
trap 'rm -rf \"$ROOTPATH_TMP\"' EXIT

0 commit comments

Comments
 (0)