Skip to content

Commit ff114c0

Browse files
committed
Add crete SD Card workflow
1 parent da3bf57 commit ff114c0

File tree

2 files changed

+231
-4
lines changed

2 files changed

+231
-4
lines changed

.github/workflows/build-image.yml

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

src/board/raspberry-pi-4/mksdcard.sh renamed to src/board/raspberry-pi-4/mkimage.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ set -e
55
BOARD_DIR=$(dirname "$0")
66
GENIMAGE_CFG="${BUILD_DIR}/genimage.cfg"
77
GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
8+
#TARGET_DIR="${BR2_EXTERNAL_INFIX_PATH}/output/target"
89

910
# Device trees are installed for distro boot (syslinux.conf), but on RPi
1011
# we need them for the SPL, which feeds the TPL (U-Boot) for use instead
1112
# of the (built-in) control DT other platforms use.
12-
find "${TARGET_DIR}/boot" -type f -name '*.dtb' -exec cp '{}' "${BINARIES_DIR}/" \;
13+
#find "${BINARIES_DIR}" -type f -name '*.dtb' -exec cp '{}' "${BINARIES_DIR}/" \;
1314

1415
# We've asked U-Boot previously to build overlays for us: Infix signing
1516
# key and our ixboot scripts. Make sure here they are installed in the
@@ -26,15 +27,16 @@ for f in "${BINARIES_DIR}"/rpi-firmware/*; do
2627
echo "${FILES}" | grep -q `basename $f` && continue # If already exist it has been added by us.
2728
FILES="${FILES}\t\t\t\"${f#"${BINARIES_DIR}/"}\",\n"
2829
done
29-
30+
FILES="${FILES}\t\t\t\"splash.bmp\",\n"
3031
echo $FILES
3132
KERNEL=$(sed -n 's/^kernel=//p' "${BINARIES_DIR}/rpi-firmware/config.txt")
3233
FILES="${FILES}\t\t\t\"${KERNEL}\""
3334

3435

3536
sed "s|#BOOT_FILES#|${FILES}|" "${BOARD_DIR}/genimage.cfg.in" | \
36-
sed "s|#VERSION#|${RELEASE}|" | \
37-
sed "s|#INFIX_ID#|${INFIX_ID}|" > "${GENIMAGE_CFG}"
37+
sed "s|#INFIX_ID#|${INFIX_ID}|" | \
38+
sed "s|#VERSION#|${RELEASE}|" > "${GENIMAGE_CFG}"
39+
3840

3941
ROOTPATH_TMP=$(mktemp -d)
4042
trap 'rm -rf \"$ROOTPATH_TMP\"' EXIT

0 commit comments

Comments
 (0)