prevent dfu 832 bootloader on 840 and vice versa

This commit is contained in:
hathach 2018-08-09 12:37:39 +07:00
parent 25d3da0511
commit 352c44c90d
3 changed files with 40 additions and 36 deletions

View File

@ -107,10 +107,10 @@ BUILD = _build-$(BOARD)
ifneq ($(IS_NRF52840),) ifneq ($(IS_NRF52840),)
SD_NAME = s140 SD_NAME = s140
DFU_DEV_TYPE = 52840 DFU_DEV_REV = 52840
else else
SD_NAME = s132 SD_NAME = s132
DFU_DEV_TYPE = 0x0052 DFU_DEV_REV = 0xADAF
endif endif
@ -122,6 +122,7 @@ endif
# src # src
C_SOURCE_FILES += $(SRC_PATH)/main.c C_SOURCE_FILES += $(SRC_PATH)/main.c
C_SOURCE_FILES += $(SRC_PATH)/dfu_ble_svc.c C_SOURCE_FILES += $(SRC_PATH)/dfu_ble_svc.c
C_SOURCE_FILES += $(SRC_PATH)/dfu_init.c
# nrfx # nrfx
C_SOURCE_FILES += $(NRFX_PATH)/drivers/src/nrfx_power.c C_SOURCE_FILES += $(NRFX_PATH)/drivers/src/nrfx_power.c
@ -131,7 +132,6 @@ C_SOURCE_FILES += $(NRFX_PATH)/hal/nrf_nvmc.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader.c C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_settings.c C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_settings.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_util.c C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_util.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_init_template.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_serial.c C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_serial.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_ble.c C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_ble.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_single_bank.c C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_single_bank.c
@ -432,7 +432,7 @@ $(BUILD)/$(OUTPUT_FILENAME).hex: $(BUILD)/$(OUTPUT_FILENAME).out
genpkg: $(BUILD)/$(BOOT_SD_NAME).zip genpkg: $(BUILD)/$(BOOT_SD_NAME).zip
$(BUILD)/$(BOOT_SD_NAME).zip: $(BUILD)/$(OUTPUT_FILENAME).hex $(BUILD)/$(BOOT_SD_NAME).zip: $(BUILD)/$(OUTPUT_FILENAME).hex
@$(NRFUTIL) dfu genpkg --dev-type $(DFU_DEV_TYPE) --dev-revision 0xADAF --bootloader $< --softdevice $(SD_HEX) $@ @$(NRFUTIL) dfu genpkg --dev-type 0x0052 --dev-revision $(DFU_DEV_REV) --bootloader $< --softdevice $(SD_HEX) $@
# Create SD+bootloader combo with hex & dfu package at beta folder # Create SD+bootloader combo with hex & dfu package at beta folder
beta: genhex genpkg beta: genhex genpkg

View File

