Skip to content

Commit 47c841b

Browse files
committed
tinyuf2 working well with rt1176
1 parent dda895f commit 47c841b

File tree

13 files changed

+37
-21
lines changed

13 files changed

+37
-21
lines changed

ports/mimxrt10xx/Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ UF2_ADDR = $(UF2_$(MCU)_ADDR)
7676

7777
DBL_TAP_REG_ADDR = 0x400D410C
7878

79-
# extract _fcfb_origin and _ivt_origin from linker file
79+
# extract _fcfb_origin from linker file
8080
ifeq ($(FLASH_BUILD),1)
8181
FCFB_ORIGIN := $(shell sed -n 's/_fcfb_origin.*\(0x.*\);/\1/p' $(TOP)/$(PORT_DIR)/linker/$(MCU)_flash.ld)
8282
else
8383
FCFB_ORIGIN := $(shell sed -n 's/_fcfb_origin.*\(0x.*\);/\1/p' $(TOP)/$(PORT_DIR)/linker/$(MCU)_ram.ld)
8484
endif
8585
IVT_ORIGIN := $(shell printf "0x%X\n" $$(( ($(FCFB_ORIGIN) & ~0xFFF) + 0x1000 )))
86+
$(info FCFB_ORIGIN=$(FCFB_ORIGIN) IVT_ORIGIN=$(IVT_ORIGIN))
8687

8788
$(BUILD)/$(OUTNAME).hex: $(BUILD)/$(OUTNAME).elf
8889
@echo CREATE $@
@@ -130,9 +131,9 @@ flash-sdp: $(BUILD)/$(OUTNAME).bin
130131
else
131132
# RAM build: direct load-image (TinyUF2 runs from RAM and self-programs to flash)
132133
flash-sdp: $(BUILD)/$(OUTNAME).bin
133-
@echo "RT1176 RAM Build: Loading TinyUF2 via blhost load-image..."
134-
@echo "TinyUF2 will self-program to flash, then enumerate as USB mass storage."
135-
$(BLHOST) -u 0x1fc9,$(SDP_PID) load-image $<
134+
@if [ -z "$(BLHOST)" ]; then echo SDPHOST is not found for this machine; exit 1; fi
135+
$(PYTHON3) tools/make_ivt0_image.py $< $(BUILD)/$(OUTNAME)_ivt0.bin
136+
$(BLHOST) -u 0x1fc9,$(SDP_PID) load-image $(BUILD)/$(OUTNAME)_ivt0.bin
136137
endif
137138
else
138139
flash-sdp: $(BUILD)/$(OUTNAME).bin

ports/mimxrt10xx/board_flash.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,15 @@
5656

5757
// Flash Configuration Structure
5858
extern flexspi_nor_config_t const qspiflash_config;
59+
static flexspi_nor_config_t flash_cfg; // local copy since ROM API may modify it
5960

6061
#if defined(MIMXRT1176_cm7_SERIES)
62+
#define USE_BLHOST
6163
extern const flexspi_nor_config_t qspiflash_config_copy;
6264
extern const BOOT_DATA_T g_boot_data_copy;
6365
extern const ivt image_vector_table;
64-
65-
// SDP ivt0 image has ivt at address 0, no FCFB in RAM, cooked boot data use the copies in .text
66-
const uint8_t *fcfb_data = (const uint8_t *)&qspiflash_config_copy;
67-
const uint8_t *boot_data = (const uint8_t *)&g_boot_data_copy;
68-
69-
#else
70-
const uint8_t *fcfb_data = (const uint8_t *)&qspiflash_config;
71-
const uint8_t *boot_data = (const uint8_t *)&g_boot_data;
72-
7366
#endif
7467

75-
static flexspi_nor_config_t flash_cfg;
76-
7768
static uint32_t _flash_page_addr = FLASH_CACHE_INVALID_ADDR;
7869
static uint8_t _flash_cache[SECTOR_SIZE] __attribute__((aligned(4)));
7970

