summaryrefslogtreecommitdiff
path: root/Makefile
blob: a88f8f572d0fa4319b6a730ff98ffe27426cd48d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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

all: fw.tar

version: dcs8000lh-configure.py
	sed -ne 's/"//g' -e 's/^VERSION *= *//p' dcs8000lh-configure.py >$@

opt.squashfs: $(FILES)
	mksquashfs $(FILES) $@ -all-root -comp xz

aes.key:
	openssl rand 16 > $@

aes.key.rsa: aes.key $(PRIKEY)
	openssl rsautl -encrypt -in aes.key -inkey $(PRIKEY) -out $@

### FIXME:  This is verified using the pubkey in /etc/db/verify.key, which will fail
sign.sha1.rsa: sign.sha1 $(SIGNKEY)
	openssl rsautl -sign -inkey $(SIGNKEY) -out sign.sha1.rsa -in sign.sha1

$(SIGNKEY):
	openssl genrsa -out $(SIGNKEY)

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 $@ $^

update.sha1: update.aes
	 openssl dgst -sha1 $^ | cut -d' ' -f2 > $@

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
	$(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

certificate.info:
	echo "Publisher:DMdssdFW1" >$@
	echo "Supported Models:$(MODEL),$(MODEL)" >>$@
	echo "Firmware Version:1.0.0" >>$@
	echo "Target:update.bin" >>$@
	echo "Build No:$(BUILD)" >>$@
	echo "Contents:update" >>$@

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

distclean: clean
	rm aes.key