From 723203c3e4bdce17f013e0e1fd470efd3950d241 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Fri, 16 Feb 2024 01:50:57 -0700 Subject: [PATCH] Added uboot and FOTA --- pm_static.yml | 5 +++++ prj.conf | 24 +++++++++--------------- src/main.c | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 pm_static.yml diff --git a/pm_static.yml b/pm_static.yml new file mode 100644 index 0000000..bc1f8ee --- /dev/null +++ b/pm_static.yml @@ -0,0 +1,5 @@ +mcuboot: + address: 0x00000000 + end_address: 0x00010000 + region: flash_primary + size: 0x10000 \ No newline at end of file diff --git a/prj.conf b/prj.conf index f355228..bea75eb 100644 --- a/prj.conf +++ b/prj.conf @@ -23,7 +23,6 @@ CONFIG_HEAP_MEM_POOL_SIZE=2048 CONFIG_MAIN_THREAD_PRIORITY=7 CONFIG_ZIGBEE=y -CONFIG_ZIGBEE_CHANNEL=11 CONFIG_ZIGBEE_APP_UTILS=y CONFIG_ZIGBEE_ROLE_ROUTER=y @@ -51,21 +50,16 @@ CONFIG_UART_LINE_CTRL=y # as backend for both Shell and Logging subsystems. CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y -CONFIG_BOARD_HAS_NRF5_BOOTLOADER=n - -CONFIG_DEBUG_OPTIMIZATIONS=y -CONFIG_DEBUG_THREAD_INFO=y +CONFIG_BOARD_HAS_NRF5_BOOTLOADER=y CONFIG_RESET_ON_FATAL_ERROR=n -CONFIG_LOG_BACKEND_SWO=y - -CONFIG_ZIGBEE_SHELL_ENDPOINT=10 -CONFIG_ZIGBEE_SHELL=y -CONFIG_ZIGBEE_SHELL_DEBUG_CMD=y +CONFIG_ZIGBEE_CHANNEL_SELECTION_MODE_MULTI=y -CONFIG_DEBUG=y -CONFIG_ASSERT=y -CONFIG_ZBOSS_HALT_ON_ASSERT=y -CONFIG_ZIGBEE_LOGGER_EP=n -CONFIG_ZIGBEE_CHANNEL_SELECTION_MODE_MULTI=y \ No newline at end of file +CONFIG_BOOTLOADER_MCUBOOT=y +CONFIG_ZIGBEE_FOTA=y +CONFIG_IMG_MANAGER=y +CONFIG_STREAM_FLASH=y +CONFIG_STREAM_FLASH_ERASE=y +CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE=y +CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION="0.0.0" \ No newline at end of file diff --git a/src/main.c b/src/main.c index 60d0c91..dcba758 100644 --- a/src/main.c +++ b/src/main.c @@ -9,11 +9,15 @@ #include #include +#include + +#include + #include "switch.h" LOG_MODULE_REGISTER(app, LOG_LEVEL_INF); -#define INFO_ENDPOINT CONFIG_ZIGBEE_SHELL_ENDPOINT +#define INFO_ENDPOINT 64 #define SW0_EP 1 #define SW1_EP 2 #define SW2_EP 3 @@ -94,13 +98,16 @@ ZB_DECLARE_SW_EP(sw1_ep, SW1_EP, app_ram.states[1], app_static.types[1], app_nvr ZB_DECLARE_SW_EP(sw2_ep, SW2_EP, app_ram.states[2], app_static.types[2], app_nvram.actions[2]); ZB_DECLARE_SW_EP(sw3_ep, SW3_EP, app_ram.states[3], app_static.types[3], app_nvram.actions[3]); +extern zb_af_endpoint_desc_t zigbee_fota_client_ep; + ZBOSS_DECLARE_DEVICE_CTX_EP_VA( zigbee_ctx, &info_ep, &sw0_ep, &sw1_ep, &sw2_ep, - &sw3_ep); + &sw3_ep, + &zigbee_fota_client_ep); static const struct gpio_dt_spec network_led = GPIO_DT_SPEC_GET(DT_NODELABEL(network_led), gpios); static const struct gpio_dt_spec sw[4] = { @@ -191,6 +198,7 @@ static void configure_gpio(void) */ void zboss_signal_handler(zb_bufid_t bufid) { + zigbee_fota_signal_handler(bufid); gpio_pin_toggle_dt(&network_led); zb_zdo_app_signal_hdr_t *sig_handler = NULL; @@ -297,6 +305,23 @@ static void zcl_device_cb(zb_bufid_t bufid) { } } +/**@brief Callback function for handling OTA events. + * + * @param[in] *evt Structure containing event information + */ +static void ota_evt_handler(const struct zigbee_fota_evt *evt) +{ + switch (evt->id) { + case ZIGBEE_FOTA_EVT_FINISHED: + LOG_INF("Reboot application."); + if (IS_ENABLED(CONFIG_RAM_POWER_DOWN_LIBRARY)) { + power_up_unused_ram(); + } + sys_reboot(SYS_REBOOT_COLD); + break; + } +} + int main(void) { LOG_INF("Starting jamie"); @@ -310,9 +335,15 @@ int main(void) /* Register device context (endpoints). */ ZB_AF_REGISTER_DEVICE_CTX(&zigbee_ctx); + /* Initialize Zigbee FOTA download service. */ + zigbee_fota_init(ota_evt_handler); + /* Register callback for handling ZCL commands. */ + ZB_ZCL_REGISTER_DEVICE_CB(zigbee_fota_zcl_cb); + zigbee_init_clusters(); ZB_AF_SET_IDENTIFY_NOTIFICATION_HANDLER(INFO_ENDPOINT, identify_cb); + ZB_AF_SET_IDENTIFY_NOTIFICATION_HANDLER(CONFIG_ZIGBEE_FOTA_ENDPOINT, identify_cb); zb_nvram_register_app1_read_cb(app_nvram_read); zb_nvram_register_app1_write_cb(app_nvram_write, app_nvram_size); @@ -321,6 +352,10 @@ int main(void) LOG_INF("Zigbee Stack Initialized"); + boot_write_img_confirmed(); + + LOG_INF("Confirmed firmware"); + while(true) { queue_item_t* item = (queue_item_t*) k_queue_get(&switch_queue, K_FOREVER); if(item != NULL) {