@@ -7,6 +7,13 @@ BUILD_PATH=$DIR/build
77ARMBIAN_PATH=$BUILD_PATH /armbian-build
88ARMBIAN_IMAGE_PATH=$ARMBIAN_PATH /output/images
99BOOTLOADER_IMAGE_PATH=$ARMBIAN_PATH /cache/sources/u-boot-worktree/u-boot-rockchip64/next-dev-v2024.03/
10+
11+ # Pre-tested flash.img location (SPINOR bootloader)
12+ # Using pre-tested bootloader by default to prevent bricking devices
13+ PRETESTED_FLASH_IMG=$DIR /userpatches/flash/flash.img
14+
15+ # Set REFLASH_BOOTLOADER=yes to regenerate flash.img from build instead of using pre-tested
16+ : ${REFLASH_BOOTLOADER:= no}
1017# #######################################################
1118Main () {
1219
@@ -147,19 +154,35 @@ CreateUsbFlashUpdate()
147154{
148155 echo " Create USB Flash Update files"
149156
150- echo " copy bootloader to output folder"
151- # Find rkspi_loader.img dynamically as u-boot version path varies between Armbian releases
152- RKSPI_LOADER=$( find $BOOTLOADER_IMAGE_PATH -name " rkspi_loader.img" -type f 2> /dev/null | head -n 1)
153- if [ -z " $RKSPI_LOADER " ]; then
154- echo " Warning: rkspi_loader.img not found in $BOOTLOADER_IMAGE_PATH "
155- echo " Searching in alternative locations..."
156- RKSPI_LOADER=$( find $ARMBIAN_PATH /cache/sources -name " rkspi_loader.img" -type f 2> /dev/null | head -n 1)
157- fi
158- if [ -n " $RKSPI_LOADER " ]; then
159- cp " $RKSPI_LOADER " $BUILD_PATH /flash.img
157+ echo " Preparing bootloader (flash.img)..."
158+
159+ if [ " $REFLASH_BOOTLOADER " = " yes" ]; then
160+ echo " REFLASH_BOOTLOADER=yes: Generating NEW flash.img from build"
161+ echo " WARNING: This is a new bootloader - test carefully before deploying!"
162+ # Find rkspi_loader.img dynamically as u-boot version path varies between Armbian releases
163+ RKSPI_LOADER=$( find $BOOTLOADER_IMAGE_PATH -name " rkspi_loader.img" -type f 2> /dev/null | head -n 1)
164+ if [ -z " $RKSPI_LOADER " ]; then
165+ echo " Warning: rkspi_loader.img not found in $BOOTLOADER_IMAGE_PATH "
166+ echo " Searching in alternative locations..."
167+ RKSPI_LOADER=$( find $ARMBIAN_PATH /cache/sources -name " rkspi_loader.img" -type f 2> /dev/null | head -n 1)
168+ fi
169+ if [ -n " $RKSPI_LOADER " ]; then
170+ cp " $RKSPI_LOADER " $BUILD_PATH /flash.img
171+ echo " New flash.img created from: $RKSPI_LOADER "
172+ else
173+ echo " Error: Could not find rkspi_loader.img"
174+ exit 1
175+ fi
160176 else
161- echo " Error: Could not find rkspi_loader.img"
162- exit 1
177+ echo " Using pre-tested flash.img (default safe mode)"
178+ if [ -f " $PRETESTED_FLASH_IMG " ]; then
179+ cp " $PRETESTED_FLASH_IMG " $BUILD_PATH /flash.img
180+ echo " Copied pre-tested flash.img from: $PRETESTED_FLASH_IMG "
181+ else
182+ echo " Error: Pre-tested flash.img not found at $PRETESTED_FLASH_IMG "
183+ echo " Either place a tested flash.img there or set REFLASH_BOOTLOADER=yes to generate new one"
184+ exit 1
185+ fi
163186 fi
164187
165188 echo " Split update file to 1GB parts"
0 commit comments