bootloader: Add separate XIP partitions.

This commit is contained in:
iabdalkader 2024-11-08 09:13:46 +01:00
parent 11a1256eef
commit 6d8f48e8f3
4 changed files with 22 additions and 46 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

@ -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__