aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils/src/mkfwimage.c
Commit message (Collapse)AuthorAgeFilesLines
* ath79: add support for Ubiquiti airCube ACRoman Kuzmitskii2020-12-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Ubiquiti Network airCube AC is a cube shaped device supporting 2.4 GHz and 5 GHz with internal 2x2 MIMO antennas. It can be powered with either one of: - 24v power supply with 3.0mm x 1.0mm barrel plug - 24v passive PoE on first LAN port There are four 10/100/1000 Mbps ports (1 * WAN + 3 * LAN). First LAN port have optional PoE passthrough to the WAN port. SoC: Qualcomm / Atheros AR9342 RAM: 64 MB DDR2 Flash: 16 MB SPI NOR Ethernet: 4x 10/100/1000 Mbps (1 WAN + 3 LAN) LEDS: 1x via a SPI controller (not yet supported) Buttons: 1x Reset Serial: 1x (only RX and TX); 115200 baud, 8N1 Missing features: - LED control is not supported Physical to internal switch port mapping: - physical port #1 (poe in) = switchport 2 - physical port #2 = switchport 3 - physical port #3 = switchport 5 - physical port #4 (wan/poe out) = switchport 4 Factory update is tested and is the same as for Ubiquiti AirCube ISP hence the shared configuration between that devices. Signed-off-by: Roman Kuzmitskii <damex.pp@icloud.com>
* firmware-utils: mkfwimage: fix memcpy and strncpy usagePetr Štetiar2020-07-111-9/+9
| | | | | | | | | | | | | | Firmware is binary blob, so there are barely any NULL terminated strings expected, so we should probably convert all chars into u8 types, and after that it's clear, that using strcpy doesn't make sense anymore. This is rather theoretical stuff, but `uint8_t name[PART_NAME_LENGTH]` means, that you can supply PART_NAME_LENGTH sized name, not PART_NAME_LENGTH-1 name when NULL terminated. Ref: https://github.com/openwrt/openwrt/pull/2274 Fixes: 04cb651376f9 ("firmware-utils: mkfwimage: fix more errors reported by gcc-6/7/9") Signed-off-by: Petr Štetiar <ynezz@true.cz>
* firmware-utils: mkfwimage: add support for Ubiquiti XC devicesRoger Pueyo Centelles2020-05-171-0/+9
| | | | | | | | This commit adds support for Ubiquiti devices based on the XC board type, such as the PowerBeam 5AC 500. The factory binary structure is the same as the WA type. Signed-off-by: Roger Pueyo Centelles <roger.pueyo@guifi.net>
* firmware-utils/mkfwimage: fix possible memory and resource leakAndrea Dalla Costa2020-01-141-0/+3
| | | | | | | | | Add missing calls to `free` for variable `mem`. Add missing call to `fclose` for variable `f`. The same changes were made in both `mkfwimage.c` and `mkfwimage2.c`. Signed-off-by: Andrea Dalla Costa <andrea@dallacosta.me>
* firmware-utils: mkfwimage: add support for Ubiquiti SW devicesTobias Schramm2020-01-121-0/+9
| | | | | | | | This commit adds support for Ubiquiti ToughSwitch XP (and probably also EdgeSwitch XP) devices. They are mostly based on the same hardware as MX devices. Signed-off-by: Tobias Schramm <tobleminer@gmail.com>
* ath79: generate firmware image for aircube-ispChristian Mauderer2019-12-311-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a "factory" image for the aircube-isp devices. Note that the firmware can't be uploaded without prior special preparation. For the most recent instructions on how to do that, visit the OpenWRT wiki page of the Ubiquiti airCube ISP for details: https://openwrt.org/toh/ubiquiti/ubiquiti_aircube_isp Current procedure: With the original firmware 2.5.0 it is possible to upload and execute a script via the configuration. To do that download and unpack the original configuration, adapt uhttpd config to execute another lua handler (placed in the config directory) and pack and upload it again. The lua handler can call a script that mounts an overlayfs and modifies the "fwupdate.real" binary so that an unsigned image is accepted. The overlayfs is necessary because a security system (called tomoyo) doesn't allow binaries in other locations than /sbin/fwupdate.real (and maybe some more) to access the flash when executed via network. A big thanks to Torvald Menningen (Snap) from the OpenWRT forum for finding out how to patch the binary so that it accepts an unsigned image. The current step-by-step procedure is: - Use a version 2.5.0 of the original firmware. This is important because a binary file will be modified. - Download a configuration. - Unpack it (it's just a tar gz file without an ending). - Add the following to uhttpd: `````` config 'uhttpd' 'other' list listen_http 0.0.0.0:8080 list listen_http [::]:8080 option 'home' '/tmp/persistent/config/patch/www' option lua_prefix '/lua' option lua_handler '/tmp/persistent/config/patch/handler.lua' `````` - Create a `patch` subfolder. - Create a `patch/www` subfolder. - Create a `patch/handler.lua` with the following content: `````` function handle_request(env) uhttpd.send("Status: 200 OK\r\n") uhttpd.send("Content-Type: text/plain\r\n\r\n") local command = "/bin/sh /tmp/persistent/config/patch/patch.sh 2>&1" local proc = assert(io.popen(command)) for line in proc:lines() do uhttpd.send(line.."\r\n") end proc:close() end `````` - Create a `patch/patch.sh` with the following content: `````` #!/bin/sh -x set -e set -u set -x UBNTBOX_PATCHED="/tmp/fwupdate.real" MD5FILE="/tmp/patchmd5" cat <<EOF > ${MD5FILE} c33235322da5baca5a7b237c09bc8df1 /sbin/fwupdate.real EOF # check md5 of files that will be patched if ! md5sum -c ${MD5FILE} then echo "******** Error when checking files. Refuse to do anything. ********" exit 0 fi # prepare some overlay functionality LOWERDIR="/tmp/lower_root" mkdir -p ${LOWERDIR} mount -t squashfs -oro /dev/mtdblock3 ${LOWERDIR} overlay_some_path() { PATH_TO_OVERLAY=$1 ALIAS=$2 UPPERDIR="/tmp/over_${ALIAS}" WORKDIR="/tmp/over_${ALIAS}_work" mkdir -p ${UPPERDIR} mkdir -p ${WORKDIR} mount -t overlay -o lowerdir=${LOWERDIR}${PATH_TO_OVERLAY},upperdir=${UPPERDIR},workdir=${WORKDIR} overlay ${PATH_TO_OVERLAY} } # patch the ubntbox binary. overlay_some_path "/sbin" "sbin" echo -en '\x10' | dd of=/sbin/fwupdate.real conv=notrunc bs=1 count=1 seek=24598 echo "******** Done ********" `````` - Repack the configuration. - Upload it via the normal web interface. - Wait about a minute. The webserver should restart. - Now there is a second web server at port 8080 which can call the lua script. Visit the page with a web browser. Link is for example http://192.168.1.1:8080/lua - You should see the output of the script with a "*** Done ***" at the end. Note that the patches are not permanent. If you restart the router you have to re-visit the link (but not re-upload the config). - Now you can upload an unsigned binary via the normal web interface. Signed-off-by: Christian Mauderer <oss@c-mauderer.de>
* firmware-utils: mkfwimage: fix build failure on macOS with gcc 9Petr Štetiar2019-07-191-2/+3
| | | | | | | | | | | | | | | | | Fixes following errors: src/mkfwimage.c:279:8: error: format specifies type 'long' but the argument has type 'off_t' (aka 'long long') [-Werror,-Wformat] d->stats.st_size, ^~~~~~~~~~~~~~~~ src/mkfwimage.c:280:8: error: format specifies type 'long' but the argument has type 'long long' [-Werror,-Wformat] d->partition_length - d->stats.st_size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/mkfwimage.c:378:6: error: format specifies type 'unsigned long' but the argument has type 'long long' [-Werror,-Wformat] d->stats.st_size - d->partition_length); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Reported-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk> Signed-off-by: Petr Štetiar <ynezz@true.cz>
* firmware-utils: mkfwimage: fix more errors reported by gcc-6/7/9Petr Štetiar2019-07-191-11/+12
| | | | | | | | | | | | | | | | | | | | | src/mkfwimage.c:276:8: error: format '%lld' expects argument of type 'long long int', but argument 4 has type '__off_t' {aka 'const long int'} [-Werror=format=] src/fw.h:71:36: error: format '%llu' expects argument of type 'long long unsigned int', but argument 6 has type '__off_t' {aka 'long int'} [-Werror=format=] inlined from 'main' at src/mkfwimage.c:543:12: /string_fortified.h:106:10: error: '__builtin_strncpy' output truncated before terminating nul copying 4 bytes from a string of the same length [-Werror=stringop-truncation] inlined from 'write_part' at src/mkfwimage.c:235:2, string_fortified.h:106:10: error: '__builtin_strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation] inlined from 'main' at src/mkfwimage.c:477:5: string_fortified.h:106:10: error: '__builtin_strncpy' specified bound 256 equals destination size [-Werror=stringop-truncation] inlined from 'main' at src/mkfwimage.c:496:5: string_fortified.h:106:10: error: '__builtin_strncpy' specified bound 4096 equals destination size [-Werror=stringop-truncation] inlined from 'main' at src/mkfwimage.c:481:5: string_fortified.h:106:10: error: '__builtin_strncpy' specified bound 4096 equals destination size [-Werror=stringop-truncation] inlined from 'main' at src/mkfwimage.c:485:5: string_fortified.h:106:10: error: '__builtin_strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation] Runtested on ath79 and UBNT Bullet M XW. Signed-off-by: Petr Štetiar <ynezz@true.cz>
* firmware-utils: mkfwimage: fix more errorsKevin Darbyshire-Bryant2019-07-191-4/+4
| | | | | | | | | Fix 4 errors reported by gcc 9 3 mismatched format type errors 1 unused variable error Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
* firmware-utils: mkfwimage: provide human readable errorPetr Štetiar2019-07-191-1/+7
| | | | | | | | | | | | | While looking at the ath25 build breakage of 19.07 images today I've encountered following error: mkfwimage -B XS5 -v [...] ath25-ubnt5-squashfs-sysupgrade.bin.new ERROR: Failed creating firmware layout description - error code: -2 Which is barely human readable and needs poking into the source code, so this patch makes the error more verbose and usable by mere mortals. Signed-off-by: Petr Štetiar <ynezz@true.cz>
* firmware-utils: mkfwimage: enable extra compiler checks and fix themPetr Štetiar2019-07-191-5/+4
| | | | | | | Let's enforce additional automatic checks enforced by the compiler in order to catch possible errors during compilation. Signed-off-by: Petr Štetiar <ynezz@true.cz>
* mkfwimage: Add image type definition for WA imagesTobias Schramm2018-10-071-47/+121
| | | | | | | | | | | | | This patch adds a new type of ubiquiti image, the WA image. First seen on the NanoStation AC loco the generic name implies that we will see this type of image on more ubiquiti devices thus it makes sense to implement it in mkfwimage. The main difference is that WA images are signed. The "END" header has been replaced by a "ENDS" header followed by a 2048 bit RSA signature. This signature is not being generated by mkfwimage and filled with 0x00. Signed-off-by: Tobias Schramm <tobleminer@gmail.com>
* firmware-utils: mkfwimage: fix firmware_max_length for XM layoutFelix Fietkau2016-02-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new u-boot version bundled with the 5.6.x firmwares from Ubiquiti gets confused by the smaller rootfs partition size; this can lead to various issues: 1. We've gotten reports that flashing from the 5.6.x stock firmware to OpenWrt will brick devices; I wasn't able to reproduce this myself 2. Flashing from 5.5.x stock firmware to OpenWrt and back to stock (via TFTP recovery), following by an update to 5.6.x via web interface can yield a bricked device with the following properties: - It can't be booted without entering commands over a serial console, as u-boot supplies the wrong MTD layout - The web interface won't accept any image with the original flash layout, so stock firmware upgrades are impossible - As the TFTP recovery doesn't update u-boot, returning to the old u-boot from firmware 5.5.x is impossible To recover from 2., creating an OpenWrt image which doesn't set u-boot as read-only and flashing a backup of the old u-boot from there is the only way known to me. (Fixing the mtdparts variable in u-boot-env from OpenWrt might also work; settings this from u-boot over serial didn't have any permanent effect.) Fix all of this by setting the correct flash layout also used by the stock firmware. Flashing has been tested from both firmware 5.5.x and 5.6.x. The fixed layout also matches the mtdparts defined by OpenWrt. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net> SVN-Revision: 48829
* ar71xx, firmware-utils: split ubdev01 flash layout from XMFelix Fietkau2016-02-291-0/+6
| | | | | | | | | The ubdev01 profile defines its own MTDPARTS with smaller firmware partition, so give it its own UBNT_BOARD in mkfwimage. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net> SVN-Revision: 48828
* firmware-utils: mkfwimage: add -Wall, fix obvious bugs causing compile warningsFelix Fietkau2016-02-291-7/+5
| | | | | | Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net> SVN-Revision: 48827
* mkfwimage: Increase RSPRO maximum size to 0xF00000 (15 MiB)Gabor Juhos2013-10-201-1/+1
| | | | | | | | | | | | | | | | | | | | | RSPRO has 16MiB of Flash, using the following layout: [ 2.930000] 0x000000000000-0x000000030000 : "RedBoot" [ 2.940000] 0x000000030000-0x000000130000 : "kernel" [ 2.950000] 0x000000130000-0x000000ff0000 : "rootfs" [ 2.960000] 0x000000ff0000-0x000000fff000 : "FIS directory" [ 2.970000] 0x000000fff000-0x000001000000 : "RedBoot config" Firmware images contain kernel and rootfs, so they can use up to 0xFF0000 - 0x30000 = 0xFC0000 (15,75MiB) of space. We don't include the RedBoot and FIS partitions and leave an extra 0xC0000 (768KiB) of space. This is based on revision 18410 which sets the limit to 0xB00000 (11 MiB). Signed-off-by: Bruno Randolf <br1@einfach.org> Signed-off-by: Gabor Juhos <juhosg@openwrt.org> SVN-Revision: 38484
* firmware-utils/mkfwimage: allow to override firmware magicGabor Juhos2012-02-181-5/+12
| | | | SVN-Revision: 30627
* mkfwimage: add support for the XM layout (bullet/rocket/nano M)Felix Fietkau2009-11-181-1/+7
| | | | SVN-Revision: 18448
* ar71xx: increase max size of RouterStation and RouterStation Pro firmware imagesGabor Juhos2009-11-131-2/+2
| | | | | | Thanks to riskable! (closes #5860) SVN-Revision: 18410
* firmware-utils/mkfwimage: add support for RouterStation Pro (patch from ↵Gabor Juhos2009-05-251-0/+6
| | | | | | Ubiquiti Networks) SVN-Revision: 16064
* Generate suitable images for the UBNT PicoStation2Jo-Philipp Wich2009-04-211-0/+6
| | | | SVN-Revision: 15314
* create firmware image for the Ubiquiti LS-SR71 boardGabor Juhos2009-03-141-0/+6
| | | | SVN-Revision: 14874
* firmware-utils/mkfwimage: update RouterStation specific values, adn remove ↵Gabor Juhos2009-02-041-14/+2
| | | | | | some unused code SVN-Revision: 14404
* firmware-utils/mkfwimage: fix root_start valuesGabor Juhos2009-01-051-2/+2
| | | | SVN-Revision: 13874
* firmware-utils/mkfwimage: fix Ubiquiti firmware generation (closes #4414)Gabor Juhos2009-01-041-5/+5
| | | | SVN-Revision: 13859
* firmware-utils/mkfwimage: add RouterStation support (based on a patch by ↵Gabor Juhos2008-12-181-14/+71
| | | | | | Jonas <jonas at ubnt.com>) SVN-Revision: 13682
* fix mkfwimage to recognize the -s optionTravis Kemen2008-07-281-1/+1
| | | | SVN-Revision: 11978
* fix mkfwimage build on mac os xFelix Fietkau2008-07-261-1/+1
| | | | SVN-Revision: 11947
* Use mkfwimage from athero.openwrt.net with modification for XS2 devices. Add ↵Travis Kemen2008-07-251-77/+74
| | | | | | back in ubiquiti image generation. SVN-Revision: 11920
* buld images for the Ubiquiti LiteStation and NanoStation ported from ↵Travis Kemen2008-05-071-0/+394
http://atheros.openwrt.net. Tested on a Nanostation 2 with airos 3 SVN-Revision: 11061