Merge pull request #2489 from openmv/bootloader_fixes
Some checks are pending
🔎 Check Code Formatting / formatting-check (push) Waiting to run
🔥 Firmware Build / build-firmware (ARDUINO_GIGA) (push) Waiting to run
🔥 Firmware Build / build-firmware (ARDUINO_NANO_33_BLE_SENSE) (push) Waiting to run
🔥 Firmware Build / build-firmware (ARDUINO_NANO_RP2040_CONNECT) (push) Waiting to run
🔥 Firmware Build / build-firmware (ARDUINO_NICLA_VISION) (push) Waiting to run
🔥 Firmware Build / build-firmware (ARDUINO_PORTENTA_H7) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV2) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV3) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV4) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV4P) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMVPT) (push) Waiting to run
🔥 Firmware Build / build-firmware (OPENMV_RT1060) (push) Waiting to run
🔥 Firmware Build / code-size-report (push) Blocked by required conditions
🔥 Firmware Build / stable-release (push) Blocked by required conditions
🔥 Firmware Build / development-release (push) Blocked by required conditions

bootloader: Add separate XIP partitions.
This commit is contained in:
Ibrahim Abdelkader 2024-11-08 10:21:01 +02:00 committed by GitHub
commit d634dd885d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 37 additions and 61 deletions

View File

