From 29ce012506759344ef7a1f2ac14421a6efbf7fbb Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Wed, 4 May 2022 16:29:28 +0100 Subject: [PATCH] kl27z_hic: Add ROM bootloader configuration to GCC builds. As done with the armcc builds, this only enables USB in the ROM bootloader, so that any random traffic in the I2C/SPI/UART pins doesn't accidentally trigger the bootloader. --- source/hic_hal/freescale/kinetis.ld | 11 +++++++- .../freescale/kl27z/gcc/startup_MKL27Z4.S | 25 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/source/hic_hal/freescale/kinetis.ld b/source/hic_hal/freescale/kinetis.ld index e07b3ce0a..9647e7061 100644 --- a/source/hic_hal/freescale/kinetis.ld +++ b/source/hic_hal/freescale/kinetis.ld @@ -33,11 +33,13 @@ STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : DAPLINK_STACK_SIZE; /* Specify the memory areas */ MEMORY { - m_interrupts (RX) : ORIGIN = DAPLINK_ROM_APP_START, LENGTH = 0x400 #if defined(DAPLINK_BL) + m_interrupts (RX) : ORIGIN = DAPLINK_ROM_APP_START, LENGTH = 0x3C0 + m_bootloader_config (RX) : ORIGIN = DAPLINK_ROM_APP_START + 0x3C0, LENGTH = 0x40 m_flash_config (RX) : ORIGIN = DAPLINK_ROM_APP_START + 0x400, LENGTH = 0x10 m_text (RX) : ORIGIN = DAPLINK_ROM_APP_START + 0x410, LENGTH = DAPLINK_ROM_APP_SIZE - 0x410 #else + m_interrupts (RX) : ORIGIN = DAPLINK_ROM_APP_START, LENGTH = 0x400 m_text (RX) : ORIGIN = DAPLINK_ROM_APP_START + 0x400, LENGTH = DAPLINK_ROM_APP_SIZE - 0x400 #endif m_cfgrom (RW) : ORIGIN = DAPLINK_ROM_CONFIG_USER_START, LENGTH = DAPLINK_ROM_CONFIG_USER_SIZE @@ -59,6 +61,13 @@ SECTIONS } > m_interrupts #if defined(DAPLINK_BL) + .bootloader_config : + { + . = ALIGN(4); + KEEP(*(.BootloaderConfig)) /* Bootloader Configuration Area (BCA) */ + . = ALIGN(4); + } > m_bootloader_config + .flash_config : { . = ALIGN(4); diff --git a/source/hic_hal/freescale/kl27z/gcc/startup_MKL27Z4.S b/source/hic_hal/freescale/kl27z/gcc/startup_MKL27Z4.S index 5f4a0d557..73e324d21 100644 --- a/source/hic_hal/freescale/kl27z/gcc/startup_MKL27Z4.S +++ b/source/hic_hal/freescale/kl27z/gcc/startup_MKL27Z4.S @@ -77,7 +77,30 @@ __isr_vector: .size __isr_vector, . - __isr_vector #if defined(DAPLINK_BL) - /* TODO: Bootloader Configuration Area (BCA) used by Kinetis ROM Bootloader */ + /* Bootloader Configuration Area (BCA) used by Kinetis ROM Bootloader */ + .section .BootloaderConfig, "a" + .long 0x6766636B /* 0x00 Magic number to verify bootloader configuration is valid. Must be set to 'kcfg'. */ + .long 0xFFFFFFFF /* 0x04 Reserved */ + .long 0xFFFFFFFF /* 0x08 Reserved */ + .long 0xFFFFFFFF /* 0x0C Reserved */ + .byte 0x10 /* 0x10 Bitfield of peripherals to enable. bit 0 LPUART, bit 1 I2C, bit 2 SPI, bit 4 USB. 0x10 = USB only */ + .byte 0xFF /* 0x11 i2cSlaveAddress */ + .byte 0xFF, 0xFF /* 0x12 peripheralDetectionTimeout */ + .byte 0xFF, 0xFF /* 0x14 usbVid */ + .byte 0xFF, 0xFF /* 0x16 usbPid */ + .long 0xFFFFFFFF /* 0x18 usbStringsPointer */ + .byte 0xFF /* 0x1C clockFlags */ + .byte 0xFF /* 0x1D clockDivider */ + .byte 0xFF /* 0x1E bootFlags */ + .byte 0xFF /* 0x1F pad byte */ + .long 0xFFFFFFFF /* 0x20 Reserved */ + .long 0xFFFFFFFF /* 0x24 Reserved */ + .long 0xFFFFFFFF /* 0x28 Reserved */ + .long 0xFFFFFFFF /* 0x2C Reserved */ + .long 0xFFFFFFFF /* 0x30 Reserved */ + .long 0xFFFFFFFF /* 0x34 Reserved */ + .long 0xFFFFFFFF /* 0x38 Reserved */ + .long 0xFFFFFFFF /* 0x3C Reserved */ /* Flash Configuration */ .section .FlashConfig, "a"