Skip to content

Commit

Permalink
IMXRT OTA: support included for 1024, 1040, 1064
Browse files Browse the repository at this point in the history
  • Loading branch information
robert committed Nov 6, 2024
1 parent 192f5e5 commit 6e8dea3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
27 changes: 17 additions & 10 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -5452,18 +5452,26 @@ bool mg_ota_end(void) {



#if MG_OTA == MG_OTA_RT1020 || MG_OTA == MG_OTA_RT1060
#if MG_OTA >= MG_OTA_RT1020 && MG_OTA <= MG_OTA_RT1064

static bool mg_imxrt_write(void *, const void *, size_t);
static bool mg_imxrt_swap(void);

#if MG_OTA != MG_OTA_RT1064
#define MG_IMXRT_FLASH_START 0x60000000
#define FLEXSPI_NOR_INSTANCE 0
#else
#define MG_IMXRT_FLASH_START 0x70000000
#define FLEXSPI_NOR_INSTANCE 1
#endif

// TODO(): fill at init, support more devices in a dynamic way
// TODO(): then, check alignment is <= 256, see Wizard's #251
static struct mg_flash s_mg_flash_imxrt = {
(void *) 0x60000000, // Start,
8 * 1024 * 1024, // Size, 8mb
4 * 1024, // Sector size, 4k
256, // Align,
(void *) MG_IMXRT_FLASH_START, // Start,
4 * 1024 * 1024, // Size, 8mb
4 * 1024, // Sector size, 4k
256, // Align,
mg_imxrt_write,
mg_imxrt_swap,
};
Expand Down Expand Up @@ -5592,8 +5600,6 @@ struct mg_flexspi_nor_config {
#define MG_FLEXSPI_LUT_OPCODE1(x) \
(((uint32_t) (((uint32_t) (x)) << 26U)) & 0xFC000000U)

#define FLEXSPI_NOR_INSTANCE 0

#if MG_OTA == MG_OTA_RT1020
struct mg_flexspi_nor_driver_interface {
uint32_t version;
Expand All @@ -5609,7 +5615,7 @@ struct mg_flexspi_nor_driver_interface {
int (*xfer)(uint32_t instance, char *xfer);
void (*clear_cache)(uint32_t instance);
};
#elif MG_OTA == MG_OTA_RT1060
#else
struct mg_flexspi_nor_driver_interface {
uint32_t version;
int (*init)(uint32_t instance, struct mg_flexspi_nor_config *config);
Expand Down Expand Up @@ -5642,7 +5648,6 @@ MG_IRAM static bool flash_page_start(volatile uint32_t *dst) {
}

// Note: the get_config function below works both for RT1020 and 1060
#if MG_OTA == MG_OTA_RT1020
// must reside in RAM, as flash will be erased
static struct mg_flexspi_nor_config default_config = {
.memConfig = {.tag = MG_FLEXSPI_CFG_BLK_TAG,
Expand All @@ -5667,7 +5672,9 @@ MG_IRAM static int flexspi_nor_get_config(
*config = &default_config;
return 0;
}
#else

#if 0
// ROM API get_config call (ROM version >= 1.5)
MG_IRAM static int flexspi_nor_get_config(
struct mg_flexspi_nor_config **config) {
uint32_t options[] = {0xc0000000, 0x00};
Expand Down
2 changes: 1 addition & 1 deletion mongoose.h
Original file line number Diff line number Diff line change
Expand Up @@ -2647,6 +2647,7 @@ void mg_rpc_list(struct mg_rpc_req *r);
#define MG_OTA_U2A 200 // Renesas U2A16, U2A8, U2A6
#define MG_OTA_RT1020 300 // IMXRT1020
#define MG_OTA_RT1060 301 // IMXRT1060
#define MG_OTA_RT1064 302 // IMXRT1064
#define MG_OTA_MCXN 310 // MCXN947
#define MG_OTA_FLASH 900 // OTA via an internal flash
#define MG_OTA_ESP32 910 // ESP32 OTA implementation
Expand Down Expand Up @@ -2762,7 +2763,6 @@ void mg_tcpip_arp_request(struct mg_tcpip_if *ifp, uint32_t ip, uint8_t *mac);
extern struct mg_tcpip_driver mg_tcpip_driver_stm32f;
extern struct mg_tcpip_driver mg_tcpip_driver_w5500;
extern struct mg_tcpip_driver mg_tcpip_driver_tm4c;
extern struct mg_tcpip_driver mg_tcpip_driver_tms570;
extern struct mg_tcpip_driver mg_tcpip_driver_stm32h;
extern struct mg_tcpip_driver mg_tcpip_driver_imxrt;
extern struct mg_tcpip_driver mg_tcpip_driver_same54;
Expand Down
1 change: 1 addition & 0 deletions src/ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define MG_OTA_U2A 200 // Renesas U2A16, U2A8, U2A6
#define MG_OTA_RT1020 300 // IMXRT1020
#define MG_OTA_RT1060 301 // IMXRT1060
#define MG_OTA_RT1064 302 // IMXRT1064
#define MG_OTA_MCXN 310 // MCXN947
#define MG_OTA_FLASH 900 // OTA via an internal flash
#define MG_OTA_ESP32 910 // ESP32 OTA implementation
Expand Down
27 changes: 17 additions & 10 deletions src/ota_imxrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@
#include "log.h"
#include "ota.h"

#if MG_OTA == MG_OTA_RT1020 || MG_OTA == MG_OTA_RT1060
#if MG_OTA >= MG_OTA_RT1020 && MG_OTA <= MG_OTA_RT1064

static bool mg_imxrt_write(void *, const void *, size_t);
static bool mg_imxrt_swap(void);

#if MG_OTA != MG_OTA_RT1064
#define MG_IMXRT_FLASH_START 0x60000000
#define FLEXSPI_NOR_INSTANCE 0
#else
#define MG_IMXRT_FLASH_START 0x70000000
#define FLEXSPI_NOR_INSTANCE 1
#endif

// TODO(): fill at init, support more devices in a dynamic way
// TODO(): then, check alignment is <= 256, see Wizard's #251
static struct mg_flash s_mg_flash_imxrt = {
(void *) 0x60000000, // Start,
8 * 1024 * 1024, // Size, 8mb
4 * 1024, // Sector size, 4k
256, // Align,
(void *) MG_IMXRT_FLASH_START, // Start,
4 * 1024 * 1024, // Size, 4mb
4 * 1024, // Sector size, 4k
256, // Align,
mg_imxrt_write,
mg_imxrt_swap,
};
Expand Down Expand Up @@ -142,8 +150,6 @@ struct mg_flexspi_nor_config {
#define MG_FLEXSPI_LUT_OPCODE1(x) \
(((uint32_t) (((uint32_t) (x)) << 26U)) & 0xFC000000U)

#define FLEXSPI_NOR_INSTANCE 0

#if MG_OTA == MG_OTA_RT1020
struct mg_flexspi_nor_driver_interface {
uint32_t version;
Expand All @@ -159,7 +165,7 @@ struct mg_flexspi_nor_driver_interface {
int (*xfer)(uint32_t instance, char *xfer);
void (*clear_cache)(uint32_t instance);
};
#elif MG_OTA == MG_OTA_RT1060
#else
struct mg_flexspi_nor_driver_interface {
uint32_t version;
int (*init)(uint32_t instance, struct mg_flexspi_nor_config *config);
Expand Down Expand Up @@ -192,7 +198,6 @@ MG_IRAM static bool flash_page_start(volatile uint32_t *dst) {
}

// Note: the get_config function below works both for RT1020 and 1060
#if MG_OTA == MG_OTA_RT1020
// must reside in RAM, as flash will be erased
static struct mg_flexspi_nor_config default_config = {
.memConfig = {.tag = MG_FLEXSPI_CFG_BLK_TAG,
Expand All @@ -217,7 +222,9 @@ MG_IRAM static int flexspi_nor_get_config(
*config = &default_config;
return 0;
}
#else

#if 0
// ROM API get_config call (ROM version >= 1.5)
MG_IRAM static int flexspi_nor_get_config(
struct mg_flexspi_nor_config **config) {
uint32_t options[] = {0xc0000000, 0x00};
Expand Down

0 comments on commit 6e8dea3

Please sign in to comment.