altos: Move from newlib-nano to picolibc
authorKeith Packard <keithp@keithp.com>
Mon, 16 Sep 2019 00:05:17 +0000 (17:05 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 22 May 2020 05:04:46 +0000 (22:04 -0700)
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 <keithp@keithp.com>
36 files changed:
src/Makefile.defs
src/kernel/ao_product.c
src/lpc/Makefile-flash.defs
src/lpc/Makefile-lpc.defs
src/lpc/Makefile.defs
src/lpc/altos-loader.ld
src/lpc/altos.ld
src/lpc/ao_arch.h
src/lpc/ao_boot_chain.c
src/lpc/ao_interrupt.c
src/micropeak-v2.0/Makefile
src/micropeak-v2.0/micropeak.ld
src/pnpservo-v1/lambda.ld
src/stm/Makefile-flash.defs
src/stm/Makefile-stm.defs
src/stm/Makefile.defs
src/stm/altos-loader.ld
src/stm/altos.ld
src/stm/ao_arch.h
src/stm/ao_boot_chain.c
src/stm/ao_flash_stm.c
src/stm/ao_interrupt.c
src/stm32f4/altos-loader.ld
src/stmf0/Makefile-flash.defs
src/stmf0/Makefile-stmf0.defs
src/stmf0/Makefile.defs
src/stmf0/altos-loader.ld
src/stmf0/altos.ld
src/stmf0/ao_arch.h
src/stmf0/ao_boot_chain.c
src/stmf0/ao_flash_stm.c
src/stmf0/ao_interrupt.c
src/stmf0/ao_storage_stm.c
src/telegps-v1.0/Makefile
src/telegps-v2.0/Makefile
src/telemetrum-v2.0/Makefile

index d6244feedd159a74d0aed70d4076502a1cb59338..a14b8042f9516708113b25a12bbf446d13185f09 100644 (file)
@@ -20,12 +20,11 @@ WARN_FLAGS=-Wall -Wextra -Werror -Wcast-align \
 
 OPT=-Os -Wl,-Map=$(PROGNAME)-$(VERSION).map
 
-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 \
index 7248865427b725a60d6544f3e4fbec90bca59511..eaa6c78b8626d3b0070d0d8e811ca9d70aa59352 100644 (file)
@@ -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,
index 44b43bfe94d5f627f6f5bfc3b9f26d7a702eab22..1ae94c1548bef0c9261a25dde823fce1bb18ca6f 100644 (file)
@@ -35,7 +35,7 @@ IDPRODUCT=0x000a
 
 CFLAGS = $(PRODUCT_DEF) $(LPC_CFLAGS)
 
-LDFLAGS=$(CFLAGS) -L$(TOPDIR)/lpc -Wl,-Taltos-loader.ld
+LDFLAGS=-nostartfiles $(CFLAGS) -L$(TOPDIR)/lpc -Taltos-loader.ld
 
 PROGNAME=altos-flash
 PROG=$(HARDWARE)-$(PROGNAME)-$(VERSION).elf
index 8b2973512ba9d58b2e045631bfb22d90b91c9070..fb3747dd5941e91196596c020a54962b57805aef 100644 (file)
@@ -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)
index 7fdcf0dc4770a0050e6fbd6c35eb65967a7d7f5a..7ea76e1c85b3bb838bddc2fcc402d61676f239fb 100644 (file)
@@ -4,7 +4,7 @@ endif
 
 include $(TOPDIR)/lpc/Makefile-lpc.defs
 