@ -47,19 +47,24 @@
#include "nrf_error.h" #include "nrf_error.h"
#include "crc16.h" #include "crc16.h"
// ADAFRUIT /* ADAFRUIT
// All firmware init data must has Device Type ADAFRUIT_DEVICE_TYPE * - All firmware init data must has Device Type ADAFRUIT_DEVICE_TYPE (nrf52832 and nrf52840)
// SD + Bootloader upgrade must have ADAFRUIT_SD_UNLOCK_CODE in Device Revision * - SD + Bootloader upgrade must have correct Device Revision to make sure bootloader is not flashed
* on the wrong device (e.g flah nRF52832's bootloader on nRF52840 board and vice versa)
* - nrf52832 dev-rev is 0xADAF
* - nrf52840 dev-rev is 52840
*/
#define ADAFRUIT_DEVICE_TYPE 0x0052
#ifdef NRF52840_XXAA #ifdef NRF52840_XXAA
#define ADAFRUIT_DEVICE_TYPE 52840 #define ADAFRUIT_DEV_REV 52840
#elif defined NRF52832_XXAA #elif defined NRF52832_XXAA
#define ADAFRUIT_DEVICE_TYPE 0x0052 #define ADAFRUIT_DEV_REV 0xADAF
#else #else
#error Unknown MCU #error Unknown MCU
#endif #endif
#define ADAFRUIT_SD_UNLOCK_CODE 0xADAF
#define DFU_INIT_PACKET_EXT_LENGTH_MIN 2 //< Minimum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a minimum value of two in order to hold a CRC. */ #define DFU_INIT_PACKET_EXT_LENGTH_MIN 2 //< Minimum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a minimum value of two in order to hold a CRC. */
#define DFU_INIT_PACKET_EXT_LENGTH_MAX 10 //< Maximum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a maximum value of 10 in order to hold a CRC and any padded data on transport layer without overflow. */ #define DFU_INIT_PACKET_EXT_LENGTH_MAX 10 //< Maximum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a maximum value of 10 in order to hold a CRC and any padded data on transport layer without overflow. */
@ -131,7 +136,7 @@ uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len, uin
// Adafruit unlock code must match to upgrade SoftDevice and/or Bootloader // Adafruit unlock code must match to upgrade SoftDevice and/or Bootloader
if ( image_type & (DFU_UPDATE_SD | DFU_UPDATE_BL) ) if ( image_type & (DFU_UPDATE_SD | DFU_UPDATE_BL) )
{ {
if (p_init_packet->device_rev != ADAFRUIT_SD_UNLOCK_CODE) if (p_init_packet->device_rev != ADAFRUIT_DEV_REV)
{ {
return NRF_ERROR_FORBIDDEN; return NRF_ERROR_FORBIDDEN;
} }

View File

@ -19,13 +19,13 @@
arm_target_device_name="nRF52840_xxAA" arm_target_device_name="nRF52840_xxAA"
arm_target_interface_type="SWD" arm_target_interface_type="SWD"
c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;BOARD_PCA10056;MK_BOOTLOADER_VERSION=0x06000000;MK_DIS_FIRMWARE=&quot;s140 6.0.0 r0&quot;;S140;CONFIG_GPIO_AS_PINRESET;BLE_STACK_SUPPORT_REQD;SWI_DISABLE0;SOFTDEVICE_PRESENT;FLOAT_ABI_HARD" c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;BOARD_PCA10056;MK_BOOTLOADER_VERSION=0x06000000;MK_DIS_FIRMWARE=&quot;s140 6.0.0 r0&quot;;S140;CONFIG_GPIO_AS_PINRESET;BLE_STACK_SUPPORT_REQD;SWI_DISABLE0;SOFTDEVICE_PRESENT;FLOAT_ABI_HARD"
c_user_include_directories="../;../usb;../cmsis/include;$(tusbDir);$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(sdDir)/headers;$(sdDir)/headers/nrf52;$(sdk11Dir)/drivers_nrf/pstorage;$(sdk11Dir)/ble/common/;$(sdk11Dir)/ble/ble_services/ble_dfu;$(sdk11Dir)/ble/ble_services/ble_dis;$(sdk11Dir)/libraries/bootloader_dfu;$(sdk11Dir)/libraries/bootloader_dfu/hci_transport;$(sdk11Dir)/libraries/util;$(sdkDir)/toolchain/cmsis/include;$(sdkDir)/device;$(sdkDir)/toolchain;$(sdkDir)/drivers_nrf/hal;$(sdkDir)/drivers_nrf/systick;$(sdkDir)/drivers_nrf/uart;$(sdkDir)/drivers_nrf/usbd;$(sdkDir)/drivers_nrf/common;$(sdkDir)/drivers_nrf/delay;$(sdkDir)/drivers_nrf/power;$(sdkDir)/drivers_nrf/clock;$(sdkDir)/libraries/util;$(sdkDir)/libraries/timer;$(sdkDir)/libraries/scheduler;$(sdkDir)/libraries/crc16;$(sdkDir)/libraries/util;$(sdkDir)/libraries/hci/config;$(sdkDir)/libraries/uart;$(sdkDir)/libraries/hci;$(sdkDir)/external/fprintf;$(sdkDir)/libraries/strerror;$(sdkDir)/libraries/atomic;$(sdkDir)/libraries/balloc;$(sdkDir)/libraries/experimental_log/src;$(sdkDir)/libraries/experimental_log;$(sdkDir)/libraries/experimental_section_vars;$(sdkDir)/libraries/experimental_memobj" c_user_include_directories="../;../usb;../cmsis/include;$(tusbDir);$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(sdDir)/include;$(sdDir)/include/nrf52;$(sdk11Dir)/drivers_nrf/pstorage;$(sdk11Dir)/ble/common/;$(sdk11Dir)/ble/ble_services/ble_dfu;$(sdk11Dir)/ble/ble_services/ble_dis;$(sdk11Dir)/libraries/bootloader_dfu;$(sdk11Dir)/libraries/bootloader_dfu/hci_transport;$(sdk11Dir)/libraries/util;$(sdkDir)/toolchain/cmsis/include;$(sdkDir)/device;$(sdkDir)/toolchain;$(sdkDir)/drivers_nrf/hal;$(sdkDir)/drivers_nrf/systick;$(sdkDir)/drivers_nrf/uart;$(sdkDir)/drivers_nrf/usbd;$(sdkDir)/drivers_nrf/common;$(sdkDir)/drivers_nrf/delay;$(sdkDir)/drivers_nrf/power;$(sdkDir)/drivers_nrf/clock;$(sdkDir)/libraries/util;$(sdkDir)/libraries/timer;$(sdkDir)/libraries/scheduler;$(sdkDir)/libraries/crc16;$(sdkDir)/libraries/util;$(sdkDir)/libraries/hci/config;$(sdkDir)/libraries/uart;$(sdkDir)/libraries/hci;$(sdkDir)/external/fprintf;$(sdkDir)/libraries/strerror;$(sdkDir)/libraries/atomic;$(sdkDir)/libraries/balloc;$(sdkDir)/libraries/experimental_log/src;$(sdkDir)/libraries/experimental_log;$(sdkDir)/libraries/experimental_section_vars;$(sdkDir)/libraries/experimental_memobj"
debug_register_definition_file="$(ProjectDir)/nrf52840_Registers.xml" debug_register_definition_file="$(ProjectDir)/nrf52840_Registers.xml"
debug_target_connection="J-Link" debug_target_connection="J-Link"
gcc_entry_point="Reset_Handler" gcc_entry_point="Reset_Handler"
linker_memory_map_file="$(ProjectDir)/nRF52840_xxAA_MemoryMap.xml" linker_memory_map_file="$(ProjectDir)/nRF52840_xxAA_MemoryMap.xml"
linker_section_placement_file="$(ProjectDir)/flash_placement.xml" linker_section_placement_file="$(ProjectDir)/flash_placement.xml"
macros="DeviceHeaderFile=$(PackagesDir)/nRF/CMSIS/Device/Include/nrf.h;DeviceLibraryIdentifier=M4lf;DeviceSystemFile=$(PackagesDir)/nRF/CMSIS/Device/Source/system_nrf52840.c;DeviceVectorsFile=$(PackagesDir)/nRF/Source/ses_nrf52840_Vectors.s;DeviceFamily=nRF;Target=nRF52840_xxAA;Placement=Flash;sdkDir=../../lib/sdk/components;sdk11Dir=../../lib/sdk11/components;sdDir=../../lib/softdevice/s140/6.0.0;tusbDir=../../lib/tinyusb/src;nrfxDir=../../lib/nrfx" macros="DeviceHeaderFile=$(PackagesDir)/nRF/CMSIS/Device/Include/nrf.h;DeviceLibraryIdentifier=M4lf;DeviceSystemFile=$(PackagesDir)/nRF/CMSIS/Device/Source/system_nrf52840.c;DeviceVectorsFile=$(PackagesDir)/nRF/Source/ses_nrf52840_Vectors.s;DeviceFamily=nRF;Target=nRF52840_xxAA;Placement=Flash;sdkDir=../../lib/sdk/components;sdk11Dir=../../lib/sdk11/components;sdDir=../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API;tusbDir=../../lib/tinyusb/src;nrfxDir=../../lib/nrfx"
project_directory="" project_directory=""
project_type="Executable" project_type="Executable"
target_reset_script="Reset();" target_reset_script="Reset();"
@ -93,6 +93,7 @@
<file file_name="../boards/feather52840.h" /> <file file_name="../boards/feather52840.h" />
<file file_name="../boards/pca10056.h" /> <file file_name="../boards/pca10056.h" />
</folder> </folder>
<file file_name="../dfu_init.c" />
</folder> </folder>
<configuration Name="Debug Single" gcc_optimization_level="Debug" /> <configuration Name="Debug Single" gcc_optimization_level="Debug" />
<configuration <configuration
@ -142,7 +143,6 @@
<file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_ble_svc.h" /> <file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_ble_svc.h" />
<file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_ble_svc_internal.h" /> <file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_ble_svc_internal.h" />
<file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_init.h" /> <file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_init.h" />
<file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_init_template.c" />
<file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_transport.h" /> <file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_transport.h" />
<file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c" /> <file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c" />
<file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_serial.c" /> <file file_name="../../lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_serial.c" />
@ -228,29 +228,28 @@
</folder> </folder>
</folder> </folder>
<folder Name="softdevice"> <folder Name="softdevice">
<folder Name="6.0.0"> <folder Name="s140_nrf52_6.1.0">
<folder Name="s140"> <folder Name="s140_nrf52_6.1.0_API">
<folder Name="headers"> <folder Name="include">
<file file_name="../../lib/softdevice/6.0.0/s140/headers/ble.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/ble.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/ble_err.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/ble_err.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/ble_gap.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/ble_gap.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/ble_gatt.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/ble_gatt.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/ble_gattc.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/ble_gattc.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/ble_gatts.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/ble_gatts.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/ble_hci.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/ble_hci.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/ble_l2cap.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/ble_l2cap.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/ble_ranges.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/ble_ranges.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/ble_types.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/ble_types.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/nrf_error.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/nrf_error.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/nrf_error_sdm.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/nrf_error_sdm.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/nrf_error_soc.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/nrf_error_soc.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/nrf_nvic.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/nrf_nvic.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/nrf_sd_def.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/nrf_sdm.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/nrf_sdm.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/nrf_soc.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/nrf_soc.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/nrf_svc.h" />
<file file_name="../../lib/softdevice/6.0.0/s140/headers/nrf_svc.h" />
<folder Name="nrf52"> <folder Name="nrf52">
<file file_name="../../lib/softdevice/6.0.0/s140/headers/nrf52/nrf_mbr.h" /> <file file_name="../../lib/softdevice/s140_nrf52_6.1.0/s140_nrf52_6.1.0_API/include/nrf52/nrf_mbr.h" />
</folder> </folder>
</folder> </folder>
</folder> </folder>