openwrt/tools
Christian Mauderer 5e5e92b7c3 ath79: generate firmware image for aircube-isp
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>
2019-12-31 01:42:13 +01:00
..
autoconf treewide: clean up download hashes 2016-12-16 22:39:22 +01:00
automake tools/automake: Revert "Do not use $(V) - force AM_V=1" 2019-11-06 00:21:15 +01:00
b43-tools tools/b43-tools/b43-fwsquash: convert to Python 3 with 2-to-3 2019-07-26 08:09:16 +02:00
bc Revert "bc: update to 1.07.1" 2019-05-22 21:27:44 +02:00
bison tools/bison: Update to 3.4.1 2019-06-22 10:23:56 +02:00
cbootimage tools: add cbootimage for tegra 2019-04-06 14:48:46 +02:00
cbootimage-configs tools: add cbootimage-configs for tegra 2019-04-06 14:48:46 +02:00
ccache ccache: update to 3.7.6 2019-11-24 21:48:54 +01:00
cmake tools/cmake: Update to 3.15.1 2019-09-01 18:38:05 +02:00
coreutils tools/coreutils: install "touch" 2019-09-25 10:19:24 +02:00
dosfstools add PKG_CPE_ID ids to package and tools 2017-11-17 02:24:35 +01:00
e2fsprogs tools/e2fsprogs: Update to version 1.45.4 2019-10-08 21:51:08 +02:00
elftosb treewide: clean up download hashes 2016-12-16 22:39:22 +01:00
expat tools/expat: change package source to GitHub 2019-11-24 23:17:34 +01:00
findutils tools: findutils: fix compilation with glibc 2.28 2018-08-10 06:29:49 +02:00
firmware-utils ath79: generate firmware image for aircube-isp 2019-12-31 01:42:13 +01:00
flex flex: Add a lex symlink 2018-11-25 19:23:03 +01:00
flock tools: flock: add NFSv4 compatibility 2016-08-11 10:50:10 +02:00
genext2fs treewide: clean up download hashes 2016-12-16 22:39:22 +01:00
gengetopt tools/gengetopt: Update to 2.23 2019-07-08 16:42:26 +02:00
gmp tools: gmp: Update to 6.1.2 2017-01-03 14:24:33 +01:00
include tools: Update endian definitions for Mac OSX 2018-12-19 15:08:30 +00:00
isl tools/isl: update to 0.20 2019-02-26 23:20:04 +01:00
kernel2minor tools: kernel2minor: update to latest version 2018-07-12 18:15:33 +02:00
libelf tools: libelf: fix headers to trigger -Wundef warnings 2019-09-03 10:44:21 +02:00
libressl tools: libressl: fix compilation for non-glibc clib (FS#2400) 2019-07-23 14:54:07 +02:00
libtool add PKG_CPE_ID ids to package and tools 2017-11-17 02:24:35 +01:00
lzma treewide: clean up download hashes 2016-12-16 22:39:22 +01:00
lzma-old tools/zlib: move zlib build to tools 2018-04-28 15:28:59 +02:00
m4 tools: m4: fix compilation with glibc 2.28 2018-08-10 06:29:32 +02:00
make-ext4fs make-ext4fs: update to HEAD of 2017-05-29 - eebda1 2019-08-24 23:18:12 +02:00
missing-macros tools: remove a bunch of unused automake macros 2015-03-17 10:11:00 +00:00
mkimage tools/mkimage: Update U-Boot to version 2019.07 2019-09-04 22:35:22 +02:00
mklibs tools/mklibs: update to 0.1.44 and convert to Python 3 2019-07-26 23:50:21 +02:00
mm-macros tools/mm-macros: Update to 0.9.12 2018-05-05 07:13:48 +02:00
mpc tools/mpc: Update to 1.1.0 2018-01-18 08:04:18 +01:00
mpfr tools/mpfr: Update to 4.0.2 2019-02-10 20:51:09 +01:00
mtd-utils tools/mtd-utils: update to 2.1.1 2019-08-27 10:32:44 +02:00
mtools tools/mtools: Update to 4.0.23 2018-12-24 17:05:57 +01:00
padjffs2 tools: padjffs2: add option to output padding data to stdout 2016-07-11 13:26:33 +02:00
patch tools/patch: apply upstream patch for cve-2019-13638 2019-08-13 10:00:10 +02:00
patch-image tools: patch-image: fix file descriptor leak. 2017-02-15 07:45:24 +01:00
patchelf treewide: clean up download hashes 2016-12-16 22:39:22 +01:00
pkg-config tools/pkg-config: Handle variable substitution of 'bindir' to redirect to STAGING_DIR/bin 2018-11-13 15:40:30 -05:00
qemu tools: qemu: Add patches to support adapter_type and monolithicFlat 2019-12-23 00:22:06 +01:00
quilt tools/quilt: update to 0.66 2019-11-24 21:35:45 +01:00
sdimage tools/sdimage: Fix build with host Linux headers < 3.18 2018-12-16 14:03:35 +01:00
sed tools/sed: Update to 4.7 2019-02-10 20:48:25 +01:00
sparse sparse: updated to version 0.5.2 2018-06-08 09:56:26 +02:00
squashfs add PKG_CPE_ID ids to package and tools 2017-11-17 02:24:35 +01:00
squashfskit4 tools/squashfskit: fix version detection on non-linux system 2019-03-03 19:45:10 +01:00
sstrip tools/sstrip: Fix compile under standard linux. 2017-12-08 10:40:20 +01:00
tar tools: tar: update to version 1.32 2019-03-10 21:36:28 +01:00
upslug2 upslug2: Update to git repository 2019-09-03 11:56:47 +02:00
wrt350nv2-builder tools: remove static linking support 2015-02-06 00:00:43 +00:00
xz tools/xz: Compile with PIC to fix linking errors 2019-04-06 19:14:06 +02:00
zip tools: zip: add option for reproducible archives 2019-01-15 19:11:53 +01:00
zlib tools: zlib: do not hardcode the install prefix in zlib.pc 2018-05-24 17:07:10 +02:00
Makefile rules.mk: remove "$(STAGING_DIR)/include" 2019-11-02 20:51:56 +01:00