-LDFLAGS=$(CFLAGS) -L$(TOPDIR)/lpc -Wl,-Taltos.ld -n
+LDFLAGS=-nostartfiles $(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` > $@
index be4f115d50e76b666307c7efa15baf139138f7c3..75b527fb24bf9fc79a3d9addc5f53d179e44ad66 100644 (file)
  * 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;
+__ram = 0x10000000;
+__ram_size = 4k;
+__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
index 028ad775d28ef579a3f44e99c9d25422f4874001..3e0157300fb2d4c86a0ac2d0631b7738d7318403 100644 (file)
  * 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;
+__ram = 0x10000000;
+__ram_size = 4k;
+__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
index 93676b860ff6c9edfb79804805307f288fd67c75..c638aa22b9658846a0a4319daec94b377706b6d4 100644 (file)
@@ -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")
index 0d0bb91c75f3c5f05bff78cc4025780ebca4c054..0cb92a5299565d90026cdde42688a921af192e6d 100644 (file)
@@ -43,7 +43,7 @@ struct ao_boot {
        uint32_t        check;
 };
 
-static struct ao_boot __attribute__ ((section(".boot"))) ao_boot;
+struct ao_boot ao_boot __attribute__((section(".preserve.2")));
 
 int
 ao_boot_check_chain(void)
index a479ec6d59585835c508e6e2cff7ce8db47e0c13..bc2848c3bffa364ba6298d3a32c9439a817dc57c 100644 (file)
 #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,26 +40,6 @@ void lpc_ignore_isr(void)
 {
 }
 
-void start(void) {
-#ifdef AO_BOOT_CHAIN
-       if (ao_boot_check_chain()) {
-#ifdef AO_BOOT_PIN
-               if (ao_boot_check_pin())
-#endif
-               {
-                       ao_boot_chain(AO_BOOT_APPLICATION_BASE);
-               }
-       }
-#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) \
@@ -122,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[];
+void _start(void) __attribute__((__noreturn__));
+
+__attribute__ ((section(".init")))
+const void *const __interrupt_vector[0x30] = {
+       [0] = __stack,
+       [1] = _start,
        i(0x08, nmi),
        i(0x0c, hardfault),
        c(0x10, 0),
@@ -178,3 +152,43 @@ const void *lpc_interrupt_vector[] = {
        i(0xb8, usb_wakeup),
        i(0xbc, hardfault),
 };
+
+/*
+ * Previous versions of this code had a 256 byte interupt vector. Add
+ * some padding to make sure the other low ROM variables land at the
+ * same address
+ */
+
+__attribute__ ((section(".init.0")))
+const void *const __interrupt_pad[0x10];
+
+void main(void) __attribute__((__noreturn__));
+
+void *__interrupt_ram[sizeof(__interrupt_vector)/sizeof(__interrupt_vector[0])] __attribute((section(".preserve.1")));
+
+extern char __data_source[];
+extern char __data_start[];
+extern char __data_size[];
+extern char __bss_start[];
+extern char __bss_size[];
+
+void _start(void) {
+       memcpy(__data_start, __data_source, (uintptr_t) __data_size);
+       memset(__bss_start, '\0', (uintptr_t) __bss_size);
+
+#ifdef AO_BOOT_CHAIN
+       if (ao_boot_check_chain()) {
+#ifdef AO_BOOT_PIN
+               if (ao_boot_check_pin())
+#endif
+               {
+                       ao_boot_chain(AO_BOOT_APPLICATION_BASE);
+               }
+       }
+#endif
+#if RELOCATE_INTERRUPT
+       memcpy(__interrupt_ram, __interrupt_vector, sizeof(__interrupt_ram));
+       lpc_scb.sysmemremap = LPC_SCB_SYSMEMREMAP_MAP_RAM << LPC_SCB_SYSMEMREMAP_MAP;
+#endif
+       main();
+}
index f1f57440a89c30f8ad42409c1fdaaac04fa1b096..5949ec0963f63324a5c87f6d97bd3c931ff874e6 100644 (file)
@@ -71,10 +71,10 @@ OBJ=$(SRC:.c=.o)
 
 all: $(PROG) $(HEX)
 
-LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Wl,-Tmicropeak.ld -n
+LDFLAGS=-nostartfiles $(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
 
index a73d4c1d3dbff1b1607550e964c985908583fa0c..b4e06a877708bd7cbdbe446b4262a5b1d5265856 100644 (file)
  * 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;
+__ram = 0x20000000;
+__ram_size = 6K;
+__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
index d3edbe9fb2168ed9eefd93ace5795bdd439382b6..20b3ace79be0df292ec4e771f6bc39abab6b9443 100644 (file)
@@ -87,7 +87,7 @@ SECTIONS {
        .textram BLOCK(8): {
                _start__ = .;
                __text_ram_start__ = .;
-               *(.ramtext)
+               *(.srodata)
                __text_ram_end = .;
        } >ram AT>rom
 
index 08a4b1773e00be742ac16856a883402d7e4f16b3..4a3864318eb342c85d849fd17dd9b991f385f15e 100644 (file)
@@ -35,13 +35,13 @@ IDPRODUCT=0x000a
 
 CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS)
 
-LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stm -Wl,-Taltos-loader.ld -n
+LDFLAGS=-nostartfiles $(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)
 
index cce28f009f86f648d907489ff483e3ffe522206a..f3fd9de65ee1f8916b56e3b346bd48540b6aef0a 100644 (file)
@@ -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)
index 26ba582404fa4cd99b74701e71487970f99788ea..d6cbe4d4921a3be1d6257146860a16e63206e3be 100644 (file)
@@ -4,4 +4,4 @@ endif
 
 include $(TOPDIR)/stm/Makefile-stm.defs
 
-LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stm -Wl,-Taltos.ld -n
+LDFLAGS=-nostartfiles $(CFLAGS) -L$(TOPDIR)/stm -Taltos.ld -n
index 1ebbc7a2afcb15b30d2c24fe692547edec4e1073..5ef09cd237140791cb9407a3db9d3190956781cc 100644 (file)
  * 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;
+__ram =   0x20000000;
+__ram_size = 16K;
+__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
index e352ed36601d85409801dc8c605a8a49a07536e7..9638bb6724cd5f00ee62ab79a65ab38008119026 100644 (file)
  * 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;
+__ram = 0x20000000;
+__ram_size = 16k;
+__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
index e83b6bd2cfbf3e1dac4a7c2816703fcf1214ba08..e3094c6abec04fdcc4a700d5d216639995beb7b2 100644 (file)
@@ -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
index 488af1e1b8dffc2261e303aa3b3981b3a69f29f7..d91afdabc7fcbfb949ac007d72d0b8e330339fdf 100644 (file)
@@ -43,8 +43,8 @@ struct ao_boot {
        uint32_t        check;
 };
 
-static struct ao_boot __attribute__ ((section(".boot"))) ao_boot;
-       
+struct ao_boot ao_boot __attribute__((section(".preserve.2")));
+
 int
 ao_boot_check_chain(void)
 {
index 38618bbe53165f64138c0a3a39fa81c2740cbf20..77296c322d2f11906c2f02ae966da7e153b0a54c 100644 (file)
@@ -70,7 +70,7 @@ ao_flash_wait_bsy(void)
                ;
 }
 
-static void __attribute__ ((section(".ramtext"),noinline))
+static void __attribute__ ((section(".sdata2.flash"), 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(".sdata2.flash"), noinline))
 _ao_flash_half_page(uint32_t *dst, uint32_t *src)
 {
        uint8_t         i;
index 1d563532b755cf7f1144400803ef0a034536febb..c62870b745ffebfb616f9e0498d61e7c919ff81c 100644 (file)
 #include <ao_boot.h>
 
 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 __interrupt_vector[];
 
 uint32_t
 stm_flash_size(void) {
@@ -72,25 +68,6 @@ stm_flash_size(void) {
        return (uint32_t) kbytes * 1024;
 }
 
-void start(void)
-{
-#ifdef AO_BOOT_CHAIN
-       if (ao_boot_check_chain()) {
-#ifdef AO_BOOT_PIN
-               if (ao_boot_check_pin())
-#endif
-               {
-                       ao_boot_chain(AO_BOOT_APPLICATION_BASE);
-               }
-       }
-#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
 
 #define isr(name) \
@@ -158,10 +135,18 @@ isr(tim7)
 
 #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__((__noreturn__));
+void main(void) __attribute__((__noreturn__));
+
+/* This must be exactly 256 bytes long so that the configuration data
+ * gets loaded at the right place
+ */
+
+__attribute__ ((section(".init")))
+void * const __interrupt_vector[64] = {
+       [0] = &__stack,
+       [1] = _start,
        i(0x08, nmi),
        i(0x0c, hardfault),
        i(0x10, memmanage),
@@ -217,3 +202,28 @@ const void *stm_interrupt_vector[] = {
        i(0xec, tim6),
        i(0xf0, tim7),
 };
+
+extern char __data_source[];
+extern char __data_start[];
+extern char __data_size[];
+extern char __bss_start[];
+extern char __bss_size[];
+
+void _start(void) {
+       memcpy(__data_start, __data_source, (uintptr_t) __data_size);
+       memset(__bss_start, '\0', (uintptr_t) __bss_size);
+
+#ifdef AO_BOOT_CHAIN
+       if (ao_boot_check_chain()) {
+#ifdef AO_BOOT_PIN
+               if (ao_boot_check_pin())
+#endif
+               {
+                       ao_boot_chain(AO_BOOT_APPLICATION_BASE);
+               }
+       }
+#endif
+       /* Set interrupt vector table offset */
+       stm_nvic.vto = (uint32_t) &__interrupt_vector;
+       main();
+}
index 5d6e1f4b14006ff037e2c988f564681c05cf4ab1..9a46987fa33969bb1b2ab3cc7bac742e02581da2 100644 (file)
@@ -68,7 +68,7 @@ SECTIONS {
        .textram BLOCK(8): {
                _start__ = .;
                __text_ram_start__ = .;
-               *(.ramtext)
+               *(.srodata)
                __text_ram_end = .;
        } >ram AT>rom
 
index b6e44990b5a0f1fbd88ff98934d10855a48cb39b..bbb04e77c1292669b8210b6297b903321dcf6998 100644 (file)
@@ -35,7 +35,7 @@ IDPRODUCT=0x000a
 
 CFLAGS = $(PRODUCT_DEF) $(STMF0_CFLAGS)
 
-LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Wl,-Taltos-loader.ld
+LDFLAGS=-nostartfiles $(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)
index 5a883adf1345bdd72593ca23f50321ba5068f4b8..f3add106902fc6dca051d79da3663c30f149f7cd 100644 (file)
@@ -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
index 2baba4f2b3536360cb03933929fd825c62c9d425..fb62f095e6e63d99eaba4c37296dc79ef12363b9 100644 (file)
@@ -4,7 +4,7 @@ endif
 
 include $(TOPDIR)/stmf0/Makefile-stmf0.defs
 
-LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Wl,-Taltos.ld -n
+LDFLAGS=-nostartfiles $(CFLAGS) -L$(TOPDIR)/stmf0 -Taltos.ld -n
 
 LOADER=flash-loader/$(PROGNAME)-altos-flash-$(VERSION).elf
 MAKEBIN=$(TOPDIR)/../ao-tools/ao-makebin/ao-makebin
index 4d9b81ae0ad16d0121b8d79ee75638c994b6b618..4ce0b7043e1d34304917c7a5cc4433cbedeb7b85 100644 (file)
  * 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;
+__ram = 0x20000000;
+__ram_size = 6k;
+__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
index 64e1d00cf0ab5b1aadebebdd389914a1d8d63c5e..019565cf9f82016b4ec0c7991b712bf32f38557a 100644 (file)
  * 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;
+__ram = 0x20000000;
+__ram_size = 6k;
+__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
index d70a9110e91fa02ac481ced1e928fa1868b0ca6d..47ac72787aa1801bbd3f56dc891efa0c8402ce44 100644 (file)
@@ -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;
index 8f850a0a6d98d7ee1b0484f746dd8f6453e19d43..d91afdabc7fcbfb949ac007d72d0b8e330339fdf 100644 (file)
@@ -43,7 +43,7 @@ struct ao_boot {
        uint32_t        check;
 };
 
-static struct ao_boot __attribute__ ((section(".boot"))) ao_boot;
+struct ao_boot ao_boot __attribute__((section(".preserve.2")));
 
 int
 ao_boot_check_chain(void)
index 2d57eea72701eefeae6e61ad0a6fc0395cf2dac7..896d536ba0c1612e7fe341b4a4da0d399aa445ba 100644 (file)
@@ -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(".sdata2.flash"), 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(".sdata2.flash"), noinline))
 _ao_flash_page(uint16_t *dst, uint16_t *src)
 {
        uint8_t         i;
index 1ee6e720091be2e277fca3b26536fd559caea35d..3d7dc7a82c653e2eff6be3327b4edd252ae6ad88 100644 (file)
 #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,35 +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
-               if (ao_boot_check_pin())
-#endif
-               {
-                       ao_boot_chain(AO_BOOT_APPLICATION_BASE);
-               }
-       }
-#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) \
@@ -153,10 +113,14 @@ 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__((__noreturn__));
+void main(void) __attribute__((__noreturn__));
+
+__attribute__ ((section(".init")))
+const void * const __interrupt_vector[0x30] = {
+       [0] = __stack,
+       [1] = _start,
        i(0x08, nmi),
        i(0x0c, hardfault),
        i(0x2c, svc),
@@ -196,3 +160,47 @@ const void *stm_interrupt_vector[] = {
        i(0xb8, cec_can),
        i(0xbc, usb),
 };
+
+/*
+ * Previous versions of this code had a 256 byte interupt vector. Add
+ * some padding to make sure the other low ROM variables land at the
+ * same address
+ */
+
+__attribute__ ((section(".init.0")))
+const void *const __interrupt_pad[0x10];
+
+void *__interrupt_ram[sizeof(__interrupt_vector)/sizeof(__interrupt_vector[0])] __attribute__((section(".preserve.1")));
+
+extern char __data_source[];
+extern char __data_start[];
+extern char __data_size[];
+extern char __bss_start[];
+extern char __bss_size[];
+
+void _start(void)
+{
+       memcpy(__data_start, __data_source, (uintptr_t) __data_size);
+       memset(__bss_start, '\0', (uintptr_t) __bss_size);
+
+#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_ram, __interrupt_vector, sizeof(__interrupt_ram));
+       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
+       main();
+}
index c6f1defe8e67b3f8efe97a3424804e9eac470126..111db04a12a4cf21893c99d2adae5af252831877 100644 (file)
@@ -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(".sdata2.flash"), noinline))
 _ao_flash_erase_page(uint16_t *page)
 {
        stm_flash.cr |= (1 << STM_FLASH_CR_PER);
@@ -86,7 +86,8 @@ _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(".sdata2.flash"), noinline))
+_ao_flash_byte(uint32_t pos, uint8_t b)
 {
        uint16_t        v;
        uint16_t        *a = _ao_flash_addr(pos & ~1);
@@ -99,7 +100,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(".sdata2.flash"), noinline))
 _ao_flash_write(uint32_t pos, void *sv, uint16_t len)
 {
        uint8_t         *s = sv;
index fc1b1f28c8de9396a72e1fd38ea69bd9bb95b23b..aa644298a2f11cca28c35d339e9492b87ce64c3a 100644 (file)
@@ -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)
 
index 7ce2847154b4483e433f4c26504af8dcad00af3d..24410e0d375403c771b8b43c321b61404d133494 100644 (file)
@@ -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)
 
index c1e220e3df54ca7a10edab50cc5c25a5c794c974..9b66c5180407eb08a921d4a4f06b5d8750222699 100644 (file)
@@ -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)