@ -37,7 +37,7 @@
#define STR_DESC_MAX_LEN (32)
#define STR_DESC_COUNT (sizeof(desc_string) / sizeof(desc_string[0]))
#define DFU_DESC_ALT_COUNT OMV_BOOT_PARTITIONS_COUNT
#define DFU_DESC_ALT_COUNT OMV_BOOT_DFU_PARTITIONS_COUNT
#define DFU_DESC_FUNC_ATTR (DFU_ATTR_CAN_UPLOAD | DFU_ATTR_CAN_DOWNLOAD | DFU_ATTR_MANIFESTATION_TOLERANT)
#define CFG_DESC_ITF_DFU (0)
@ -49,7 +49,7 @@ static char const *desc_string[] = {
"OpenMV", // 1: Manufacturer
"OpenMV Camera (DFU Mode)", // 2: Product
"0123456789ABCDEF", // 3: Default Serial.
OMV_BOOT_PARTITIONS_STR,
OMV_BOOT_DFU_PARTITIONS_STR,
};
static tusb_desc_device_t const desc_device = {

View File

@ -61,7 +61,7 @@ uint32_t tud_dfu_get_timeout_cb(uint8_t itf, uint8_t state) {
// Invoked when DFU_DNLOAD is received followed by DFU_GETSTATUS (state=DFU_DNBUSY).
void tud_dfu_download_cb(uint8_t itf, uint16_t block, uint8_t const *buf, uint16_t size) {
const partition_t *p = &OMV_BOOT_PARTITIONS[itf];
const partition_t *p = &OMV_BOOT_DFU_PARTITIONS[itf];
uint32_t addr = p->start + (block * CFG_TUD_DFU_XFER_BUFSIZE);
// Check if partition is writable.
@ -88,13 +88,13 @@ void tud_dfu_download_cb(uint8_t itf, uint16_t block, uint8_t const *buf, uint16
// Invoked when the download process is complete, i.e.,
// DFU_DNLOAD followed by DFU_GETSTATUS (state=Manifest).
void tud_dfu_manifest_cb(uint8_t itf) {
port_mpu_config(&OMV_BOOT_PARTITIONS[itf], 1, 1, 1);
port_mpu_config(&OMV_BOOT_DFU_PARTITIONS[itf], 1, 1, 1);
return tud_dfu_finish_flashing(DFU_STATUS_OK);
}
// Invoked when DFU_UPLOAD request is received.
uint16_t tud_dfu_upload_cb(uint8_t itf, uint16_t block, uint8_t *buf, uint16_t size) {
const partition_t *p = &OMV_BOOT_PARTITIONS[itf];
const partition_t *p = &OMV_BOOT_DFU_PARTITIONS[itf];
uint32_t addr = p->start + (block * CFG_TUD_DFU_XFER_BUFSIZE);
if (addr + size > p->limit) {

View File

@ -99,31 +99,36 @@ __weak void port_mpu_init(void) {
#endif
// Configure read-only MPU regions for boot partitions.
for (size_t i = 0; i < OMV_BOOT_PARTITIONS_COUNT; i++) {
// Note first region is the bootloader's partition,
// which normally needs to be executable.
port_mpu_config(&OMV_BOOT_PARTITIONS[i], 1, 1, (i != 0));
for (size_t i = 0; i < OMV_BOOT_DFU_PARTITIONS_COUNT; i++) {
// Note first region is the bootloader's partition, which normally
// needs to be executable. If more executable partitions are needed
// a XN flag can be added to partition_t.
port_mpu_config(&OMV_BOOT_DFU_PARTITIONS[i], 1, 1, (i != 0));
}
}
__weak void port_mpu_deinit() {
#if (__ARM_ARCH >= 8)
ARM_MPU_Disable();
// Disable all regions.
for (size_t i = 0; i < OMV_BOOT_PARTITIONS_COUNT; i++) {
if (OMV_BOOT_PARTITIONS[i].region != -1) {
ARM_MPU_ClrRegion(OMV_BOOT_PARTITIONS[i].region);
for (size_t i = 0; i < OMV_BOOT_DFU_PARTITIONS_COUNT; i++) {
if (OMV_BOOT_DFU_PARTITIONS[i].region != -1) {
ARM_MPU_ClrRegion(OMV_BOOT_DFU_PARTITIONS[i].region);
}
}
// Configure XIP MPU regions (if any).
for (size_t i = 0; i < OMV_BOOT_PARTITIONS_COUNT; i++) {
if (OMV_BOOT_PARTITIONS[i].type == PTYPE_XIP_FLASH) {
port_mpu_config(&OMV_BOOT_PARTITIONS[i], 1, 1, 0);
#ifdef OMV_BOOT_XIP_PARTITIONS_COUNT
// Configure MPU regions for XIP partitions.
for (size_t i = 0; i < OMV_BOOT_XIP_PARTITIONS_COUNT; i++) {
if (OMV_BOOT_XIP_PARTITIONS[i].type == PTYPE_XIP_FLASH) {
port_mpu_config(&OMV_BOOT_XIP_PARTITIONS[i], 1, 1, 0);
}
}
#endif // OMV_BOOT_XIP_PARTITIONS_COUNT
ARM_MPU_Enable(MPU_CTRL_PRIVDEFENA_Msk | MPU_CTRL_HFNMIENA_Msk);
#endif
#endif // __ARM_ARCH >= 8
}
__weak void port_mpu_load_defaults() {

View File

@ -48,11 +48,11 @@ static const pin_t omv_boot_pins[] = {
#define OMV_BOOT_PINS_COUNT (sizeof(omv_boot_pins) / sizeof(omv_boot_pins[0]))
// Boot partitions.
static const partition_t OMV_BOOT_PARTITIONS[] = {
static const partition_t OMV_BOOT_DFU_PARTITIONS[] = {
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 1, .start = 0x08000000, .limit = 0x08008000, .attr = 0 }, // Boot
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08008000, .limit = 0x08010000, .attr = 0 }, // FFS
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08010000, .limit = 0x08100000, .attr = 0 }, // Firmware
};
#define OMV_BOOT_PARTITIONS_COUNT 3 // Must be a literal
#define OMV_BOOT_PARTITIONS_STR "BOOTLOADER", "FILESYSTEM", "FIRMWARE"
#define OMV_BOOT_DFU_PARTITIONS_COUNT 3 // Must be a literal
#define OMV_BOOT_DFU_PARTITIONS_STR "BOOTLOADER", "FILESYSTEM", "FIRMWARE"
#endif //__OMV_BOOTCONFIG_H__

View File

@ -48,11 +48,11 @@ static const pin_t omv_boot_pins[] = {
#define OMV_BOOT_PINS_COUNT (sizeof(omv_boot_pins) / sizeof(omv_boot_pins[0]))
// Boot partitions.
static const partition_t OMV_BOOT_PARTITIONS[] = {
static const partition_t OMV_BOOT_DFU_PARTITIONS[] = {
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 1, .start = 0x08000000, .limit = 0x08008000, .attr = 0 }, // Boot
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08008000, .limit = 0x08020000, .attr = 0 }, // FFS
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08020000, .limit = 0x08200000, .attr = 0 }, // FIRMWARE
};
#define OMV_BOOT_PARTITIONS_COUNT 3 // Must be a literal
#define OMV_BOOT_PARTITIONS_STR "BOOTLOADER", "FILESYSTEM", "FIRMWARE"
#define OMV_BOOT_DFU_PARTITIONS_COUNT 3 // Must be a literal
#define OMV_BOOT_DFU_PARTITIONS_STR "BOOTLOADER", "FILESYSTEM", "FIRMWARE"
#endif //__OMV_BOOTCONFIG_H__

View File

@ -48,11 +48,11 @@ static const pin_t omv_boot_pins[] = {
#define OMV_BOOT_PINS_COUNT (sizeof(omv_boot_pins) / sizeof(omv_boot_pins[0]))
// Boot partitions.
static const partition_t OMV_BOOT_PARTITIONS[] = {
static const partition_t OMV_BOOT_DFU_PARTITIONS[] = {
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 1, .start = 0x08000000, .limit = 0x08020000, .attr = 0 }, // Boot
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08020000, .limit = 0x08040000, .attr = 0 }, // FFS
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08040000, .limit = 0x08200000, .attr = 0 }, // FIRMWARE
};
#define OMV_BOOT_PARTITIONS_COUNT 3 // Must be a literal
#define OMV_BOOT_PARTITIONS_STR "BOOTLOADER", "FILESYSTEM", "FIRMWARE"
#define OMV_BOOT_DFU_PARTITIONS_COUNT 3 // Must be a literal
#define OMV_BOOT_DFU_PARTITIONS_STR "BOOTLOADER", "FILESYSTEM", "FIRMWARE"
#endif //__OMV_BOOTCONFIG_H__

View File

@ -56,12 +56,12 @@ static const pin_t omv_boot_pins[] = {
#define OMV_BOOT_PINS_COUNT (sizeof(omv_boot_pins) / sizeof(omv_boot_pins[0]))
// Boot partitions.
static const partition_t OMV_BOOT_PARTITIONS[] = {
static const partition_t OMV_BOOT_DFU_PARTITIONS[] = {
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 1, .start = 0x08000000, .limit = 0x08020000, .attr = 0 }, // Boot
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08020000, .limit = 0x08040000, .attr = 0 }, // FFS
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08040000, .limit = 0x08200000, .attr = 0 }, // FIRMWARE
{ .type = PTYPE_SPI_FLASH, .region = -1, .rdonly = 0, .start = 0x00000000, .limit = 0x02000000, .attr = 0 }, // QSPI
};
#define OMV_BOOT_PARTITIONS_COUNT 4 // Must be a literal
#define OMV_BOOT_PARTITIONS_STR "BOOTLOADER", "FILESYSTEM", "FIRMWARE", "SPI_FLASH"
#define OMV_BOOT_DFU_PARTITIONS_COUNT 4 // Must be a literal
#define OMV_BOOT_DFU_PARTITIONS_STR "BOOTLOADER", "FILESYSTEM", "FIRMWARE", "SPI_FLASH"
#endif //__OMV_BOOTCONFIG_H__

View File

@ -56,12 +56,12 @@ static const pin_t omv_boot_pins[] = {
#define OMV_BOOT_PINS_COUNT (sizeof(omv_boot_pins) / sizeof(omv_boot_pins[0]))
// Boot partitions.
static const partition_t OMV_BOOT_PARTITIONS[] = {
static const partition_t OMV_BOOT_DFU_PARTITIONS[] = {
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 1, .start = 0x08000000, .limit = 0x08020000, .attr = 0 }, // Boot
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08020000, .limit = 0x08040000, .attr = 0 }, // FFS
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08040000, .limit = 0x08200000, .attr = 0 }, // FIRMWARE
{ .type = PTYPE_SPI_FLASH, .region = -1, .rdonly = 0, .start = 0x00000000, .limit = 0x02000000, .attr = 0 }, // QSPI
};
#define OMV_BOOT_PARTITIONS_COUNT 4 // Must be a literal
#define OMV_BOOT_PARTITIONS_STR "BOOTLOADER", "FILESYSTEM", "FIRMWARE", "SPI_FLASH"
#define OMV_BOOT_DFU_PARTITIONS_COUNT 4 // Must be a literal
#define OMV_BOOT_DFU_PARTITIONS_STR "BOOTLOADER", "FILESYSTEM", "FIRMWARE", "SPI_FLASH"
#endif //__OMV_BOOTCONFIG_H__

View File

@ -1,29 +0,0 @@
/*
* This file is part of the OpenMV project.
*
* Copyright (c) 2013-2022 Ibrahim Abdelkader <iabdalkader@openmv.io>
* Copyright (c) 2013-2022 Kwabena W. Agyeman <kwagyeman@openmv.io>
*
* This work is licensed under the MIT license, see the file LICENSE for details.
*
* Board configuration and pin definitions.
*/
#ifndef __OMV_BOOTCONFIG_H__
#define __OMV_BOOTCONFIG_H__
// Bootloader version.
#define OMV_BOOT_VERSION (0xABCD0003)
// Bootloader LED GPIO config.
#define OMV_BOOT_LED_PIN (GPIO_PIN_7)
#define OMV_BOOT_LED_PORT (GPIOA)
// Flash layout for the bootloader.
// Flash FS sector, main FW sector, max sector.
#define OMV_BOOT_FLASH_LAYOUT {1, 2, 15}
// Flash configuration.
#define OMV_BOOT_FLASH_ORIGIN 0x34180400
#define OMV_BOOT_FLASH_LENGTH 128K
#endif //__OMV_BOOTCONFIG_H__