summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2019-05-12 11:04:57 +0200
committerBjørn Mork <bjorn@mork.no>2019-05-12 11:04:57 +0200
commit5efffeea3d37803b528a21ce1213029340a20373 (patch)
tree2a4575837f979be88d0a75f30ef10bf438151842
parenta8cc3f324dba617551bb091c7cf4dcde1c9eea17 (diff)
WiP: fw generation sort-of working
Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rw-r--r--Makefile36
-rw-r--r--update.sh14
2 files changed, 32 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index a88f8f5..ba043cd 100644
--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,21 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2019 Bjørn Mork <bjorn@mork.no>
-FILES=version opt.local
-PRIKEY=PriKey.pem
-SIGNKEY=signkey.pem
MODEL=DCS-8000LH
BUILD=9999
+PRIKEY=keys/$(MODEL)-PriKey.pem
+SIGNKEY=keys/$(MODEL)-sign.pem
-all: fw.tar
+OPTFILES=version opt.local
+FW_XTRA_FILES=
+
+all: fw
version: dcs8000lh-configure.py
sed -ne 's/"//g' -e 's/^VERSION *= *//p' dcs8000lh-configure.py >$@
-opt.squashfs: $(FILES)
- mksquashfs $(FILES) $@ -all-root -comp xz
+opt.squashfs: $(OPTFILES)
+ mksquashfs $(OPTFILES) $@ -all-root -comp xz
aes.key:
openssl rand 16 > $@
@@ -25,14 +27,22 @@ aes.key.rsa: aes.key $(PRIKEY)
sign.sha1.rsa: sign.sha1 $(SIGNKEY)
openssl rsautl -sign -inkey $(SIGNKEY) -out sign.sha1.rsa -in sign.sha1
+## FIXME: It would be nice to have the D-Link signing key instead :-)
$(SIGNKEY):
- openssl genrsa -out $(SIGNKEY)
+ echo "WARNING: $(SIGNKEY) is missing - using a new abitrary key instead"
+ $(eval SIGNKEY := random-signkey.pem)
+ $(eval FW_XTRA_FILES := $(FW_XTRA_FILES) verify.key)
+ [ -f $(SIGNKEY) ] || openssl genrsa -out $(SIGNKEY)
+
+verify.key: $(SIGNKEY)
+ openssl rsa -pubout -in $(SIGNKEY) -out $@
sign.sha1: update.bin.aes aes.key.rsa certificate.info update.sha1
cat $^ | openssl dgst -sha1 | cut -d' ' -f2 > $@
-fw.tar: certificate.info aes.key.rsa sign.sha1.rsa update.aes update.bin.aes
- tar cvf $@ $^
+fw: verify.key fw.tar
+fw.tar: certificate.info aes.key.rsa sign.sha1.rsa update.aes update.bin.aes $(FW_XTRA_FILES)
+ tar cvf $@ $^ $(FW_XTRA_FILES)
update.sha1: update.aes
openssl dgst -sha1 $^ | cut -d' ' -f2 > $@
@@ -40,9 +50,9 @@ update.sha1: update.aes
update.aes: aes.key opt.squashfs
openssl aes-128-cbc -md md5 -kfile aes.key -nosalt -e -out $@ -in opt.squashfs
-update.bin: update.aes
+update.bin: aes.key update.aes update.sh
$(eval MD5SUM := $(shell openssl aes-128-cbc -md md5 -kfile aes.key -nosalt -d -in update.aes | md5sum - | cut -d' ' -f1 | md5sum - | cut -d' ' -f1))
- sed -i -e "s/^MD5SUM=.*/MD5SUM=\"$(MD5SUM)\"/" -e "s/^VERSION=\"1.0.0-.*/VERSION=\"1.0.0-$(BUILD)\"/" update.bin
+ sed -e "s/@@MODEL@@/\"$(MODEL)\"/" -e "s/@@MD5SUM@@/\"$(MD5SUM)\"/" -e "s/@@VERSION@@/\"1.0.0-$(BUILD)\"/" update.sh >update.bin
certificate.info:
echo "Publisher:DMdssdFW1" >$@
@@ -56,8 +66,8 @@ update.bin.aes: aes.key update.bin
openssl aes-128-cbc -md md5 -kfile aes.key -nosalt -e -out $@ -in update.bin
clean:
- rm *.rsa *.aes opt.squashfs sign.sha1
+ rm -f *.rsa *.aes opt.squashfs sign.sha1 certificate.info update.bin update.sha1 fw.tar
distclean: clean
- rm aes.key
+ rm -f aes.key random-signkey.pem
diff --git a/update.sh b/update.sh
index dc8faca..abc6ad0 100644
--- a/update.sh
+++ b/update.sh
@@ -3,9 +3,9 @@ VENDOR="Alphanetworks"
HWBOARD="r8000lh"
HWVERSION="1.0.0"
OEM="D-Link"
-MODEL="DCS-8000LH"
+MODEL=@@MODEL@@
PRODUCT="Internet Camera"
-VERSION="1.0.0-9999"
+VERSION=@@VERSION@@
PACKAGE=""
WIRELESS_MODULE="RTL8723BU"
DESCRIPT="An alternative opt."
@@ -19,7 +19,7 @@ It will update following, ...
"
}
-MD5SUM="acf7f6c0881b64f53018a26dd3e3b8c0"
+MD5SUM=@@MD5SUM@@
MECH_SIGN="QPAT"
MECH_VERSION="1.0"
@@ -32,7 +32,7 @@ showUsage() {
exam() {
rm -f /tmp/update/md5
for i in $(cat /tmp/update/certificate.info | grep Contents | cut -d":" -f2); do
- echo $(tar xOf "$1" $i.aes | openssl aes-128-cbc -k `cat /tmp/update/aes.key` -nosalt -d | md5sum - | cut -d' ' -f1 ) >> /tmp/update/md5
+ echo $(tar xOf "$1" $i.aes | openssl aes-128-cbc -kfile /tmp/update/aes.key -nosalt -d | md5sum - | cut -d' ' -f1 ) >> /tmp/update/md5
done
md5sum=$(md5sum /tmp/update/md5 | cut -d' ' -f1)
[ "$MD5SUM" = "$md5sum" ] && return 0
@@ -84,7 +84,11 @@ if [ "$action" = "update" ]; then
exam "$enc_bin" || { /etc/rc.d/init.d/services.sh start > /dev/null 2> /dev/null && exit 1; }
userdata="/dev/$(grep '"userdata"' /proc/mtd |cut -f1 -d:)"
- tar xOf "$enc_bin" update.aes | openssl aes-128-cbc -k `cat /tmp/update/aes.key` -nosalt -d | dd of="$userdata" > /dev/null 2> /dev/null || exit 1
+ size=$(grep '"userdata"' /proc/mtd |cut -f2 -d\ )
+ blocksize=$(grep '"userdata"' /proc/mtd |cut -f3 -d\ )
+ blocks=$(( 0x${size} / 0x${blocksize} ))
+ /usr/bin/flash_erase "$userdata" 0 ${blocks}
+ tar xOf "$enc_bin" update.aes | openssl aes-128-cbc -k `cat /tmp/update/aes.key` -nosalt -d | dd bs=$((0x${blocksize})) of="$userdata" > /dev/null 2> /dev/null || exit 1
{(sleep 5 && reboot) > /dev/null 2> /dev/null &}
exit 0