@@ -85,16 +76,24 @@ static uint8_t _flash_cache[SECTOR_SIZE] __attribute__((aligned(4)));
8576
static void write_tinyuf2_to_flash(void) {
8677
TUF2_LOG1("Writing TinyUF2 image to flash.\r\n");
8778

79+
#ifdef USE_BLHOST
80+
// BLHOST load-image with ivt at address 0, no FCFB in RAM, manual write it using copies
8881
// Write FCFB
89-
board_flash_write(FLASH_FCFB_ADDR, fcfb_data, sizeof(flexspi_nor_config_t));
82+
board_flash_write(FLASH_FCFB_ADDR, &qspiflash_config_copy, sizeof(flexspi_nor_config_t));
9083

9184
// Write IVT (image vector table + boot data)
9285
board_flash_write(FLASH_IVT_ADDR, &image_vector_table, sizeof(ivt));
93-
board_flash_write(FLASH_IVT_ADDR + sizeof(ivt), boot_data, sizeof(BOOT_DATA_T));
86+
board_flash_write(FLASH_IVT_ADDR + sizeof(ivt), &g_boot_data_copy, sizeof(BOOT_DATA_T));
87+
// DCD is not used, skip writing it
9488

9589
// Write Interrupts + Text
9690
const uint8_t *image_data = (const uint8_t *)((uint32_t)_interrupts_origin);
9791
uint32_t flash_addr = FLASH_IVT_ADDR + ((uint32_t)_ivt_length);
92+
#else
93+
// SDPHost write from fcfb to end of bootloader
94+
const uint8_t *image_data = (const uint8_t *)&qspiflash_config;
95+
uint32_t flash_addr = FLASH_FCFB_ADDR;
96+
#endif
9897
const uint32_t flash_end = FLEXSPI_FLASH_BASE + BOARD_BOOT_LENGTH;
9998

10099
while (flash_addr < flash_end) {

ports/mimxrt10xx/family.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ set(SDP_MIMXRT1062_PID 0x0135)
3636
set(SDP_MIMXRT1064_PID 0x0135)
3737
set(SDP_MIMXRT1176_PID 0x013d)
3838

39-
set(FLASHLOADER_MIMXRT1176_PID 0x0073)
40-
4139
set(UF2_MIMXRT1011_ADDR 0x60000400)
4240
set(UF2_MIMXRT1015_ADDR 0x60000000)
4341
set(UF2_MIMXRT1021_ADDR 0x60000000)

ports/mimxrt10xx/linker/MIMXRT1011_ram.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ _ocram_size = 64K;
1111
_fcfb_origin = 0x20206400;
1212
_text_length = 32K - 0x400;
1313

14+
_flash_base = 0x60000000;
15+
1416
/*
1517
* MIMXRT1011 Memory Layout
1618
*

ports/mimxrt10xx/linker/MIMXRT1015_ram.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ _ocram_size = 64K;
1111
_fcfb_origin = 0x20208000;
1212
_text_length = 32K - 0x2400;
1313

14+
_flash_base = 0x60000000;
15+
1416
/*
1517
* MIMXRT1015 Memory Layout
1618
*

ports/mimxrt10xx/linker/MIMXRT1021_ram.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ _ocram_size = 128K;
1111
/* The bootrom uses up to 0x20207FFF */
1212
_fcfb_origin = 0x20208000;
1313

14+
_flash_base = 0x60000000;
15+
1416
/*
1517
* MIMXRT1021 Memory Layout
1618
*

ports/mimxrt10xx/linker/MIMXRT1024_ram.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ _ocram_size = 128K;
1111
/* The bootrom uses up to 0x20207FFF */
1212
_fcfb_origin = 0x20208000;
1313

14+
_flash_base = 0x60000000;
15+
1416
/*
1517
* MIMXRT1024 Memory Layout
1618
*

ports/mimxrt10xx/linker/MIMXRT1042_ram.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ _ocram_size = 256K;
1111
/* The bootrom uses up to 0x20207FFF */
1212
_fcfb_origin = 0x20208000;
1313

14+
_flash_base = 0x60000000;
15+
1416
/*
1517
* MIMXRT1042 Memory Layout
1618
*

ports/mimxrt10xx/linker/MIMXRT1052_ram.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ _ocram_size = 256K;
1111
/* The bootrom uses up to 0x20207FFF */
1212
_fcfb_origin = 0x20208000;
1313

14+
_flash_base = 0x60000000;
15+
1416
/*
1517
* MIMXRT1052 Memory Layout
1618
*

ports/mimxrt10xx/linker/MIMXRT1062_ram.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ _ocram_size = 256K;
1515
/* in section 9.6.1.2, so start at 0x1000 */
1616
_fcfb_origin = 0x20208000;
1717

18+
_flash_base = 0x60000000;
19+
1820
/*
1921
* MIMXRT1062 Memory Layout
2022
*

0 commit comments

Comments
 (0)