openwrt/target/linux
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
..
apm821xx apm821xx: mbl_gen_hdd_img.sh: switch to /bin/sh 2019-12-31 01:28:08 +01:00
ar7 kernel: bump 4.9 to 4.9.207 2019-12-24 18:04:32 +01:00
ar71xx kernel: bump 4.14 to 4.14.159 2019-12-24 01:22:45 +01:00
arc770 arc770: gen_axs10x_sdcard_img.sh: switch to /bin/sh 2019-12-31 01:27:32 +01:00
archs38 archs38: gen_axs10x_sdcard_img.sh: switch to /bin/sh 2019-12-31 01:26:35 +01:00
armvirt treewide: Remove self from MAINTAINER entries 2019-12-23 13:18:04 -08:00
at91 at91: gen_at91_sdcard_img.sh: switch to /bin/sh 2019-12-31 01:25:44 +01:00
ath25 ath25: split up DEVICE_TITLE 2019-10-19 13:16:57 +02:00
ath79 ath79: generate firmware image for aircube-isp 2019-12-31 01:42:13 +01:00
bcm53xx bcm53xx: sysupgrade: support Luxul NAND devices 2019-10-15 20:23:04 +02:00
brcm47xx brcm47xx: add switch configuration for WNR3500L 2019-12-08 00:21:36 +01:00
brcm63xx kernel: bump 4.19 to 4.19.85 2019-11-22 16:56:46 +01:00
brcm2708 brcm2708: gen_rpi_sdcard_img.sh: use /bin/sh 2019-12-31 01:24:31 +01:00
cns3xxx kernel: bump 4.19 to 4.19.86 2019-11-29 09:59:49 +01:00
gemini gemini: dns313_gen_hdd_img.sh: switch to /bin/sh 2019-12-31 01:23:24 +01:00
generic Revert "kernel: fix kmemleak warnings introduced in 305-mips_module_reloc.patch" 2019-12-27 19:47:41 +01:00
imx6 kernel: Deactivate CONFIG_SFP in generic config 2019-12-23 15:25:36 +01:00
ipq40xx ipq40xx: build DEVICE_DTS based on SOC and device name 2019-12-27 18:00:15 +01:00
ipq806x ipq806x: build DEVICE_DTS based on SOC and device name 2019-12-27 18:00:32 +01:00
ixp4xx kernel: bump 4.9 to 4.9.207 2019-12-24 18:04:32 +01:00
kirkwood kirkwood: remove CONFIG_LEGACY_PTY from kernel config 2019-12-09 20:14:20 +01:00
lantiq kernel: bump 4.19 to 4.19.90 2019-12-24 15:34:43 +01:00
layerscape layerscape: gen_sdcard_head_img.sh: switch to /bin/sh 2019-12-31 01:22:01 +01:00
malta treewide: Remove self from MAINTAINER entries 2019-12-23 13:18:04 -08:00
mediatek mediatek: gen_mt7623_emmc_img.sh: use /bin/sh 2019-12-31 01:20:59 +01:00
mpc85xx mpc85xx: add support for Enterasys WS-AP3710i 2019-12-13 22:40:19 +01:00
mvebu mvebu: gen_mvebu_sdcard_img.sh: use /bin/sh 2019-12-31 01:13:59 +01:00
mxs mxs: gen_sdcard_ext4_ext4.sh: use /bin/sh 2019-12-31 01:19:48 +01:00
octeon octeon: fix sysupgrade 2019-11-30 20:19:12 +02:00
octeontx kernel: bump 4.14 to 4.14.160 2019-12-24 17:45:54 +01:00
omap omap: gen_omap_sdcard_img.sh: use /bin/sh 2019-12-31 01:17:09 +01:00
orion orion: replace backticks by $(...) 2019-09-29 00:46:13 +02:00
oxnas kernel: bump 4.14 to 4.14.158 2019-12-10 09:50:42 +01:00
pistachio pistachio: split up DEVICE_TITLE 2019-10-12 23:37:00 +02:00
ramips ramips: add LED trigger for TL-WR902AC v3 WAN LED 2019-12-30 15:09:30 +01:00
rb532 rb532: gen_image.sh: use /bin/sh 2019-12-31 01:16:17 +01:00
samsung samsung: split up DEVICE_TITLE 2019-09-11 15:17:09 +02:00
sunxi sunxi: gen_sunxi_sdcard_img.sh: switch to /bin/sh 2019-12-31 01:15:25 +01:00
tegra x86,tegra,mvebu: image: use common reproducible IMG_PART_SIGNATURE 2019-11-11 16:37:13 +01:00
uml treewide: Remove self from MAINTAINER entries 2019-12-23 13:18:04 -08:00
x86 kernel: bump 4.19 to 4.19.90 2019-12-24 15:34:43 +01:00
zynq zynq: gen_zynq_sdcard_img.sh: switch to /bin/sh 2019-12-31 01:14:48 +01:00
Makefile