Skip to content

Commit 95cd835

Browse files
committed
utils: add support for generating both sdcard and emmc images
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 2707303 commit 95cd835

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

board/aarch64/bananapi-bpi-r3/genimage.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ image var.ext4 {
2424
}
2525
}
2626

27-
image #INFIX_ID##VERSION#-bpi-r3-sdcard.img {
27+
image #INFIX_ID##VERSION#-bpi-r3-#TARGET#.img {
2828
hdimage {
2929
partition-table-type = "gpt"
3030

utils/mkimage.sh

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Options:
2525
-l List available boards
2626
-o Override auto-detection of genimage.sh, use host installed version
2727
-r root-dir Path to rootfs build directory or rootfs.squashfs file (default: O= or output/)
28+
-t target Image target type: sdcard or emmc (default: sdcard)
2829
2930
Arguments:
3031
board-name Board identifier (must come after options)
@@ -37,7 +38,7 @@ Description:
3738
from separate boot and rootfs sources. Useful for CI or manual image creation.
3839
3940
Output:
40-
SD card image saved to \$BINARIES_DIR/*-sdcard.img
41+
Image saved to \$BINARIES_DIR/*-sdcard.img or *-emmc.img
4142
4243
Examples:
4344
# From Buildroot build:
@@ -52,6 +53,9 @@ Examples:
5253
# Download bootloader and compose with Linux image in output directory:
5354
$0 -od bananapi-bpi-r3
5455
56+
# Create eMMC image instead of SD card:
57+
$0 -t emmc bananapi-bpi-r3
58+
5559
EOF
5660
}
5761

@@ -107,7 +111,7 @@ run_genimage()
107111
--config "$genimage_cfg"
108112

109113
if command -v bmaptool >/dev/null 2>&1; then
110-
for img in "${BINARIES_DIR}"/*-sdcard.img; do
114+
for img in "${BINARIES_DIR}"/*-sdcard.img "${BINARIES_DIR}"/*-emmc.img; do
111115
[ -f "$img" ] || continue
112116
log "Generating block map for $(basename "$img")..."
113117
bmaptool create -o "${img}.bmap" "$img"
@@ -163,12 +167,17 @@ find_build_dir()
163167
get_bootloader_name()
164168
{
165169
board="$1"
170+
target="$2"
166171
case "$board" in
167172
raspberrypi-rpi64)
168173
echo "rpi64_boot"
169174
;;
170175
bananapi-bpi-r3)
171-
echo "bpi_r3_sd_boot"
176+
if [ "$target" = "emmc" ]; then
177+
echo "bpi_r3_emmc_boot"
178+
else
179+
echo "bpi_r3_sd_boot"
180+
fi
172181
;;
173182
friendlyarm-nanopi-r2s)
174183
echo "nanopi_r2s_boot"
@@ -187,8 +196,9 @@ download_bootloader()
187196
{
188197
board="$1"
189198
build_dir="$2"
199+
target="$3"
190200

191-
bootloader=$(get_bootloader_name "$board") || return 1
201+
bootloader=$(get_bootloader_name "$board" "$target") || return 1
192202

193203
if ! command -v gh >/dev/null 2>&1; then
194204
die "gh CLI not found. Install it or build bootloader locally."
@@ -271,7 +281,7 @@ discover_rpi_boot_files()
271281
echo "$files"
272282
}
273283

274-
while getopts "hldfob:r:" opt; do
284+
while getopts "hldfob:r:t:" opt; do
275285
case $opt in
276286
b)
277287
BOOT_DIR="$OPTARG"
@@ -299,6 +309,9 @@ while getopts "hldfob:r:" opt; do
299309
ROOT_DIR="$OPTARG"
300310
STANDALONE=1
301311
;;
312+
t)
313+
TARGET="$OPTARG"
314+
;;
302315
*)
303316
usage
304317
exit 1
@@ -312,6 +325,22 @@ if ! validate_board "$1"; then
312325
exit 1
313326
fi
314327

328+
# Validate and set default target
329+
: "${TARGET:=sdcard}"
330+
case "$TARGET" in
331+
sd|sdcard)
332+
TARGET="sdcard"
333+
;;
334+
emmc)
335+
TARGET="emmc"
336+
;;
337+
*)
338+
err "Invalid target: $TARGET. Must be 'sdcard' or 'emmc'"
339+
usage
340+
exit 1
341+
;;
342+
esac
343+
315344
# Standalone mode: set up environment from build directories
316345
if [ -n "$STANDALONE" ]; then
317346
# In download mode without explicit dirs, default to same location for both
@@ -404,7 +433,7 @@ if [ -n "$DOWNLOAD_BOOT" ]; then
404433
# Save original output location
405434
ORIGINAL_BINARIES_DIR="$BINARIES_DIR"
406435

407-
download_bootloader "$BOARD" "$BUILD_DIR"
436+
download_bootloader "$BOARD" "$BUILD_DIR" "$TARGET"
408437

409438
# Now use the temporary directory for composition
410439
BINARIES_DIR="$SDCARD_TEMP_DIR"
@@ -458,7 +487,7 @@ fi
458487
# Epxand template variables
459488
sed "s|#VERSION#|${RELEASE}|" "$GENIMAGE_TEMPLATE" | \
460489
sed "s|#INFIX_ID#|${INFIX_ID}|" | \
461-
sed "s|#TARGET#|sd|" > "$GENIMAGE_CFG"
490+
sed "s|#TARGET#|${TARGET}|" > "$GENIMAGE_CFG"
462491

463492
# Clean up temp file if created
464493
rm -f "${GENIMAGE_CFG}.tmp"
@@ -479,19 +508,19 @@ else
479508
fi
480509

481510
if [ -z "$OVERRIDE" ] && command -v "$GENIMAGE_WRAPPER" >/dev/null 2>&1; then
482-
log "Creating SD card image using Buildroot $(basename "$GENIMAGE_WRAPPER") ..."
511+
log "Creating $TARGET image using Buildroot $(basename "$GENIMAGE_WRAPPER") ..."
483512
"$GENIMAGE_WRAPPER" -c "$GENIMAGE_CFG"
484513
else
485-
log "Creating SD card image ..."
514+
log "Creating $TARGET image ..."
486515
run_genimage "$GENIMAGE_CFG"
487516
fi
488517

489518
# Post-processing: move images and cleanup if using download mode
490519
if [ -n "$DOWNLOAD_BOOT" ]; then
491-
log "Moving SD card images to $ORIGINAL_BINARIES_DIR..."
520+
log "Moving $TARGET images to $ORIGINAL_BINARIES_DIR..."
492521
mkdir -p "$ORIGINAL_BINARIES_DIR"
493522

494-
for img in "${BINARIES_DIR}"/*-sdcard.img*; do
523+
for img in "${BINARIES_DIR}"/*-sdcard.img* "${BINARIES_DIR}"/*-emmc.img*; do
495524
if [ -f "$img" ]; then
496525
mv "$img" "$ORIGINAL_BINARIES_DIR/"
497526
log " $(basename "$img")"
@@ -505,8 +534,8 @@ if [ -n "$DOWNLOAD_BOOT" ]; then
505534
BINARIES_DIR="$ORIGINAL_BINARIES_DIR"
506535
fi
507536

508-
log "SD card image created successfully:"
509-
for img in "${BINARIES_DIR}"/*-sdcard.img*; do
537+
log "$TARGET image created successfully:"
538+
for img in "${BINARIES_DIR}"/*-sdcard.img* "${BINARIES_DIR}"/*-emmc.img*; do
510539
if [ -f "$img" ]; then
511540
if [ -n "$STANDALONE" ]; then
512541
# Show relative path in standalone mode

0 commit comments

Comments
 (0)