Skip to content

Commit

Permalink
connectivity_bridge: Add BL version command
Browse files Browse the repository at this point in the history
Get ready for updating bootloader with a command
to check bootloader version.

Signed-off-by: Maximilian Deubel <[email protected]>
  • Loading branch information
maxd-nordic committed Oct 22, 2024
1 parent b993af9 commit c043483
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ CONFIG_REBOOT=y
CONFIG_GPIO=y

CONFIG_DK_LIBRARY=y

# Bootloader firmware information
CONFIG_FW_INFO=y
CONFIG_SECURE_BOOT_STORAGE=y
25 changes: 25 additions & 0 deletions applications/connectivity_bridge/src/modules/usb_bulk_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <zephyr/sys/reboot.h>
#include <zephyr/drivers/gpio.h>
#include <dk_buttons_and_leds.h>
#include <fw_info.h>
#include <bl_storage.h>
#include <ncs_commit.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bulk_commands, CONFIG_BRIDGE_BULK_LOG_LEVEL);
Expand All @@ -16,17 +19,21 @@ LOG_MODULE_REGISTER(bulk_commands, CONFIG_BRIDGE_BULK_LOG_LEVEL);
#define ID_DAP_VENDOR15 (0x80 + 15)
#define ID_DAP_VENDOR16 (0x80 + 16)
#define ID_DAP_VENDOR17 (0x80 + 17)
#define ID_DAP_VENDOR18 (0x80 + 18)
#define ID_DAP_VENDOR_NRF53_BOOTLOADER ID_DAP_VENDOR14
#define ID_DAP_VENDOR_NRF91_BOOTLOADER ID_DAP_VENDOR15
#define ID_DAP_VENDOR_NRF53_RESET ID_DAP_VENDOR16
#define ID_DAP_VENDOR_NRF91_RESET ID_DAP_VENDOR17
#define ID_DAP_VENDOR_NRF53_VERSION ID_DAP_VENDOR18

#define DAP_COMMAND_SUCCESS 0x00
#define DAP_COMMAND_FAILED 0xFF

#define NRF91_RESET_DURATION K_MSEC(100)
#define NRF91_BUTTON1_DURATION K_MSEC(1000)

#define USB_BULK_PACKET_SIZE 64

static const struct gpio_dt_spec reset_pin =
GPIO_DT_SPEC_GET_OR(DT_PATH(zephyr_user), reset_gpios, {});
static const struct gpio_dt_spec button1_pin =
Expand Down Expand Up @@ -125,6 +132,24 @@ size_t dap_execute_cmd(uint8_t *in, uint8_t *out)
}
goto success;
}
if (in[0] == ID_DAP_VENDOR_NRF53_VERSION) {
const struct fw_info *s0_info = fw_info_find(s0_address_read());
const struct fw_info *s1_info = fw_info_find(s1_address_read());
const size_t VERSION_STRING_LEN = USB_BULK_PACKET_SIZE - 2;

__ASSERT_NO_MSG(s0_info != NULL);
__ASSERT_NO_MSG(s1_info != NULL);
int len = snprintf(out + 2, VERSION_STRING_LEN,
"S0: %u, S1: %u, app: " NCS_COMMIT_STRING,
s0_info->version, s1_info->version);
if (len < 0 || len >= VERSION_STRING_LEN) {
LOG_ERR("Failed to format version string");
goto error;
}
out[0] = in[0];
out[1] = len;
return len + 2;
}

error:
/* default reply: command failed */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ CONFIG_BOOT_SERIAL_IMG_GRP_IMAGE_STATE=y

# Skip checks on the secondary image to make it possible to update MCUBoot on S1/S0
CONFIG_MCUBOOT_VERIFY_IMG_ADDRESS=n

CONFIG_BOOT_SERIAL_NO_APPLICATION=y

0 comments on commit c043483

Please sign in to comment.