From: Keith Packard Date: Mon, 16 Sep 2019 00:05:17 +0000 (-0700) Subject: altos: Move from newlib-nano to picolibc X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=775a3f28bd34763acd81a115a1e8874a17a5ff44;p=fw%2Faltos altos: Move from newlib-nano to picolibc Use picolibc.ld, which involved some .ld file hacking, including: 1) Defining ao_boot RAM address in the .ld file and declaring it 'extern' 2) Changing how m0 interrupt vector got moved to ram 3) Using -Taltos.ld instead of -Wl,-Taltos.ld so picolibc.specs wouldn't add picolibc.ld 4) Placing romconfig vars in '.init.1' and '.init.2' sections instead of '.romconfig' 5) Place code needing to run out of RAM in section .srodata instead of .ramtext Signed-off-by: Keith Packard --- diff --git a/src/Makefile.defs b/src/Makefile.defs index d52cc706..db9a445c 100644 --- a/src/Makefile.defs +++ b/src/Makefile.defs @@ -20,12 +20,11 @@ WARN_FLAGS=-Wall -Wextra -Werror -Wcast-align \ OPT=-Os -NEWLIB_PRINTF_CFLAGS = -DNEWLIB_INTEGER_PRINTF_SCANF +PICOLIBC_PRINTF_CFLAGS = -DPICOLIBC_INTEGER_PRINTF_SCANF -NEWLIB_CFLAGS= \ - -ffreestanding -nostdlib \ - -isystem $(NEWLIB_NANO)/arm-none-eabi/include \ - $(NEWLIB_PRINTF_CFLAGS) +PICOLIBC_CFLAGS= \ + -specs=picolibc.specs \ + $(PICOLIBC_PRINTF_CFLAGS) AO_CFLAGS=\ -std=gnu99 \ diff --git a/src/kernel/ao_product.c b/src/kernel/ao_product.c index 72488654..eaa6c78b 100644 --- a/src/kernel/ao_product.c +++ b/src/kernel/ao_product.c @@ -60,8 +60,12 @@ const char ao_product[] = AO_iProduct_STRING; #define TOTAL_LENGTH (HEADER_LEN + AO_USB_HAS_INT * CONTROL_CLASS_LEN + DATA_LEN) #define NUM_INTERFACES (AO_USB_HAS_INT + 1) +#ifndef AO_USBCONFIG_SYMBOL +#define AO_USBCONFIG_SYMBOL AO_ROMCONFIG_SYMBOL +#endif + /* USB descriptors in one giant block of bytes */ -AO_ROMCONFIG_SYMBOL uint8_t ao_usb_descriptors [] = +AO_USBCONFIG_SYMBOL uint8_t ao_usb_descriptors [] = { /* Device descriptor */ 0x12, diff --git a/src/lpc/Makefile-flash.defs b/src/lpc/Makefile-flash.defs index 44b43bfe..a70b0073 100644 --- a/src/lpc/Makefile-flash.defs +++ b/src/lpc/Makefile-flash.defs @@ -35,7 +35,7 @@ IDPRODUCT=0x000a CFLAGS = $(PRODUCT_DEF) $(LPC_CFLAGS) -LDFLAGS=$(CFLAGS) -L$(TOPDIR)/lpc -Wl,-Taltos-loader.ld +LDFLAGS=$(CFLAGS) -L$(TOPDIR)/lpc -Taltos-loader.ld PROGNAME=altos-flash PROG=$(HARDWARE)-$(PROGNAME)-$(VERSION).elf diff --git a/src/lpc/Makefile-lpc.defs b/src/lpc/Makefile-lpc.defs index 8b297351..fb3747dd 100644 --- a/src/lpc/Makefile-lpc.defs +++ b/src/lpc/Makefile-lpc.defs @@ -8,7 +8,7 @@ vpath % $(TOPDIR)/lpc:$(AO_VPATH) CC=$(ARM_CC) -LIBS=-L$(NEWLIB_NANO)/arm-none-eabi/lib/thumb/v6-m -lc -lm -lgcc +LIBS=-lm LPC_CFLAGS=-mlittle-endian -mcpu=cortex-m0 -mthumb\ - -I$(TOPDIR)/lpc $(AO_CFLAGS) $(NEWLIB_CFLAGS) + -I$(TOPDIR)/lpc $(AO_CFLAGS) $(PICOLIBC_CFLAGS) diff --git a/src/lpc/Makefile.defs b/src/lpc/Makefile.defs index 7fdcf0dc..5c62fa2b 100644 --- a/src/lpc/Makefile.defs +++ b/src/lpc/Makefile.defs @@ -4,7 +4,7 @@ endif include $(TOPDIR)/lpc/Makefile-lpc.defs -LDFLAGS=$(CFLAGS) -L$(TOPDIR)/lpc -Wl,-Taltos.ld -n +LDFLAGS=$(CFLAGS) -L$(TOPDIR)/lpc -Taltos.ld -n ao_serial_lpc.h: $(TOPDIR)/lpc/baud_rate ao_pins.h nickle $(TOPDIR)/lpc/baud_rate `awk '/AO_LPC_CLKOUT/{print $$3}' ao_pins.h` > $@ diff --git a/src/lpc/altos-loader.ld b/src/lpc/altos-loader.ld index be4f115d..547da2db 100644 --- a/src/lpc/altos-loader.ld +++ b/src/lpc/altos-loader.ld @@ -16,66 +16,12 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -MEMORY { - rom : ORIGIN = 0x00000000, LENGTH = 4K - ram : ORIGIN = 0x10000000, LENGTH = 4k - 128 - 32 - usb (!x) : ORIGIN = 0x20004000 + 2K - 256, LENGTH = 256 - stack (!w) : ORIGIN = 0x10000000 + 4K - 128 - 32, LENGTH = 128 -} +__flash = 0x0; +__flash_size = 4K; +ao_boot = 0x100000c0; +__ram = 0x10000000 + 256; +__ram_size = 4k - 256; +__stack_size = 128; INCLUDE registers.ld - -EXTERN (lpc_interrupt_vector) - -SECTIONS { - /* - * Rom contents - */ - - .interrupt : { - __text_start__ = .; - *(.interrupt) /* Interrupt vectors */ - - } > rom - - .text ORIGIN(rom) + 0x100 : { - ao_romconfig.o(.romconfig*) - ao_product.o(.romconfig*) - - *(.text*) /* Executable code */ - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - *(.rodata*) /* Constants */ - __text_end__ = .; - } > rom - - /* Boot data which must live at the start of ram so that - * the application and bootloader share the same addresses. - * This must be all uninitialized data - */ - .boot ORIGIN(ram) + SIZEOF(.interrupt) (NOLOAD) : { - __boot_start__ = .; - *(.boot*) - __boot_end__ = .; - } >ram - - /* Data -- relocated to RAM, but written to ROM - */ - .data : { - _start__ = .; - *(.data*) /* initialized data */ - _end__ = .; - } >ram AT>rom - - - .bss : { - __bss_start__ = .; - *(.bss*) - *(COMMON*) - __bss_end__ = .; - } >ram - - PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram)); - PROVIDE(end = .); -} - -ENTRY(start); +INCLUDE picolibc.ld diff --git a/src/lpc/altos.ld b/src/lpc/altos.ld index 028ad775..37b25dc0 100644 --- a/src/lpc/altos.ld +++ b/src/lpc/altos.ld @@ -16,76 +16,13 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -MEMORY { - rom (rx) : ORIGIN = 0x00001000, LENGTH = 28K - ram (!w) : ORIGIN = 0x10000000, LENGTH = 4K - 128 - usb (!x) : ORIGIN = 0x20004000 + 2K - 256, LENGTH = 256 - stack (!w) : ORIGIN = 0x10000000 + 4K - 128, LENGTH = 128 -} +__flash = 0x1000; +__flash_size = 28K; +__interrupt_start = 0x10000000; +ao_boot = 0x100000c0; +__ram = 0x10000000 + 256; +__ram_size = 4k - 256; +__stack_size = 128; INCLUDE registers.ld - -EXTERN (lpc_interrupt_vector) - -SECTIONS { - /* - * Rom contents - */ - - .interrupt ORIGIN(ram) : AT (ORIGIN(rom)) { - __interrupt_start__ = .; - __interrupt_rom__ = ORIGIN(rom); - *(.interrupt) /* Interrupt vectors */ - __interrupt_end__ = .; - } > ram - - .text ORIGIN(rom) + 0x100 : { - __text_start__ = .; - - ao_romconfig.o(.romconfig*) - ao_product.o(.romconfig*) - - *(.text*) /* Executable code */ - *(.rodata*) /* Constants */ - - } > rom - - .ARM.exidx : { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - __text_end__ = .; - } > rom - - /* Boot data which must live at the start of ram so that - * the application and bootloader share the same addresses. - * This must be all uninitialized data - */ - .boot : { - __boot_start__ = .; - *(.boot) - . = ALIGN(4); - __boot_end__ = .; - } >ram - - /* Data -- relocated to RAM, but written to ROM - */ - .data : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) { - _start__ = .; - *(.data) /* initialized data */ - _end__ = .; - __bss_start__ = .; - } >ram - - .bss : { - __bss_start__ = .; - *(.bss) - *(COMMON) - __bss_end__ = .; - } >ram - PROVIDE(end = .); - - PROVIDE(__stack__ = ORIGIN(stack) + LENGTH(stack)); -} - -ENTRY(start); - - +INCLUDE picolibc.ld diff --git a/src/lpc/ao_arch.h b/src/lpc/ao_arch.h index 93676b86..c638aa22 100644 --- a/src/lpc/ao_arch.h +++ b/src/lpc/ao_arch.h @@ -53,7 +53,8 @@ * ao_romconfig.c */ -#define AO_ROMCONFIG_SYMBOL __attribute__((section(".romconfig"))) const +#define AO_ROMCONFIG_SYMBOL __attribute__((section(".init.1"))) const +#define AO_USBCONFIG_SYMBOL __attribute__((section(".init.2"))) const #define ao_arch_block_interrupts() asm("cpsid i") #define ao_arch_release_interrupts() asm("cpsie i") diff --git a/src/lpc/ao_boot_chain.c b/src/lpc/ao_boot_chain.c index 0d0bb91c..dc3ecff8 100644 --- a/src/lpc/ao_boot_chain.c +++ b/src/lpc/ao_boot_chain.c @@ -43,7 +43,7 @@ struct ao_boot { uint32_t check; }; -static struct ao_boot __attribute__ ((section(".boot"))) ao_boot; +extern struct ao_boot ao_boot; int ao_boot_check_chain(void) diff --git a/src/lpc/ao_interrupt.c b/src/lpc/ao_interrupt.c index 8d71f43f..f2c16806 100644 --- a/src/lpc/ao_interrupt.c +++ b/src/lpc/ao_interrupt.c @@ -29,15 +29,6 @@ #define RELOCATE_INTERRUPT 1 #endif -extern void main(void); -extern char __stack__; -extern char __text_start__, __text_end__; -extern char _start__, _end__; -extern char __bss_start__, __bss_end__; -#if RELOCATE_INTERRUPT -extern char __interrupt_rom__, __interrupt_start__, __interrupt_end__; -#endif - /* Interrupt functions */ void lpc_halt_isr(void) @@ -49,23 +40,6 @@ void lpc_ignore_isr(void) { } -void start(void) { -#ifdef AO_BOOT_CHAIN - if (ao_boot_check_chain()) { -#ifdef AO_BOOT_PIN - ao_boot_check_pin(); -#endif - } -#endif -#if RELOCATE_INTERRUPT - memcpy(&__interrupt_start__, &__interrupt_rom__, &__interrupt_end__ - &__interrupt_start__); - lpc_scb.sysmemremap = LPC_SCB_SYSMEMREMAP_MAP_RAM << LPC_SCB_SYSMEMREMAP_MAP; -#endif - memcpy(&_start__, &__text_end__, &_end__ - &_start__); - memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__); - main(); -} - #define STRINGIFY(x) #x #define isr(name) \ @@ -119,10 +93,13 @@ isr(usb_wakeup) #define i(addr,name) [(addr)/4] = lpc_ ## name ## _isr #define c(addr,value) [(addr)/4] = (value) -__attribute__ ((section(".interrupt"))) -const void *lpc_interrupt_vector[] = { - [0] = &__stack__, - [1] = start, +extern char __stack[]; +extern void _start(void); + +__attribute__ ((section(".init"))) +const void *const lpc_interrupt_vector[0x40] = { + [0] = __stack, + [1] = _start, i(0x08, nmi), i(0x0c, hardfault), c(0x10, 0), @@ -175,3 +152,24 @@ const void *lpc_interrupt_vector[] = { i(0xb8, usb_wakeup), i(0xbc, hardfault), }; + +extern char __interrupt_start[]; + +void _init(void); + +void _init(void) +{ +#ifdef AO_BOOT_CHAIN + if (ao_boot_check_chain()) { +#ifdef AO_BOOT_PIN + ao_boot_check_pin(); +#endif + } +#endif +#if RELOCATE_INTERRUPT + /* This will erase the boot chain data */ + memcpy(__interrupt_start, lpc_interrupt_vector, sizeof (lpc_interrupt_vector)); + lpc_scb.sysmemremap = LPC_SCB_SYSMEMREMAP_MAP_RAM << LPC_SCB_SYSMEMREMAP_MAP; +#endif +} + diff --git a/src/micropeak-v2.0/Makefile b/src/micropeak-v2.0/Makefile index f1f57440..37e1d2b7 100644 --- a/src/micropeak-v2.0/Makefile +++ b/src/micropeak-v2.0/Makefile @@ -71,10 +71,10 @@ OBJ=$(SRC:.c=.o) all: $(PROG) $(HEX) -LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Wl,-Tmicropeak.ld -n +LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Tmicropeak.ld -n $(PROG): Makefile $(OBJ) micropeak.ld - $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) + $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) -Wl,-Map=$(PROGNAME)-$(VERSION).map distclean: clean diff --git a/src/micropeak-v2.0/micropeak.ld b/src/micropeak-v2.0/micropeak.ld index a73d4c1d..cee1b4b6 100644 --- a/src/micropeak-v2.0/micropeak.ld +++ b/src/micropeak-v2.0/micropeak.ld @@ -16,108 +16,15 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -MEMORY { - rom (rx) : ORIGIN = 0x08001000, LENGTH = 20K - flash(rx) : ORIGIN = 0x08006000, LENGTH = 8K - ram (!w) : ORIGIN = 0x20000000, LENGTH = 6k - 512 - stack (!w) : ORIGIN = 0x20000000 + 6k - 512, LENGTH = 512 -} +__flash = 0x08001000; +__flash_size = 22K; +__flash__ = __flash + __flash_size; +__flash_end__ = __flash__ + 6K; +__interrupt_start = 0x20000000; +ao_boot = 0x200000c0; +__ram = 0x20000000 + 256; +__ram_size = 6K - 256; +__stack_size = 512; INCLUDE registers.ld - -EXTERN (stm_interrupt_vector) - -SECTIONS { - /* - * Rom contents - */ - - .interrupt ORIGIN(ram) : AT (ORIGIN(rom)) { - __interrupt_start__ = .; - __interrupt_rom__ = ORIGIN(rom); - *(.interrupt) /* Interrupt vectors */ - __interrupt_end__ = .; - } > ram - - .text ORIGIN(rom) + 0x100 : { - __text_start__ = .; - - /* Ick. What I want is to specify the - * addresses of some global constants so - * that I can find them across versions - * of the application. I can't figure out - * how to make gnu ld do that, so instead - * we just load the two files that include - * these defines in the right order here and - * expect things to 'just work'. Don't change - * the contents of those files, ok? - */ - ao_romconfig.o(.romconfig*) - ao_product.o(.romconfig*) - - *(.text*) /* Executable code */ - } > rom - - .ARM.exidx : { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > rom - - .rodata : { - *(.rodata*) /* Constants */ - } > rom - - __text_end__ = .; - - /* Boot data which must live at the start of ram so that - * the application and bootloader share the same addresses. - * This must be all uninitialized data - */ - .boot (NOLOAD) : { - __boot_start__ = .; - *(.boot) - . = ALIGN(4); - __boot_end__ = .; - } >ram - - /* Functions placed in RAM (required for flashing) - * - * Align to 8 bytes as that's what the ARM likes text - * segment alignments to be, and if we don't, then - * we end up with a mismatch between the location in - * ROM and the desired location in RAM. I don't - * entirely understand this, but at least this appears - * to work... - */ - - .textram BLOCK(8): { - _start__ = .; - *(.ramtext) - } >ram AT>rom - - /* Data -- relocated to RAM, but written to ROM, - * also aligned to 8 bytes to agree with textram - */ - .data BLOCK(8): { - *(.data) /* initialized data */ - _end__ = .; - } >ram AT>rom - - .bss : { - __bss_start__ = .; - *(.bss) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } >ram - - PROVIDE(end = .); - - PROVIDE(__flash__ = ORIGIN(flash)); - PROVIDE(__flash_end__ = ORIGIN(flash) + LENGTH(flash)); - - PROVIDE(__stack__ = ORIGIN(stack) + LENGTH(stack)); -} - -ENTRY(start); - - +INCLUDE picolibc.ld diff --git a/src/pnpservo-v1/lambda.ld b/src/pnpservo-v1/lambda.ld index d3edbe9f..20b3ace7 100644 --- a/src/pnpservo-v1/lambda.ld +++ b/src/pnpservo-v1/lambda.ld @@ -87,7 +87,7 @@ SECTIONS { .textram BLOCK(8): { _start__ = .; __text_ram_start__ = .; - *(.ramtext) + *(.srodata) __text_ram_end = .; } >ram AT>rom diff --git a/src/stm/Makefile-flash.defs b/src/stm/Makefile-flash.defs index 08a4b177..a02be9c1 100644 --- a/src/stm/Makefile-flash.defs +++ b/src/stm/Makefile-flash.defs @@ -35,13 +35,13 @@ IDPRODUCT=0x000a CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS) -LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stm -Wl,-Taltos-loader.ld -n +LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stm -Taltos-loader.ld -n PROGNAME=altos-flash PROG=$(HARDWARE)-$(PROGNAME)-$(VERSION).elf $(PROG): Makefile $(OBJ) altos-loader.ld - $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS) + $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) $(OBJ): $(INC) diff --git a/src/stm/Makefile-stm.defs b/src/stm/Makefile-stm.defs index cce28f00..f3fd9de6 100644 --- a/src/stm/Makefile-stm.defs +++ b/src/stm/Makefile-stm.defs @@ -7,7 +7,7 @@ include $(TOPDIR)/Makefile.defs vpath % $(TOPDIR)/stm:$(AO_VPATH) CC=$(ARM_CC) -LIBS=-L$(NEWLIB_NANO)/arm-none-eabi/lib/thumb/v7-m -lm -lc -lgcc +LIBS=-lm STM_CFLAGS=-mlittle-endian -mcpu=cortex-m3 -mthumb \ - -I$(TOPDIR)/stm $(AO_CFLAGS) $(NEWLIB_CFLAGS) + -I$(TOPDIR)/stm $(AO_CFLAGS) $(PICOLIBC_CFLAGS) diff --git a/src/stm/Makefile.defs b/src/stm/Makefile.defs index 26ba5824..2ed89f7e 100644 --- a/src/stm/Makefile.defs +++ b/src/stm/Makefile.defs @@ -4,4 +4,4 @@ endif include $(TOPDIR)/stm/Makefile-stm.defs -LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stm -Wl,-Taltos.ld -n +LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stm -Taltos.ld -n diff --git a/src/stm/altos-loader.ld b/src/stm/altos-loader.ld index 1ebbc7a2..756babf5 100644 --- a/src/stm/altos-loader.ld +++ b/src/stm/altos-loader.ld @@ -16,81 +16,12 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -MEMORY { - rom : ORIGIN = 0x08000000, LENGTH = 4K - ram : ORIGIN = 0x20000000, LENGTH = 16K -} +__flash = 0x08000000; +__flash_size = 4K; +ao_boot = 0x100000c0; +__ram = 0x10000000 + 256; +__ram_size = 16K - 256; +__stack_size = 512; INCLUDE registers.ld - -EXTERN (stm_interrupt_vector) - -SECTIONS { - /* - * Rom contents - */ - - .text : { - __text_start__ = .; - *(.interrupt) /* Interrupt vectors */ - - . = ORIGIN(rom) + 0x100; - - ao_romconfig.o(.romconfig*) - ao_product.o(.romconfig*) - *(.text*) /* Executable code */ - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - *(.rodata*) /* Constants */ - } > rom - __text_end__ = .; - - /* Boot data which must live at the start of ram so that - * the application and bootloader share the same addresses. - * This must be all uninitialized data - */ - .boot (NOLOAD) : { - __boot_start__ = .; - *(.boot) - __boot_end__ = .; - } >ram - - /* Functions placed in RAM (required for flashing) - * - * Align to 8 bytes as that's what the ARM likes text - * segment alignments to be, and if we don't, then - * we end up with a mismatch between the location in - * ROM and the desired location in RAM. I don't - * entirely understand this, but at least this appears - * to work... - */ - - .textram BLOCK(8): { - _start__ = .; - __text_ram_start__ = .; - *(.ramtext) - __text_ram_end = .; - } >ram AT>rom - - /* Data -- relocated to RAM, but written to ROM - * Also aligned to 8 bytes to agree with textram - */ - .data BLOCK(8): { - *(.data) /* initialized data */ - _end__ = .; - } >ram AT>rom - - - .bss : { - __bss_start__ = .; - *(.bss) - *(COMMON) - __bss_end__ = .; - } >ram - - PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram)); - PROVIDE(end = .); -} - -ENTRY(start); - - +INCLUDE picolibc.ld diff --git a/src/stm/altos.ld b/src/stm/altos.ld index e352ed36..fb142df6 100644 --- a/src/stm/altos.ld +++ b/src/stm/altos.ld @@ -16,83 +16,14 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -MEMORY { - rom (rx) : ORIGIN = 0x08001000, LENGTH = 124K - ram (!w) : ORIGIN = 0x20000000, LENGTH = 15872 - stack (!w) : ORIGIN = 0x20003e00, LENGTH = 512 -} +__flash = 0x08001000; +__flash_size = 124K; +ao_boot = 0x20000000; +/* just past ao_boot */ +__ram = 0x2000000c; +/* leave out ao_boot */ +__ram_size = 16k - 12; +__stack_size = 512; INCLUDE registers.ld - -EXTERN (stm_interrupt_vector) - -SECTIONS { - /* - * Rom contents - */ - - .text ORIGIN(rom) : { - __text_start__ = .; - *(.interrupt) /* Interrupt vectors */ - - . = ORIGIN(rom) + 0x100; - - - /* Ick. What I want is to specify the - * addresses of some global constants so - * that I can find them across versions - * of the application. I can't figure out - * how to make gnu ld do that, so instead - * we just load the two files that include - * these defines in the right order here and - * expect things to 'just work'. Don't change - * the contents of those files, ok? - */ - ao_romconfig.o(.romconfig*) - ao_product.o(.romconfig*) - *(.text*) /* Executable code */ - *(.rodata*) /* Constants */ - - } > rom - - .ARM.exidx : { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > rom - __text_end__ = .; - - /* Boot data which must live at the start of ram so that - * the application and bootloader share the same addresses. - * This must be all uninitialized data - */ - .boot (NOLOAD) : { - __boot_start__ = .; - *(.boot) - . = ALIGN(4); - __boot_end__ = .; - } >ram - - /* Data -- relocated to RAM, but written to ROM - */ - .data : { - _start__ = .; - *(.data) /* initialized data */ - . = ALIGN(4); - _end__ = .; - } >ram AT>rom - - .bss : { - __bss_start__ = .; - *(.bss) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } >ram - - PROVIDE(end = .); - - PROVIDE(__stack__ = ORIGIN(stack) + LENGTH(stack)); -} - -ENTRY(start); - - +INCLUDE picolibc.ld diff --git a/src/stm/ao_arch.h b/src/stm/ao_arch.h index e83b6bd2..e3094c6a 100644 --- a/src/stm/ao_arch.h +++ b/src/stm/ao_arch.h @@ -51,7 +51,8 @@ * ao_romconfig.c */ -#define AO_ROMCONFIG_SYMBOL __attribute__((section(".romconfig"))) const +#define AO_ROMCONFIG_SYMBOL __attribute__((section(".init.1"))) const +#define AO_USBCONFIG_SYMBOL __attribute__((section(".init.2"))) const /* * For now, we're running at a weird frequency diff --git a/src/stm/ao_boot_chain.c b/src/stm/ao_boot_chain.c index 488af1e1..5834827b 100644 --- a/src/stm/ao_boot_chain.c +++ b/src/stm/ao_boot_chain.c @@ -43,8 +43,8 @@ struct ao_boot { uint32_t check; }; -static struct ao_boot __attribute__ ((section(".boot"))) ao_boot; - +extern struct ao_boot ao_boot; + int ao_boot_check_chain(void) { diff --git a/src/stm/ao_flash_stm.c b/src/stm/ao_flash_stm.c index 38618bbe..3dcbaea6 100644 --- a/src/stm/ao_flash_stm.c +++ b/src/stm/ao_flash_stm.c @@ -70,7 +70,7 @@ ao_flash_wait_bsy(void) ; } -static void __attribute__ ((section(".ramtext"),noinline)) +static void __attribute__ ((section(".srodata"),noinline)) _ao_flash_erase_page(uint32_t *page) { stm_flash.pecr |= (1 << STM_FLASH_PECR_ERASE) | (1 << STM_FLASH_PECR_PROG); @@ -93,7 +93,7 @@ ao_flash_erase_page(uint32_t *page) ao_arch_release_interrupts(); } -static void __attribute__ ((section(".ramtext"), noinline)) +static void __attribute__ ((section(".srodata"), noinline)) _ao_flash_half_page(uint32_t *dst, uint32_t *src) { uint8_t i; diff --git a/src/stm/ao_interrupt.c b/src/stm/ao_interrupt.c index d8be3667..5738014e 100644 --- a/src/stm/ao_interrupt.c +++ b/src/stm/ao_interrupt.c @@ -22,10 +22,6 @@ #include extern void main(void); -extern char __stack__; -extern char __text_start__, __text_end__; -extern char _start__, _end__; -extern char __bss_start__, __bss_end__; /* Interrupt functions */ @@ -38,7 +34,7 @@ void stm_ignore_isr(void) { } -const void *stm_interrupt_vector[]; +void *const stm_interrupt_vector[]; uint32_t stm_flash_size(void) { @@ -72,8 +68,11 @@ stm_flash_size(void) { return (uint32_t) kbytes * 1024; } -void start(void) -{ +extern char __stack[]; + +void _init(void); + +void _init(void) { #ifdef AO_BOOT_CHAIN if (ao_boot_check_chain()) { #ifdef AO_BOOT_PIN @@ -83,9 +82,6 @@ void start(void) #endif /* Set interrupt vector table offset */ stm_nvic.vto = (uint32_t) &stm_interrupt_vector; - memcpy(&_start__, &__text_end__, &_end__ - &_start__); - memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__); - main(); } #define STRINGIFY(x) #x @@ -155,10 +151,16 @@ isr(tim7) #define i(addr,name) [(addr)/4] = stm_ ## name ## _isr -__attribute__ ((section(".interrupt"))) -const void *stm_interrupt_vector[] = { - [0] = &__stack__, - [1] = start, +extern void _start(void); + +/* This must be exactly 256 bytes long so that the configuration data + * gets loaded at the right place + */ + +__attribute__ ((section(".init"))) +void * const stm_interrupt_vector[64] = { + [0] = &__stack, + [1] = _start, i(0x08, nmi), i(0x0c, hardfault), i(0x10, memmanage), diff --git a/src/stm32f4/altos-loader.ld b/src/stm32f4/altos-loader.ld index 5d6e1f4b..9a46987f 100644 --- a/src/stm32f4/altos-loader.ld +++ b/src/stm32f4/altos-loader.ld @@ -68,7 +68,7 @@ SECTIONS { .textram BLOCK(8): { _start__ = .; __text_ram_start__ = .; - *(.ramtext) + *(.srodata) __text_ram_end = .; } >ram AT>rom diff --git a/src/stmf0/Makefile-flash.defs b/src/stmf0/Makefile-flash.defs index b6e44990..eec4c568 100644 --- a/src/stmf0/Makefile-flash.defs +++ b/src/stmf0/Makefile-flash.defs @@ -35,7 +35,7 @@ IDPRODUCT=0x000a CFLAGS = $(PRODUCT_DEF) $(STMF0_CFLAGS) -LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Wl,-Taltos-loader.ld +LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Taltos-loader.ld PROGNAME=altos-flash PROG=$(HARDWARE)-$(PROGNAME)-$(VERSION).elf @@ -47,7 +47,7 @@ FLASH_ADDR=0x08000000 all: $(PROG) $(BIN) $(PROG): Makefile $(OBJ) altos-loader.ld - $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS) + $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) $(BIN): $(PROG) $(MAKEBIN) --output=$@ --base=$(FLASH_ADDR) $(PROG) diff --git a/src/stmf0/Makefile-stmf0.defs b/src/stmf0/Makefile-stmf0.defs index 5a883adf..f3add106 100644 --- a/src/stmf0/Makefile-stmf0.defs +++ b/src/stmf0/Makefile-stmf0.defs @@ -9,6 +9,6 @@ vpath % $(TOPDIR)/stmf0:$(AO_VPATH) CC=$(ARM_CC) STMF0_CFLAGS=-mlittle-endian -mcpu=cortex-m0 -mthumb\ - -I$(TOPDIR)/stmf0 $(AO_CFLAGS) $(NEWLIB_CFLAGS) + -I$(TOPDIR)/stmf0 $(AO_CFLAGS) $(PICOLIBC_CFLAGS) -LIBS=-L$(NEWLIB_NANO)/arm-none-eabi/lib/thumb/v6-m -lc -lm -lgcc +LIBS=-lm diff --git a/src/stmf0/Makefile.defs b/src/stmf0/Makefile.defs index 2baba4f2..ffce3257 100644 --- a/src/stmf0/Makefile.defs +++ b/src/stmf0/Makefile.defs @@ -4,7 +4,7 @@ endif include $(TOPDIR)/stmf0/Makefile-stmf0.defs -LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Wl,-Taltos.ld -n +LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Taltos.ld -n LOADER=flash-loader/$(PROGNAME)-altos-flash-$(VERSION).elf MAKEBIN=$(TOPDIR)/../ao-tools/ao-makebin/ao-makebin diff --git a/src/stmf0/altos-loader.ld b/src/stmf0/altos-loader.ld index 4d9b81ae..2f3bd383 100644 --- a/src/stmf0/altos-loader.ld +++ b/src/stmf0/altos-loader.ld @@ -16,82 +16,12 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -MEMORY { - rom : ORIGIN = 0x08000000, LENGTH = 4K - ram : ORIGIN = 0x20000000, LENGTH = 6K -} +__flash = 0x08000000; +__flash_size = 4K; +ao_boot = 0x200000c0; +__ram = 0x20000000 + 256; +__ram_size = 6k - 256; +__stack_size = 128; INCLUDE registers.ld - -EXTERN (stm_interrupt_vector) - -SECTIONS { - /* - * Rom contents - */ - - .interrupt : { - __text_start__ = .; - *(.interrupt) /* Interrupt vectors */ - } > rom - - .text ORIGIN(rom) + 0x100 : { - ao_romconfig.o(.romconfig*) - ao_product.o(.romconfig*) - - *(.text*) /* Executable code */ - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - *(.rodata*) /* Constants */ - } > rom - __text_end__ = .; - - /* Boot data which must live at the start of ram so that - * the application and bootloader share the same addresses. - * This must be all uninitialized data - */ - .boot ORIGIN(ram) + SIZEOF(.interrupt) (NOLOAD) : { - __boot_start__ = .; - *(.boot) - __boot_end__ = .; - } >ram - - /* Functions placed in RAM (required for flashing) - * - * Align to 8 bytes as that's what the ARM likes text - * segment alignments to be, and if we don't, then - * we end up with a mismatch between the location in - * ROM and the desired location in RAM. I don't - * entirely understand this, but at least this appears - * to work... - */ - - .textram BLOCK(8): { - _start__ = .; - __text_ram_start__ = .; - *(.ramtext) - __text_ram_end = .; - } >ram AT>rom - - /* Data -- relocated to RAM, but written to ROM. - * also aligned to 8 bytes in case textram is empty - */ - .data BLOCK(8): { - *(.data) /* initialized data */ - _end__ = .; - } >ram AT>rom - - - .bss : { - __bss_start__ = .; - *(.bss) - *(COMMON) - __bss_end__ = .; - } >ram - - PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram)); - PROVIDE(end = .); -} - -ENTRY(start); - - +INCLUDE picolibc.ld diff --git a/src/stmf0/altos.ld b/src/stmf0/altos.ld index 64e1d00c..19f257ea 100644 --- a/src/stmf0/altos.ld +++ b/src/stmf0/altos.ld @@ -16,90 +16,13 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -MEMORY { - rom (rx) : ORIGIN = 0x08001000, LENGTH = 28K - ram (!w) : ORIGIN = 0x20000000, LENGTH = 6k - 128 - stack (!w) : ORIGIN = 0x20000000 + 6k - 128, LENGTH = 128 -} +__flash = 0x08001000; +__flash_size = 28K; +__interrupt_start = 0x20000000; +ao_boot = 0x200000c0; +__ram = 0x20000000 + 256; +__ram_size = 6k - 256; +__stack_size = 128; INCLUDE registers.ld - -EXTERN (stm_interrupt_vector) - -SECTIONS { - /* - * Rom contents - */ - - .interrupt ORIGIN(ram) : AT (ORIGIN(rom)) { - __interrupt_start__ = .; - __interrupt_rom__ = ORIGIN(rom); - *(.interrupt) /* Interrupt vectors */ - __interrupt_end__ = .; - } > ram - - .text ORIGIN(rom) + 0x100 : { - __text_start__ = .; - - /* Ick. What I want is to specify the - * addresses of some global constants so - * that I can find them across versions - * of the application. I can't figure out - * how to make gnu ld do that, so instead - * we just load the two files that include - * these defines in the right order here and - * expect things to 'just work'. Don't change - * the contents of those files, ok? - */ - ao_romconfig.o(.romconfig*) - ao_product.o(.romconfig*) - - *(.text*) /* Executable code */ - } > rom - - .ARM.exidx : { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > rom - - .rodata : { - *(.rodata*) /* Constants */ - } > rom - - __text_end__ = .; - - /* Boot data which must live at the start of ram so that - * the application and bootloader share the same addresses. - * This must be all uninitialized data - */ - .boot (NOLOAD) : { - __boot_start__ = .; - *(.boot) - . = ALIGN(4); - __boot_end__ = .; - } >ram - - /* Data -- relocated to RAM, but written to ROM - */ - .data : { - _start__ = .; - *(.data) /* initialized data */ - . = ALIGN(4); - _end__ = .; - } >ram AT>rom - - .bss : { - __bss_start__ = .; - *(.bss) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } >ram - - PROVIDE(end = .); - - PROVIDE(__stack__ = ORIGIN(stack) + LENGTH(stack)); -} - -ENTRY(start); - - +INCLUDE picolibc.ld diff --git a/src/stmf0/ao_arch.h b/src/stmf0/ao_arch.h index d70a9110..47ac7278 100644 --- a/src/stmf0/ao_arch.h +++ b/src/stmf0/ao_arch.h @@ -53,7 +53,8 @@ * ao_romconfig.c */ -#define AO_ROMCONFIG_SYMBOL __attribute__((section(".romconfig"))) const +#define AO_ROMCONFIG_SYMBOL __attribute__((section(".init.1"))) const +#define AO_USBCONFIG_SYMBOL __attribute__((section(".init.2"))) const extern const uint16_t ao_romconfig_version; extern const uint16_t ao_romconfig_check; diff --git a/src/stmf0/ao_boot_chain.c b/src/stmf0/ao_boot_chain.c index 8f850a0a..5834827b 100644 --- a/src/stmf0/ao_boot_chain.c +++ b/src/stmf0/ao_boot_chain.c @@ -43,7 +43,7 @@ struct ao_boot { uint32_t check; }; -static struct ao_boot __attribute__ ((section(".boot"))) ao_boot; +extern struct ao_boot ao_boot; int ao_boot_check_chain(void) diff --git a/src/stmf0/ao_flash_stm.c b/src/stmf0/ao_flash_stm.c index 2d57eea7..1445950c 100644 --- a/src/stmf0/ao_flash_stm.c +++ b/src/stmf0/ao_flash_stm.c @@ -52,7 +52,7 @@ ao_flash_lock(void) #define ao_flash_wait_bsy() do { while (stm_flash.sr & (1 << STM_FLASH_SR_BSY)); } while (0) -static void __attribute__ ((section(".ramtext"),noinline)) +static void __attribute__ ((section(".srodata"),noinline)) _ao_flash_erase_page(uint32_t *page) { stm_flash.cr |= (1 << STM_FLASH_CR_PER); @@ -103,7 +103,7 @@ ao_flash_erase_page(uint32_t *page) ao_arch_release_interrupts(); } -static void __attribute__ ((section(".ramtext"), noinline)) +static void __attribute__ ((section(".srodata"), noinline)) _ao_flash_page(uint16_t *dst, uint16_t *src) { uint8_t i; diff --git a/src/stmf0/ao_interrupt.c b/src/stmf0/ao_interrupt.c index 0025de47..1e6c717f 100644 --- a/src/stmf0/ao_interrupt.c +++ b/src/stmf0/ao_interrupt.c @@ -32,15 +32,6 @@ #endif #endif -extern void main(void); -extern char __stack__; -extern char __text_start__, __text_end__; -extern char _start__, _end__; -extern char __bss_start__, __bss_end__; -#if RELOCATE_INTERRUPT -extern char __interrupt_rom__, __interrupt_start__, __interrupt_end__; -#endif - /* Interrupt functions */ void stm_halt_isr(void) @@ -52,8 +43,6 @@ void stm_ignore_isr(void) { } -const void *stm_interrupt_vector[]; - uint32_t stm_flash_size(void) { uint16_t dev_id = stm_dev_id(); @@ -67,32 +56,6 @@ stm_flash_size(void) { return (uint32_t) kbytes * 1024; } -void start(void) -{ -#if AO_BOOT_CHAIN - if (ao_boot_check_chain()) { -#if AO_BOOT_PIN - ao_boot_check_pin(); -#endif - } -#endif - /* Turn on syscfg */ - stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_SYSCFGCOMPEN); - -#if RELOCATE_INTERRUPT - memcpy(&__interrupt_start__, &__interrupt_rom__, &__interrupt_end__ - &__interrupt_start__); - stm_syscfg.cfgr1 = (stm_syscfg.cfgr1 & ~(STM_SYSCFG_CFGR1_MEM_MODE_MASK << STM_SYSCFG_CFGR1_MEM_MODE)) | - (STM_SYSCFG_CFGR1_MEM_MODE_SRAM << STM_SYSCFG_CFGR1_MEM_MODE); -#else - /* Switch to Main Flash mode (DFU loader leaves us in System mode) */ - stm_syscfg.cfgr1 = (stm_syscfg.cfgr1 & ~(STM_SYSCFG_CFGR1_MEM_MODE_MASK << STM_SYSCFG_CFGR1_MEM_MODE)) | - (STM_SYSCFG_CFGR1_MEM_MODE_MAIN_FLASH << STM_SYSCFG_CFGR1_MEM_MODE); -#endif - memcpy(&_start__, &__text_end__, &_end__ - &_start__); - memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__); - main(); -} - #define STRINGIFY(x) #x #define isr(name) \ @@ -150,10 +113,13 @@ isr(usb) #define i(addr,name) [(addr)/4] = stm_ ## name ## _isr -__attribute__ ((section(".interrupt"))) -const void *stm_interrupt_vector[] = { - [0] = &__stack__, - [1] = start, +extern char __stack[]; +void _start(void); + +__attribute__ ((section(".init"))) +const void * const stm_interrupt_vector[] = { + [0] = __stack, + [1] = _start, i(0x08, nmi), i(0x0c, hardfault), i(0x2c, svc), @@ -193,3 +159,33 @@ const void *stm_interrupt_vector[] = { i(0xb8, cec_can), i(0xbc, usb), }; + +void _init(void); + +#if RELOCATE_INTERRUPT +extern char __interrupt_start[]; +#endif + +void _init(void) +{ +#if AO_BOOT_CHAIN + if (ao_boot_check_chain()) { +#if AO_BOOT_PIN + ao_boot_check_pin(); +#endif + } +#endif + /* Turn on syscfg */ + stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_SYSCFGCOMPEN); + +#if RELOCATE_INTERRUPT + /* This will erase the boot chain data */ + memcpy(&__interrupt_start, stm_interrupt_vector, sizeof (stm_interrupt_vector)); + stm_syscfg.cfgr1 = (stm_syscfg.cfgr1 & ~(STM_SYSCFG_CFGR1_MEM_MODE_MASK << STM_SYSCFG_CFGR1_MEM_MODE)) | + (STM_SYSCFG_CFGR1_MEM_MODE_SRAM << STM_SYSCFG_CFGR1_MEM_MODE); +#else + /* Switch to Main Flash mode (DFU loader leaves us in System mode) */ + stm_syscfg.cfgr1 = (stm_syscfg.cfgr1 & ~(STM_SYSCFG_CFGR1_MEM_MODE_MASK << STM_SYSCFG_CFGR1_MEM_MODE)) | + (STM_SYSCFG_CFGR1_MEM_MODE_MAIN_FLASH << STM_SYSCFG_CFGR1_MEM_MODE); +#endif +} diff --git a/src/stmf0/ao_storage_stm.c b/src/stmf0/ao_storage_stm.c index c6f1defe..0819350e 100644 --- a/src/stmf0/ao_storage_stm.c +++ b/src/stmf0/ao_storage_stm.c @@ -70,7 +70,7 @@ stm_flash_page_size(void) #define ao_flash_wait_bsy() do { while (stm_flash.sr & (1 << STM_FLASH_SR_BSY)); } while (0) -static void __attribute__ ((section(".ramtext"),noinline)) +static void __attribute__ ((section(".srodata"),noinline)) _ao_flash_erase_page(uint16_t *page) { stm_flash.cr |= (1 << STM_FLASH_CR_PER); @@ -86,7 +86,7 @@ _ao_flash_erase_page(uint16_t *page) #define _ao_flash_addr(pos) ((uint16_t *) (void *) ((uint8_t *) __flash__ + (pos))) -static void __attribute ((section(".ramtext"), noinline)) _ao_flash_byte(uint32_t pos, uint8_t b) +static void __attribute ((section(".srodata"), noinline)) _ao_flash_byte(uint32_t pos, uint8_t b) { uint16_t v; uint16_t *a = _ao_flash_addr(pos & ~1); @@ -99,7 +99,7 @@ static void __attribute ((section(".ramtext"), noinline)) _ao_flash_byte(uint32_ ao_flash_wait_bsy(); } -static void __attribute__ ((section(".ramtext"), noinline)) +static void __attribute__ ((section(".srodata"), noinline)) _ao_flash_write(uint32_t pos, void *sv, uint16_t len) { uint8_t *s = sv; diff --git a/src/telegps-v1.0/Makefile b/src/telegps-v1.0/Makefile index fc1b1f28..aa644298 100644 --- a/src/telegps-v1.0/Makefile +++ b/src/telegps-v1.0/Makefile @@ -71,7 +71,7 @@ OBJ=$(SRC:.c=.o) all: $(PROG) $(HEX) $(PROG): Makefile $(OBJ) altos.ld - $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) + $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) -Wl,-Map=$(PROGNAME)-$(VERSION).map $(OBJ): $(INC) diff --git a/src/telegps-v2.0/Makefile b/src/telegps-v2.0/Makefile index 7ce28471..24410e0d 100644 --- a/src/telegps-v2.0/Makefile +++ b/src/telegps-v2.0/Makefile @@ -73,7 +73,7 @@ OBJ=$(SRC:.c=.o) all: $(PROG) $(HEX) $(PROG): Makefile $(OBJ) altos.ld - $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) + $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) -Wl,-Map=$(PROGNAME)-$(VERSION).map $(OBJ): $(INC) diff --git a/src/telemetrum-v2.0/Makefile b/src/telemetrum-v2.0/Makefile index c1e220e3..9b66c518 100644 --- a/src/telemetrum-v2.0/Makefile +++ b/src/telemetrum-v2.0/Makefile @@ -105,7 +105,7 @@ OBJ=$(SRC:.c=.o) all: $(PROG) $(HEX) $(PROG): Makefile $(OBJ) altos.ld - $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) + $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) -Wl,-Map=$(PROGNAME)-$(VERSION).map $(OBJ): $(INC)