-
Notifications
You must be signed in to change notification settings - Fork 1
/
moduleinfo.mk
89 lines (76 loc) · 2.97 KB
/
moduleinfo.mk
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
include macros.mk
include verbose.mk
include platform.mk
include version.mk
CRC = crc32
XXD = xxd
crc32_path := $(shell which $(CRC))
ifeq ("$(crc32_path)", "")
$(error "$(CRC) tool is not found")
endif
.PHONY: module, prefix, suffix
# generated by running xxd -p crc_block
CRC_LEN = 4
CRC_BLOCK_LEN = 38
DEFAULT_SHA_256 = 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20
MOD_INFO_SUFFIX_LEN ?= 2800
MOD_INFO_SUFFIX = $(DEFAULT_SHA_256)$(MOD_INFO_SUFFIX_LEN)
CRC_BLOCK_CONTENTS = $(MOD_INFO_SUFFIX)78563412
# OS X + debian systems have shasum, RHEL + windows have sha256sum
SHASUM_COMMAND_VERSION := $(shell shasum --version 2>/dev/null)
SHA256SUM_COMMAND_VERSION := $(shell sha256sum --version 2>/dev/null)
ifdef SHASUM_COMMAND_VERSION
SHA_256 = shasum -a 256
else ifdef SHA256SUM_COMMAND_VERSION
SHA_256 = sha256sum
else ifeq (WINDOWS,$(MAKE_OS))
SHA_256 = $(COMMON_BUILD)/bin/win32/sha256sum
endif
OUT=build/$(PROJECT_NAME)
BIN=$(OUT).bin
MODULE=$(OUT)@$(FIRMWARE_VERSION).bin
PREFIX=$(OUT).prefix
SUFFIX=$(OUT).suffix
CP=cp
# all of these are in hex, little-endian
START_ADDR=00000000 # not used
END_ADDR=00000000 # not used
NCP_ID=21 # 33 (see hal/src/hRF52840/platform_ncp.h)
RESERVED2=00 # not used
ifeq ("$(PLATFORM)","argon")
PLATFORM_ID=0C00 # 12 - Argon
else ifeq ("$(PLATFORM)","tracker")
PLATFORM_ID=1A00 # 26 - Tracker
else
$(error Unknown platform!)
endif
MODULE_FUNCTION=07 # third party mono firmware
MODULE_INDEX=00 # not used with mono firmware
MODULE_PREFIX=$(START_ADDR)$(END_ADDR)$(NCP_ID)$(RESERVED2)$(MODULE_VERSION_LE)$(PLATFORM_ID)$(MODULE_FUNCTION)$(MODULE_INDEX)$(MODULE_DEPENDENCY)$(MODULE_DEPENDENCY2)
# regular MCU firmware has the product ID stored before the suffix
# since this has little relevance here we don't bother
RESERVED_U16=0000
DEFAULT_SHA_256=0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20
SUFFIX_SIZE=2400 # 36
CRC32=00000000
MODULE_SUFFIX=$(RESERVED_U16)$(DEFAULT_SHA_256)$(SUFFIX_SIZE)
MODULE_SUFFIX_PLUS_PREFIX_SIZE=60
prefix:
# patch the end address with the length of the file
# build the default prefix using static data
# use perl to convert the filesize into hex and make little endian
# xxd to convert this to binary and write in place to offset 4 in the file
echo $(MODULE_PREFIX) | xxd -r -p > $(PREFIX)
echo "print scalar reverse unpack \"h*\", pack \"H*\", sprintf(\"%08X\"," $(shell expr $(call filesize,$(BIN)) + $(MODULE_SUFFIX_PLUS_PREFIX_SIZE)) ")" | perl -l | \
$(XXD) -r -p | \
dd bs=1 of=$(PREFIX) seek=4 conv=notrunc $(VERBOSE_REDIRECT)
suffix:
echo "$(MODULE_SUFFIX)" | xxd -r -p > $(SUFFIX)
$(SHA_256) $(BIN) | cut -c 1-65 | $(XXD) -r -p | dd bs=1 of=$(SUFFIX) seek=2 conv=notrunc $(VERBOSE_REDIRECT)
cat $(PREFIX) $(BIN) $(SUFFIX) > $(MODULE)
$(CRC) $(MODULE) | cut -c 1-10 | $(XXD) -r -p | dd bs=1 of=$(SUFFIX) seek=36 conv=notrunc $(VERBOSE_REDIRECT)
module: prefix suffix
$(call echo,"Making module from binary")
cat $(PREFIX) $(BIN) $(SUFFIX) > $(MODULE)
module-clean:
rm -f $(MODULE)