Skip to content

Commit

Permalink
Puck.js/Jolt.js: Ensure that firmware update ZIPs *do not* perform a …
Browse files Browse the repository at this point in the history
…self test at boot until they pass (only hex files that are used at the factory do)
  • Loading branch information
gfwilliams committed Jul 4, 2024
1 parent eacd006 commit 1efcb1c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Fix for unexpected power draw on newest batch of Bangle.js devices
Puck.js: skip CRT startup code to save ~300b
Fix memory leak when using Pin.getInfo on a pin with ADCs (and non-reporting of analogs)
Puck.js/Jolt.js: Ensure that firmware update ZIPs *do not* perform a self test at boot until they pass (only hex files that are used at the factory do)

2v23 : Fix XON/OFF thresholds to be based off the correct buffer size
Bangle.js2: Added BANGLE2_IFLASH target for firmware using internal flash for js files (currently only partially working)
Expand Down
11 changes: 10 additions & 1 deletion libs/joltjs/jswrap_jolt.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,14 @@ void jswrap_jolt_hwinit() {
void jswrap_jolt_init() {
/* If the button is pressed during reset, perform a self test.
* With bootloader this means apply power while holding button for >3 secs */
bool firstStart = jsiStatus & JSIS_FIRST_BOOT; // is this the first time jswrapjolt_init was called?
bool firstStart = jsiStatus & JSIS_FIRST_BOOT; // is this the first time jswrap_jolt_init was called?
/** If we're NOT doing a DFU update build (eg we're making a full a hex file)
then ensure that the firmware keeps doing a self test until it passes (eg it'll
output 5 red flashes for fail or 5 green for pass). If we're a firmware update
package don't do that as the device might be connected to something which will
make the test keep failing. */
bool firstRunAfterFlash = false;
#ifndef DFU_UPDATE_BUILD
uint32_t firstStartFlagAddr = FLASH_SAVED_CODE_START-4;
if (firstStart) {
// check the 4 bytes *right before* our saved code. If these are 0xFFFFFFFF
Expand All @@ -611,12 +617,14 @@ void jswrap_jolt_init() {
firstRunAfterFlash = true;
}
}
#endif

if (firstStart && (jshPinGetValue(BTN1_PININDEX) == BTN1_ONSTATE || firstRunAfterFlash)) {
// don't do it during a software reset - only first hardware reset
// if we're doing our first run after being flashed with new firmware, we set the advertising name
// up to say PASS or FAIL, to work with the factory test process.
bool result = _jswrap_jolt_selfTest(firstRunAfterFlash);
#ifndef DFU_UPDATE_BUILD
// if we passed, set the flag in flash so we don't self-test again
if (firstRunAfterFlash && result) {
uint32_t buf = 0;
Expand All @@ -625,6 +633,7 @@ void jswrap_jolt_init() {
jshFlashWrite(&buf, firstStartFlagAddr, 4);
jsfSetFlag(JSF_UNSAFE_FLASH, oldFlashStatus);
}
#endif
// green if good, red if bad
Pin indicator = result ? LED2_PININDEX : LED1_PININDEX;
int i;
Expand Down
10 changes: 9 additions & 1 deletion libs/puckjs/jswrap_puck.c
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,13 @@ void jswrap_puck_init() {
/* If the button is pressed during reset, perform a self test.
* With bootloader this means apply power while holding button for >3 secs */
bool firstStart = jsiStatus & JSIS_FIRST_BOOT; // is this the first time jswrap_puck_init was called?
/** If we're NOT doing a DFU update build (eg we're making a full a hex file)
then ensure that the firmware keeps doing a self test until it passes (eg it'll
output 5 red flashes for fail or 5 green for pass). If we're a firmware update
package don't do that as the device might be connected to something which will
make the test keep failing. */
bool firstRunAfterFlash = false;
#ifndef DFU_UPDATE_BUILD
uint32_t firstStartFlagAddr = FLASH_SAVED_CODE_START-4;
if (firstStart) {
// check the 4 bytes *right before* our saved code. If these are 0xFFFFFFFF
Expand All @@ -1745,12 +1751,13 @@ void jswrap_puck_init() {
firstRunAfterFlash = true;
}
}

#endif
if (firstStart && (jshPinGetValue(BTN1_PININDEX) == BTN1_ONSTATE || firstRunAfterFlash)) {
// don't do it during a software reset - only first hardware reset
// if we're doing our first run after being flashed with new firmware, we set the advertising name
// up to say PASS or FAIL, to work with the factory test process.
bool result = _jswrap_puck_selfTest(firstRunAfterFlash);
#ifndef DFU_UPDATE_BUILD
// if we passed, set the flag in flash so we don't self-test again
if (firstRunAfterFlash && result) {
uint32_t buf = 0;
Expand All @@ -1759,6 +1766,7 @@ void jswrap_puck_init() {
jshFlashWrite(&buf, firstStartFlagAddr, 4);
jsfSetFlag(JSF_UNSAFE_FLASH, oldFlashStatus);
}
#endif
// green if good, red if bad
Pin indicator = result ? LED2_PININDEX : LED1_PININDEX;
int i;
Expand Down
32 changes: 17 additions & 15 deletions make/common/NRF5X.make
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ $(info $(shell BOARD=$(BOARD) RELEASE=1 BOOTLOADER=1 make))
$(info RUNNING MAKE CLEAN)
$(info $(shell BOARD=$(BOARD) RELEASE=1 make clean))
$(info *************************************************************)
$(info BOOTLOADER BUILD COMPLETE)
$(info BOOTLOADER BUILD COMPLETE)
$(info *************************************************************)
endif
endif
endif
endif
endif #BOOTLOADER
endif #USE_BOOTLOADER
else #DFU_UPDATE_BUILD
DEFINES += -DDFU_UPDATE_BUILD
endif #DFU_UPDATE_BUILD

# Just try and get rid of the compile warnings.
Expand All @@ -36,10 +38,10 @@ INCLUDE += -I$(NRF5X_SDK_PATH)

# This is where the common linker for both nRF51 & nRF52 is stored.
ifdef NRF5X_SDK_11
LDFLAGS += -L$(NRF5X_SDK_PATH)/nrf5x_linkers
LDFLAGS += -L$(NRF5X_SDK_PATH)/nrf5x_linkers
endif
ifdef NRF5X_SDK_12
LDFLAGS += -L$(NRF5X_SDK_PATH)/nrf5x_linkers
LDFLAGS += -L$(NRF5X_SDK_PATH)/nrf5x_linkers
endif
ifdef NRF5X_SDK_14
LDFLAGS += -L$(NRF5X_SDK_PATH)/components/toolchain/gcc
Expand All @@ -63,11 +65,11 @@ ifdef BOOTLOADER
targets/nrf5x_dfu/dfu_public_key.c \
targets/nrf5x_dfu/lcd.c \
targets/nrf5x_dfu/main.c \
targets/nrf5x_dfu/flash.c
targets/nrf5x_dfu/flash.c
ifdef NRF5X_SDK_12
SOURCES += \
targets/nrf5x_dfu/sdk12/dfu-cc.pb.c \
targets/nrf5x_dfu/sdk12/dfu_req_handling.c
targets/nrf5x_dfu/sdk12/dfu_req_handling.c
endif
else # no BOOTLOADER
DEFINES += -DUSE_APP_CONFIG
Expand Down Expand Up @@ -204,13 +206,13 @@ endif

ifneq (,$(findstring I2C_SLAVE,$(DEFINES)))
INCLUDE += -I$(NRF5X_SDK_PATH)/components/drivers_nrf/twis_slave
TARGETSOURCES += $(NRF5X_SDK_PATH)/components/drivers_nrf/twis_slave/nrf_drv_twis.c
TARGETSOURCES += $(NRF5X_SDK_PATH)/components/drivers_nrf/twis_slave/nrf_drv_twis.c
endif

ifndef NRF5X_SDK_17
ifndef NRF5X_SDK_15_3
TARGETSOURCES += \
$(NRF5X_SDK_PATH)/components/ble/peer_manager/pm_mutex.c
$(NRF5X_SDK_PATH)/components/ble/peer_manager/pm_mutex.c
endif
endif
TARGETSOURCES += \
Expand All @@ -235,7 +237,7 @@ $(NRF5X_SDK_PATH)/components/libraries/queue/nrf_queue.c \
$(NRF5X_SDK_PATH)/components/libraries/util/app_util_platform.c \
$(NRF5X_SDK_PATH)/components/libraries/util/sdk_mapped_flags.c \
$(NRF5X_SDK_PATH)/components/libraries/util/app_error.c \
$(NRF5X_SDK_PATH)/components/libraries/util/nrf_assert.c
$(NRF5X_SDK_PATH)/components/libraries/util/nrf_assert.c

ifdef NRF5X_SDK_11
TARGETSOURCES += \
Expand All @@ -247,7 +249,7 @@ TARGETSOURCES += \
$(NRF5X_SDK_PATH)/components/softdevice/common/softdevice_handler/softdevice_handler.c \
$(NRF5X_SDK_PATH)/components/libraries/fstorage/fstorage.c \
$(NRF5X_SDK_PATH)/components/drivers_nrf/delay/nrf_delay.c \
$(NRF5X_SDK_PATH)/components/drivers_nrf/hal/nrf_adc.c
$(NRF5X_SDK_PATH)/components/drivers_nrf/hal/nrf_adc.c
else
TARGETSOURCES += \
$(NRF5X_SDK_PATH)/components/softdevice/common/nrf_sdh.c \
Expand Down Expand Up @@ -296,7 +298,7 @@ ifdef NRF5X_SDK_12
TARGETSOURCES += $(NRF5X_SDK_PATH)/components/libraries/ecc/ecc.c
TARGETSOURCES += $(NRF5X_SDK_PATH)/components/libraries/hci/hci_mem_pool.c
TARGETSOURCES += $(NRF5X_SDK_PATH)/components/libraries/util/nrf_assert.c
TARGETSOURCES += $(NRF5X_SDK_PATH)/components/libraries/queue/nrf_queue.c
TARGETSOURCES += $(NRF5X_SDK_PATH)/components/libraries/queue/nrf_queue.c
TARGETSOURCES += $(NRF5X_SDK_PATH)/components/ble/common/ble_advdata.c
TARGETSOURCES += $(NRF5X_SDK_PATH)/components/ble/common/ble_conn_params.c
TARGETSOURCES += $(NRF5X_SDK_PATH)/components/ble/common/ble_srv_common.c
Expand Down Expand Up @@ -459,7 +461,7 @@ endif
$(NRF5X_SDK_PATH)/components/libraries/bootloader/nrf_bootloader_dfu_timers.c \
$(NRF5X_SDK_PATH)/components/libraries/bootloader/nrf_bootloader_fw_activation.c \
$(NRF5X_SDK_PATH)/components/libraries/bootloader/nrf_bootloader_info.c \
$(NRF5X_SDK_PATH)/components/libraries/bootloader/nrf_bootloader_wdt.c
$(NRF5X_SDK_PATH)/components/libraries/bootloader/nrf_bootloader_wdt.c
endif
endif # BOOTLOADER
ifndef BOOTLOADER_SETTINGS_FAMILY
Expand All @@ -484,7 +486,7 @@ TARGETSOURCES += \
$(NRF5X_SDK_PATH)/components/ble/ble_services/ble_ancs_c/ancs_attr_parser.c \
$(NRF5X_SDK_PATH)/components/ble/ble_services/ble_ancs_c/ancs_tx_buffer.c \
$(NRF5X_SDK_PATH)/components/ble/ble_services/ble_ancs_c/nrf_ble_ancs_c.c \
$(NRF5X_SDK_PATH)/components/ble/ble_db_discovery/ble_db_discovery.c
$(NRF5X_SDK_PATH)/components/ble/ble_db_discovery/ble_db_discovery.c
endif # ESPR_BLUETOOTH_ANCS
endif

Expand Down Expand Up @@ -531,7 +533,7 @@ ifdef NRF5X_SDK_11 # SDK11 requires non-secure DFU that the adafruit tools suppo
@echo Creating DFU ZIP
# adafruit-nrfutil dfu genpkg --help
@cp $(PROJ_NAME).app_hex $(PROJ_NAME)_app.hex
adafruit-nrfutil dfu genpkg --application $(PROJ_NAME)_app.hex $(DFU_SETTINGS) $(PROJ_NAME).zip
adafruit-nrfutil dfu genpkg --application $(PROJ_NAME)_app.hex $(DFU_SETTINGS) $(PROJ_NAME).zip
@rm $(PROJ_NAME)_app.hex
else
@echo Creating DFU ZIP
Expand All @@ -540,7 +542,7 @@ else
ifdef BOOTLOADER
nrfutil pkg generate $(PROJ_NAME).zip --bootloader $(PROJ_NAME)_app.hex --bootloader-version 0xff --hw-version 52 --sd-req 0x8C,0x91 --key-file $(DFU_PRIVATE_KEY)
else
nrfutil pkg generate $(PROJ_NAME).zip --application $(PROJ_NAME)_app.hex $(DFU_SETTINGS) --key-file $(DFU_PRIVATE_KEY)
nrfutil pkg generate $(PROJ_NAME).zip --application $(PROJ_NAME)_app.hex $(DFU_SETTINGS) --key-file $(DFU_PRIVATE_KEY)
endif
@rm $(PROJ_NAME)_app.hex
endif
Expand Down

0 comments on commit 1efcb1c

Please sign in to comment.