Default avatar
PublicNotes 11 months ago
## Question ``` root@GL-AR300M:/tmp# sysupgrade -n 6051c63e-6c7c-41fa-9ae6-509e216dbcfa\?X-Amz-Algorithm=AWS4-HMAC-SHA256 Mon Jan 27 20:06:50 UTC 2025 upgrade: Device glinet,gl-ar300m-nor not supported by this image Mon Jan 27 20:06:50 UTC 2025 upgrade: Supported devices: glinet,gl-ar300m16 gl-ar300m Image check failed. ``` I'm using the following script to build for the `glar300m`, but I seem to have multiple similar devices as you can see in the error message above. ``` -15-Gen6:~/TollGate/tollgate-image-builder$ cat build-firmware #!/bin/bash set -e set -x # Install packages if needed # sudo apt install -y gawk # sudo apt-get install -y coreutils # Build openwrt image MODEL=$1 VERSION=23.05.3 BUILDDIR=/tmp/openwrt-build BASE_PACKAGES=" \ base-files \ busybox \ ca-bundle \ dnsmasq \ dropbear \ firewall4 \ fstools \ kmod-gpio-button-hotplug \ kmod-leds-gpio \ kmod-nft-offload \ libc \ libgcc \ libustream-mbedtls \ logd \ mtd \ netifd \ nftables \ odhcp6c \ opkg \ ppp \ ppp-mod-pppoe \ procd \ procd-seccomp \ procd-ujail \ swconfig \ uci \ uclient-fetch \ urandom-seed \ urngd \ openssh-sftp-server \ opennds \ travelmate \ luci-app-travelmate \ curl \ jshn \ jsonfilter \ rpcd \ rpcd-mod-rpcsys \ " # opennds: our captive portal dependency (for ndsctl) # travelmate: lets upstream captive portals through the firewall for user to click ok # For the gl-ar300m case, modify the EXTRA_PACKAGES: case $MODEL in "gl-mt300n-v2") PLATFORM=ramips TYPE=mt76x8 TARGET_DEVICE=ramips-mt76x8 PROFILE=glinet_gl-mt300n-v2 EXTRA_PACKAGES="\ uboot-envtools \ watchcat \ luci \ luci-ssl \ " # opennds \ REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ " ;; "gl-ar300m") PLATFORM=ath79 TYPE=generic TARGET_DEVICE=ath79-generic PROFILE=glinet_gl-ar300m16 EXTRA_PACKAGES="\ uboot-envtools \ kmod-usb2 \ kmod-usb-core \ kmod-usb-storage \ luci \ luci-ssl \ iwinfo \ wpad-wolfssl \ " REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ -wpad-basic-wolfssl \ -wpad-basic-mbedtls \ -wpad-mini \ " ;; "gl-mt3000") PLATFORM=mediatek TYPE=filogic TARGET_DEVICE=mediatek-filogic PROFILE=glinet_gl-mt3000 EXTRA_PACKAGES="\ kmod-usb2 \ kmod-usb-core \ kmod-usb-storage \ luci \ luci-ssl \ iwinfo \ wpad-wolfssl \ " REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ -wpad-basic-wolfssl \ -wpad-basic-mbedtls \ -wpad-mini \ " ;; "gl-mt6000") PLATFORM=mediatek TYPE=filogic TARGET_DEVICE=mediatek-filogic PROFILE=glinet_gl-mt6000 EXTRA_PACKAGES="\ kmod-usb2 \ kmod-usb-core \ kmod-usb-storage \ luci \ luci-ssl \ iwinfo \ wpad-wolfssl \ " REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ -wpad-basic-wolfssl \ -wpad-basic-mbedtls \ -wpad-mini \ " ;; "gl-e750") VERSION="snapshot" PLATFORM=ath79 TYPE=nand TARGET_DEVICE=ath79-nand PROFILE=glinet_gl-e750 EXTRA_PACKAGES="\ kmod-usb2 \ kmod-usb-core \ kmod-usb-storage \ uboot-envtools \ " REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ " ;; "archer_mr200") PLATFORM=ramips TYPE=mt7620 TARGET_DEVICE=ramips-mt7620 PROFILE=tplink_archer-mr200 # Update to the correct profile name EXTRA_PACKAGES="\ kmod-usb2 \ kmod-usb-core \ luci \ luci-ssl \ " REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ " ;; *) echo "specify build target (gl-mt300n-v2, gl-ar300m, gl-mt3000, gl-mt6000, gl-e750, or archer_mr200)" exit 1 ;; esac if [ ! -d ${BUILDDIR} ] ; then mkdir ${BUILDDIR} fi # the need for $TYPE and $TARGET_DEVICE seems dumb but it helps get aroudn the problem of downloads ↓↓↓↓↓↓↓ # http://downloads.openwrt.org/releases/18.06.1/targets/ath79/generic/openwrt-imagebuilder-18.06.1-ath79-generic.Linux-x86_64.tar.xz #http://downloads.openwrt.org/releases/18.06.1/targets/ipq40xx/generic/openwrt-imagebuilder-18.06.1-ipq40xx.Linux-x86_64.tar.xz if [ "$VERSION" = "snapshot" ]; then IMAGEBUILDER_NAME="openwrt-imagebuilder-${PLATFORM}-${TYPE}.Linux-x86_64" DOWNLOAD_URL="https://downloads.openwrt.org/snapshots/targets/${PLATFORM}/${TYPE}/${IMAGEBUILDER_NAME}.tar.zst" ARCHIVE_EXT="tar.zst" else IMAGEBUILDER_NAME="openwrt-imagebuilder-${VERSION}-${TARGET_DEVICE}.Linux-x86_64" DOWNLOAD_URL="https://downloads.openwrt.org/releases/${VERSION}/targets/${PLATFORM}/${TYPE}/${IMAGEBUILDER_NAME}.tar.xz" ARCHIVE_EXT="tar.xz" fi if [ ! -d ${BUILDDIR}/${IMAGEBUILDER_NAME} ] ; then if [ ! -f ${BUILDDIR}/${IMAGEBUILDER_NAME}.${ARCHIVE_EXT} ]; then (cd ${BUILDDIR} && curl -C - -O ${DOWNLOAD_URL}) fi if [ "$VERSION" = "snapshot" ]; then tar --zstd -xf ${BUILDDIR}/${IMAGEBUILDER_NAME}.${ARCHIVE_EXT} -C ${BUILDDIR}/ else tar xfJ ${BUILDDIR}/${IMAGEBUILDER_NAME}.${ARCHIVE_EXT} -C ${BUILDDIR}/ fi fi COMBINED_PACKAGE_LIST="`echo ${REMOVED_PACKAGES}` `echo ${BASE_PACKAGES}` `echo ${EXTRA_PACKAGES}`" echo "Combined package list ${COMBINED_PACKAGE_LIST}" CORES=$(nproc) # Add these lines just before the final make command echo "Copying custom files..." cp -r $(pwd)/files ${BUILDDIR}/${IMAGEBUILDER_NAME}/ # Determine architecture based on platform/type case "${PLATFORM}-${TYPE}" in "ath79-generic") BLOSSOM_ARCH="mips_24kc" ;; "mediatek-filogic") BLOSSOM_ARCH="aarch64_cortex-a53" ;; *) echo "Unsupported platform-type combination for blossom downloads: ${PLATFORM}-${TYPE}" exit 1 ;; esac # Create packages directory in image builder PACKAGES_DIR="${BUILDDIR}/${IMAGEBUILDER_NAME}/packages/local" mkdir -p "${PACKAGES_DIR}" # Download IPK files using blossom_download.py echo "Downloading IPK files for architecture ${BLOSSOM_ARCH}..." python3 $(pwd)/blossom_download.py "${PACKAGES_DIR}" "${BLOSSOM_ARCH}" # Generate package index echo "Generating package index..." (cd ${BUILDDIR}/${IMAGEBUILDER_NAME} && \ sudo bash -c 'mkhash() { if [ "$1" = "sha256" ]; then sha256sum "$2" | cut -d" " -f1; else sha256sum "$1" | cut -d" " -f1; fi; }; \ export -f mkhash; \ export MKHASH=mkhash; \ ./scripts/ipkg-make-index.sh packages/local > packages/local/Packages && \ gzip -9c packages/local/Packages > packages/local/Packages.gz') # Add tollgate packages to the package list TOLLGATE_PACKAGES="\ " # tollgate-module-whoami-go \ # Update the combined package list to include tollgate packages COMBINED_PACKAGE_LIST="${COMBINED_PACKAGE_LIST} ${TOLLGATE_PACKAGES}" # Replace the build command and error checking with: echo "Building ${VERSION} using ${CORES} cores..." BUILD_OUTPUT=$(cd ${BUILDDIR}/${IMAGEBUILDER_NAME} && \ sudo make -j${CORES} image PROFILE="$PROFILE" \ PACKAGES="$COMBINED_PACKAGE_LIST" \ FILES="${BUILDDIR}/${IMAGEBUILDER_NAME}/files" 2>&1 | tee >(cat)) echo "${BUILD_OUTPUT}" # Check for common error patterns if echo "$BUILD_OUTPUT" | grep -q "Failed to open firmware file"; then echo "Error: Build failed - firmware file creation error" exit 1 fi if echo "$BUILD_OUTPUT" | grep -q "No such file or directory"; then echo "Error: Build failed - missing files" exit 1 fi # Extract the filesystem size from the output FILESYSTEM_SIZE=$(echo "$BUILD_OUTPUT" | grep "Filesystem size" | grep -o '[0-9.]\+ Kbytes' | awk '{print $1/1024}') # After the build command, add: OUTPUT_FILE="${BUILDDIR}/${IMAGEBUILDER_NAME}/bin/targets/${PLATFORM}/${TYPE}/openwrt-${VERSION}-${TARGET_DEVICE}-${PROFILE}-squashfs-sysupgrade.bin" if [ ! -f "$OUTPUT_FILE" ]; then echo "Error: Build failed - output file not created" exit 1 fi echo "Build successful! Firmware image created at:" echo "Image size (${FILESYSTEM_SIZE}MB)" echo "${OUTPUT_FILE}" echo echo "To deploy, use:" echo "scp -O ${BUILDDIR}/${IMAGEBUILDER_NAME}/bin/targets/${PLATFORM}/${TYPE}/openwrt-${VERSION}-${TARGET_DEVICE}-${PROFILE}-squashfs-sysupgrade.bin root@<dest>:/tmp" ``` Please add a section for `glinet,gl-ar300m-nor` to the above script without removing whats already there, since that might be useful for one of the other routers that I have.. -------- ## Answer I'll add a new case for the `glinet,gl-ar300m-nor` device. You'll need to add this within the case statement, alongside the other device configurations: ```bash "gl-ar300m-nor") PLATFORM=ath79 TYPE=generic TARGET_DEVICE=ath79-generic PROFILE=glinet_gl-ar300m-nor EXTRA_PACKAGES="\ uboot-envtools \ kmod-usb2 \ kmod-usb-core \ kmod-usb-storage \ luci \ luci-ssl \ iwinfo \ wpad-wolfssl \ " REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ -wpad-basic-wolfssl \ -wpad-basic-mbedtls \ -wpad-mini \ " ;; ``` Also, you'll need to update the usage message in the default case (*) to include the new option. Change this line: ```bash *) echo "specify build target (gl-mt300n-v2, gl-ar300m, gl-mt3000, gl-mt6000, gl-e750, archer_mr200, gl-ar300m-nor)" exit 1 ;; ``` The configuration for `gl-ar300m-nor` is similar to the regular `gl-ar300m` since they share the same basic hardware, but they differ in their flash memory configuration. The "nor" variant uses NOR flash memory instead of NAND flash memory. You can now build for this specific variant by running: ```bash ./build-firmware gl-ar300m-nor ``` ## Followup ``` make: *** [Makefile:260: image] Error 2 make: *** [Makefile:260: image] Error 2' + grep -q 'No such file or directory' ++ echo 'Profile "glinet_gl-ar300m-nor" does not exist! Profile "glinet_gl-ar300m-nor" does not exist! Use "make info" to get a list of available profile names. Use "make info" to get a list of available profile names. ``` As you can see above, my build script still seems to be wrong. Here is some related information from the openwrt page about this router: ``` ### Info[]( |Brand|Model|Version|Device Type|Availability|Supported Since Commit|Supported Since Rel|Supported Current Rel|Unsupported Functions|Bootloader|Target|CPU MHz|Flash MB|RAM MB|Switch|Ethernet 100M ports|Ethernet 1Gbit ports|Comments network ports|Modem|VLAN|WLAN 2.4GHz|WLAN 5.0GHz|WLAN Hardware|WLAN Comments|Detachable Antennas|USB ports|SATA ports|Comments USB SATA ports|Serial|JTAG|LED count|Button count|Power Supply||OWrt Forum Topic URL|WikiDevi URL|OEM Device Homepage URL|Firmware OEM Stock URL|Firmware OpenWrt Install URL|Firmware OpenWrt Upgrade URL|Comments| |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---| |GL.iNet|GL-AR300M|v1.4.0|WiFi Router|Available 2020|`[d963ddf0424a](https://git.lede-project.org/?p=source.git;a=commit;h=d963ddf0424a551e5fadd561c934bfdb5d198764)`|[17.01.0](https://openwrt.org/releases/17.01.0 "releases:17.01.0")|[23.05.5]( "releases:23.05.5")|NAND flash not supported until after 19.07.x, must be forced into booting from NOR flash|U-Boot|[ar71xx-ath79]( "docs:techref:targets:ar71xx-ath79")|650|16, 128NAND|128|Qualcomm Atheros QCA9531|2|-||-|Yes|b/g/n|-|Qualcomm Atheros QCA9531|"-EXT" suffix has 2 detachable Antennas (RP-SMA)|-|1x 2.0|-||Yes|No|3|2|5 VDC, 2.0 A (µUSB)|[Edit]( "toh:hwdata:gl.inet:gl.inet_gl-ar300m")|[Discourse: gl-ar300m-sysupgrade-problem](https://forum.openwrt.org/t/gl-ar300m-sysupgrade-problem/1812), [Discourse: howto-upgrade-the-preinstalled-openwrt-lede-17-01-firmware-in-the-gl-ar300m-router](https://forum.openwrt.org/t/howto-upgrade-the-preinstalled-openwrt-lede-17-01-firmware-in-the-gl-ar300m-router/21129)|[WikiDevi: GL.iNet_GL-AR300M](https://wikidevi.wi-cat.ru/GL.iNet_GL-AR300M)|[gl-inet.com](https://www.gl-inet.com/products/gl-ar300m/)|[OEM Firmware]( image](https://downloads.openwrt.org/releases/23.05.5/targets/ath79/nand/)|[Sysupgrade image](https://downloads.openwrt.org/releases/23.05.5/targets/ath79/nand/)|Flashing to the 128MB NAND flash is supported in Snapshot ath79 at time of writing, removable external antennas on "ext" variant| |GL.iNet|GL-AR300M16||WiFi Router|Available 2024|`[b591cabd3989](https://git.openwrt.org/?p=openwrt/openwrt.git;a=commit;h=b591cabd3989b44cfaf15248af9e55a0300a9c0a)`|[21.02.0](https://openwrt.org/releases/21.02.0 "releases:21.02.0")|[23.05.5]( "releases:23.05.5")||U-Boot|[ath79]( "docs:techref:targets:ath79")|650|16|128|Qualcomm QCA9531|2|-||-|Yes|b/g/n|-|Qualcomm QCA9531|GL-AR300M16-Ext variant has 2 detachable antennas (RP-SMA)|-|1x 2.0|-||Yes|No|3|2|5V/1A, microUSB|[Edit]( "toh:hwdata:gl.inet:gl.inet_gl-ar300m16")||[WikiDevi: GL.iNet_GL-AR300M](https://wikidevi.wi-cat.ru/GL.iNet_GL-AR300M)|[gl-inet.com](https://www.gl-inet.com/products/gl-ar300m/)|[OEM Firmware]( image](https://downloads.openwrt.org/releases/23.05.5/targets/ath79/generic/openwrt-23.05.5-ath79-generic-glinet_gl-ar300m16-initramfs-kernel.bin)|[Sysupgrade image](https://downloads.openwrt.org/releases/23.05.5/targets/ath79/generic/openwrt-23.05.5-ath79-generic-glinet_gl-ar300m16-squashfs-sysupgrade.bin)|| ``` Does this information help to identify what needs to go in the build script? ## Answer It looks like OpenWrt does not actually define a “glinet_gl-ar300m-nor” profile name. Instead, the NOR version of the GL-AR300M is referred to as “glinet_gl-ar300m16.” So, if you want to build for the device’s NOR flash, you will need a case matching that existing OpenWrt profile. Below is an example of how you can add a “gl-ar300m-nor” option to your script (so that you can pass “gl-ar300m-nor” on the command line), while internally using the “glinet_gl-ar300m16” profile. Note that you are not removing anything you already have; you’re simply adding a new case for the sake of building the NOR variant: ```bash "gl-ar300m-nor") PLATFORM=ath79 TYPE=generic TARGET_DEVICE=ath79-generic PROFILE=glinet_gl-ar300m16 EXTRA_PACKAGES="\ uboot-envtools \ kmod-usb2 \ kmod-usb-core \ kmod-usb-storage \ luci \ luci-ssl \ iwinfo \ wpad-wolfssl \ " REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ -wpad-basic-wolfssl \ -wpad-basic-mbedtls \ -wpad-mini \ " ;; ``` Also modify your default usage message to include “gl-ar300m-nor” as an option: ```bash *) echo "specify build target (gl-mt300n-v2, gl-ar300m, gl-ar300m-nor, gl-mt3000, gl-mt6000, gl-e750, or archer_mr200)" exit 1 ;; ``` If you invoke your script as: » ./build-firmware gl-ar300m-nor it will now use the “glinet_gl-ar300m16” profile (which is the correct NOR-only OpenWrt image for AR300M devices). ## Followup Ok, now I think I have duplicates. The nor and nand versions both end in `m16`. How can I fix this? ``` "gl-ar300m") PLATFORM=ath79 TYPE=generic TARGET_DEVICE=ath79-generic PROFILE=glinet_gl-ar300m16 EXTRA_PACKAGES="\ uboot-envtools \ kmod-usb2 \ kmod-usb-core \ kmod-usb-storage \ luci \ luci-ssl \ iwinfo \ wpad-wolfssl \ " REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ -wpad-basic-wolfssl \ -wpad-basic-mbedtls \ -wpad-mini \ " ;; "gl-ar300m-nor") PLATFORM=ath79 TYPE=generic TARGET_DEVICE=ath79-generic PROFILE=glinet_gl-ar300m16 EXTRA_PACKAGES="\ uboot-envtools \ kmod-usb2 \ kmod-usb-core \ kmod-usb-storage \ luci \ luci-ssl \ iwinfo \ wpad-wolfssl \ " REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ -wpad-basic-wolfssl \ -wpad-basic-mbedtls \ -wpad-mini \ " ;; ``` ## Answer Looking at the OpenWrt device info you shared, the NAND version should use the `ath79/nand` target while the NOR version uses `ath79/generic`. Here's how to correctly differentiate between the two versions: ```bash "gl-ar300m") # NAND version PLATFORM=ath79 TYPE=nand TARGET_DEVICE=ath79-nand PROFILE=glinet_gl-ar300m EXTRA_PACKAGES="\ uboot-envtools \ kmod-usb2 \ kmod-usb-core \ kmod-usb-storage \ luci \ luci-ssl \ iwinfo \ wpad-wolfssl \ " REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ -wpad-basic-wolfssl \ -wpad-basic-mbedtls \ -wpad-mini \ " ;; "gl-ar300m-nor") # NOR version (16MB flash) PLATFORM=ath79 TYPE=generic TARGET_DEVICE=ath79-generic PROFILE=glinet_gl-ar300m16 EXTRA_PACKAGES="\ uboot-envtools \ kmod-usb2 \ kmod-usb-core \ kmod-usb-storage \ luci \ luci-ssl \ iwinfo \ wpad-wolfssl \ " REMOVED_PACKAGES="\ -odhcpd \ -odhcpd-ipv6only \ -wpad-basic-wolfssl \ -wpad-basic-mbedtls \ -wpad-mini \ " ;; ``` The key differences are: 1. NAND version uses `TYPE=nand` and `TARGET_DEVICE=ath79-nand` 2. NAND version uses `PROFILE=glinet_gl-ar300m` 3. NOR version uses `TYPE=generic` and `TARGET_DEVICE=ath79-generic` 4. NOR version uses `PROFILE=glinet_gl-ar300m16` This should now correctly build for both variants of the router.