diff --git a/AGENTS.md b/AGENTS.md index 49f985a3e..2ac2d07e0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -150,10 +150,7 @@ itself; a human has to edit it too. - **ARM GCC version matters.** CI pins exactly `12.3.Rel1`; 13.3.Rel1 also compiles clean and is the closest verified-working version if you can't - get the exact CI-pinned one. GCC 15 is unverified here; Adafruit's scoped - `#pragma GCC diagnostic` for its `-Werror=array-bounds` false positive in - `lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c` - (a fixed MBR-address read) is in. + get the exact CI-pinned one. GCC 15 is unverified here. - **MeshCore/Ripple content has been deliberately removed** from the docs (README, changelog) — this is Meshtastic's own branded fork now, not a place to re-add other companion-firmware documentation. If you're diff --git a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c index b36175d93..2d7ee03fb 100644 --- a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c +++ b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c @@ -16,8 +16,9 @@ #include "ble_srv_common.h" #include #include "sdk_common.h" +#include "ble_dfu_cfg.h" -#define MAX_DFU_PKT_LEN (247 - 3) // MTU - 3 bytes for ATT header /**< Maximum length (in bytes) of the DFU Packet characteristic. */ +#define MAX_DFU_PKT_LEN (BLEGATT_ATT_MTU_MAX - 3) // MTU - 3 bytes for ATT header /**< Maximum length (in bytes) of the DFU Packet characteristic. */ #define PKT_START_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Start DFU Request. */ #define PKT_INIT_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Init DFU Request. */ #define PKT_RCPT_NOTIF_REQ_LEN 3 /**< Length (in bytes) of the Packet Receipt Notification Request. */ diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c index c436a0d0f..bc4156009 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c @@ -115,6 +115,8 @@ static void wait_for_events(void) // uint32_t err_code = sd_app_evt_wait(); // APP_ERROR_CHECK(err_code); + // Firmware arms a 90 s watchdog that survives the soft reset into the bootloader; + // every path outside this loop must stay under it. // Feed all Watchdog just in case application enable it // WDT cannot be disabled once started. It even last through NVIC soft reset if ( nrf_wdt_started_check(NRF_WDT) ) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h index efd72e753..d861c6fc9 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h @@ -90,8 +90,6 @@ uint32_t bootloader_dfu_sd_update_continue(void); uint32_t bootloader_dfu_sd_update_finalize(void); -void bootloader_mbr_addrs_populate(void); - #endif // BOOTLOADER_H__ /**@} */ diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c index 1febf3fbe..0a39e61c4 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c @@ -39,23 +39,3 @@ void bootloader_util_settings_get(const bootloader_settings_t ** pp_bootloader_s *pp_bootloader_settings = p_bootloader_settings; } - -void bootloader_mbr_addrs_populate(void) -{ -#if defined(__GNUC__) && (__GNUC__ >= 12) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Warray-bounds" -#endif - if (*(const uint32_t *)MBR_BOOTLOADER_ADDR == 0xFFFFFFFF) - { - nrfx_nvmc_word_write(MBR_BOOTLOADER_ADDR, BOOTLOADER_REGION_START); - } - - if (*(const uint32_t *)MBR_PARAM_PAGE_ADDR == 0xFFFFFFFF) - { - nrfx_nvmc_word_write(MBR_PARAM_PAGE_ADDR, BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS); - } -#if defined(__GNUC__) && (__GNUC__ >= 12) -#pragma GCC diagnostic pop -#endif -} diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c index 50849ba3b..73213e095 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -34,11 +34,7 @@ #include "dfu_ble_svc_internal.h" #include "nrf_delay.h" #include "sdk_common.h" - - -#define BLEGAP_EVENT_LENGTH 6 -#define BLEGATT_ATT_MTU_MAX 247 -enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; +#include "ble_dfu_cfg.h" #define DFU_REV_MAJOR 0x00 /** DFU Major revision number to be exposed. */ #define DFU_REV_MINOR 0x08 /** DFU Minor revision number to be exposed. */ diff --git a/src/ble_dfu_cfg.h b/src/ble_dfu_cfg.h new file mode 100644 index 000000000..9e318c6d3 --- /dev/null +++ b/src/ble_dfu_cfg.h @@ -0,0 +1,8 @@ +#ifndef BLE_DFU_CFG_H__ +#define BLE_DFU_CFG_H__ + +#define BLEGAP_EVENT_LENGTH 6 +#define BLEGATT_ATT_MTU_MAX 247 +enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; + +#endif // BLE_DFU_CFG_H__ diff --git a/src/main.c b/src/main.c index e9fe140db..421d8bfbb 100644 --- a/src/main.c +++ b/src/main.c @@ -62,6 +62,7 @@ #include "nrf_error.h" #include "boards.h" +#include "ble_dfu_cfg.h" #include "pstorage_platform.h" #include "nrf_mbr.h" @@ -121,13 +122,6 @@ extern void tusb_hal_nrf_power_event(uint32_t event); // DFU_DBL_RESET magic is used to determined which mode is entered #define APP_ASKS_FOR_SINGLE_TAP_RESET() (*((uint32_t*)(DFU_BANK_0_REGION_START + 0x200)) == 0x87eeb07c) -// These values must match the values in dfu_transport_ble.c and MAX_DFU_PKT_LEN should match BLEGATT_ATT_MTU_MAX - 3 -#define BLEGAP_EVENT_LENGTH 6 -#define BLEGATT_ATT_MTU_MAX 247 -enum { - BLE_CONN_CFG_HIGH_BANDWIDTH = 1 -}; - //--------------------------------------------------------------------+ // //--------------------------------------------------------------------+ @@ -136,6 +130,7 @@ uint32_t* dbl_reset_mem = ((uint32_t*) DFU_DBL_RESET_MEM); // true if ble, false if serial bool _ota_dfu = false; bool _ota_connected = false; +// Set when the OTA session initializes the SoftDevice, so the app jump does not initialize it twice. bool _sd_inited = false; bool is_ota(void) { @@ -157,11 +152,6 @@ static void mbr_init_sd(void) { // //--------------------------------------------------------------------+ int main(void) { - // Populate Boot Address and MBR Param into MBR if not already - // MBR_BOOTLOADER_ADDR/MBR_PARAM_PAGE_ADDR are used if available, else UICR registers are used - // Note: skip it for now since this will prevent us to change the size of bootloader in the future - // bootloader_mbr_addrs_populate(); - // Save bootloader version to pre-defined register, retrieved by application // TODO move to CF2 BOOTLOADER_VERSION_REGISTER = (MK_BOOTLOADER_VERSION); @@ -228,9 +218,6 @@ int main(void) { static void check_dfu_mode(void) { uint32_t const gpregret = NRF_POWER->GPREGRET; - // SD is already Initialized in case of BOOTLOADER_DFU_OTA_MAGIC - _sd_inited = (gpregret == DFU_MAGIC_OTA_APPJUM); - // Start Bootloader in BLE OTA mode _ota_dfu = (gpregret == DFU_MAGIC_OTA_APPJUM) || (gpregret == DFU_MAGIC_OTA_RESET); @@ -335,7 +322,7 @@ static void check_dfu_mode(void) { } #endif led_state(STATE_BLE_DISCONNECTED); - if (!_sd_inited) mbr_init_sd(); + mbr_init_sd(); _sd_inited = true; ble_stack_init(); } else {