forked from SrPatinhas/smarthalo-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sh2.mk
69 lines (55 loc) · 3.44 KB
/
sh2.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
# This Makefile is called within the Docker environment
# It should be used for building the firmware binaries
# Configure as required here
CHIP=nrf52832_xxaa
FAMILY=NRF52
SD_TYPE=s132
SD_VERSION=7.0.1
SD_FWID=0xCB
SDK_ROOT=/nrf5/nRF5_SDK_16.0.0
# Directories used to store files
TEMP_DIR = tmp
ARTEFACTS_DIR = artefacts
APP_MK_DIR = smart_halo-smarthalo2-nrf-firmware-951fd67f143c/Code/Firmware/shapp
BOOT_MK_DIR = smart_halo-smarthalo2-nrf-firmware-951fd67f143c/Code/Firmware/shbootloader
# Files generated as part of the build process
APPLICATION = $(APP_MK_DIR)/_build_$(COMBINED_PRODUCT_HARDWARE_VERSION)/$(CHIP).hex
BOOTLOADER = $(BOOT_MK_DIR)/_build_$(COMBINED_PRODUCT_HARDWARE_VERSION)/$(CHIP)_$(SD_TYPE).hex
SOFTDEVICE = $(SDK_ROOT)/components/softdevice/$(SD_TYPE)/hex/$(SD_TYPE)_nrf52_$(SD_VERSION)_softdevice.hex
BL_SETTINGS = $(TEMP_DIR)/bootloadersettings.hex
# Human-readable identifier for artefacts
VERSION_IDENTIFIER = $(PRODUCT_ID).$(PCBVER)
# Combined version is a single number which combines both the Product ID and PCB revision. Useful for bootloader hardware version number...
A = $(PRODUCT_ID)
B = $(PCBVER)
COMBINED_PRODUCT_HARDWARE_VERSION=$(shell echo $$(($A*256+$B)))
# Identify the number of processors present on the build machine. Use this to set the number of jobs for best performance.
NUMPROC := $(shell grep -c "processor" /proc/cpuinfo)
ifeq ($(NUMPROC),0)
NUMPROC = 1
endif
NUMJOBS := $(shell echo $$(($(NUMPROC)*2)))
.PHONY: all clean
all:
mkdir -p $(TEMP_DIR)
@echo "project.mk is building for $(PRODUCT_NAME) with PRODUCT_ID=$(PRODUCT_ID), PCBVER=$(PCBVER)"
# Build the sub-projects
make -j$(NUMJOBS) PASS_LINKER_INPUT_VIA_FILE=0 SDK_ROOT=$(SDK_ROOT) OUTPUT_DIRECTORY=_build_$(COMBINED_PRODUCT_HARDWARE_VERSION) -C $(APP_MK_DIR)
make -j$(NUMJOBS) PASS_LINKER_INPUT_VIA_FILE=0 SDK_ROOT=$(SDK_ROOT) OUTPUT_DIRECTORY=_build_$(COMBINED_PRODUCT_HARDWARE_VERSION) COMBINED_PRODUCT_HARDWARE_VERSION=$(COMBINED_PRODUCT_HARDWARE_VERSION) -C $(BOOT_MK_DIR)
# Make the artefacts directory if it does not exist
mkdir -p $(ARTEFACTS_DIR)
# Build the DFU package from the app
nrfutil pkg generate --hw-version $(COMBINED_PRODUCT_HARDWARE_VERSION) --application-version 1 --application $(APPLICATION) --sd-req $(SD_FWID) --key-file private.pem $(ARTEFACTS_DIR)/dfu-$(VERSION_IDENTIFIER).zip
# Merge hex files to form a complete package
# In order to boot into the app immediately after flashing, the bootloader's settings page needs to be written
nrfutil settings generate --family $(FAMILY) --application $(APPLICATION) --application-version 0 --bootloader-version 0 --bl-settings-version 1 $(BL_SETTINGS)
srec_cat $(SOFTDEVICE) -intel $(APPLICATION) -intel $(BOOTLOADER) -intel $(BL_SETTINGS) -intel -o $(ARTEFACTS_DIR)/img-$(VERSION_IDENTIFIER).hex -intel -address-length=4
# For convenience, store this hex file as our latest successful build
cp $(ARTEFACTS_DIR)/img-$(VERSION_IDENTIFIER).hex latest.hex
clean:
@echo "project.mk is cleaning for $(PRODUCT_NAME) with PRODUCT_ID=$(PRODUCT_ID), PCBVER=$(PCBVER)"
make SDK_ROOT=$(SDK_ROOT) OUTPUT_DIRECTORY=_build_$(COMBINED_PRODUCT_HARDWARE_VERSION) -C $(APP_MK_DIR) clean
make SDK_ROOT=$(SDK_ROOT) OUTPUT_DIRECTORY=_build_$(COMBINED_PRODUCT_HARDWARE_VERSION) -C $(DTM_MK_DIR) clean
make SDK_ROOT=$(SDK_ROOT) OUTPUT_DIRECTORY=_build_$(COMBINED_PRODUCT_HARDWARE_VERSION) -C $(BOOT_MK_DIR) clean
rm -f $(ARTEFACTS_DIR)/img-$(VERSION_IDENTIFIER).hex
rm -f $(ARTEFACTS_DIR)/dfu-$(VERSION_IDENTIFIER).zip