Skip to content

Commit 2108da1

Browse files
committed
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 <[email protected]>
1 parent 74d5dfd commit 2108da1

36 files changed

+229
-697
lines changed

src/Makefile.defs

+4-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ WARN_FLAGS=-Wall -Wextra -Werror -Wcast-align \
2020

2121
OPT=-Os -Wl,-Map=$(PROGNAME)-$(VERSION).map
2222

23-
NEWLIB_PRINTF_CFLAGS = -DNEWLIB_INTEGER_PRINTF_SCANF
23+
PICOLIBC_PRINTF_CFLAGS = -DPICOLIBC_INTEGER_PRINTF_SCANF
2424

25-
NEWLIB_CFLAGS= \
26-
-ffreestanding -nostdlib \
27-
-isystem $(NEWLIB_NANO)/arm-none-eabi/include \
28-
$(NEWLIB_PRINTF_CFLAGS)
25+
PICOLIBC_CFLAGS= \
26+
-specs=picolibc.specs \
27+
$(PICOLIBC_PRINTF_CFLAGS)
2928

3029
AO_CFLAGS=\
3130
-std=gnu99 \

src/kernel/ao_product.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ const char ao_product[] = AO_iProduct_STRING;
6060
#define TOTAL_LENGTH (HEADER_LEN + AO_USB_HAS_INT * CONTROL_CLASS_LEN + DATA_LEN)
6161
#define NUM_INTERFACES (AO_USB_HAS_INT + 1)
6262

63+
#ifndef AO_USBCONFIG_SYMBOL
64+
#define AO_USBCONFIG_SYMBOL AO_ROMCONFIG_SYMBOL
65+
#endif
66+
6367
/* USB descriptors in one giant block of bytes */
64-
AO_ROMCONFIG_SYMBOL uint8_t ao_usb_descriptors [] =
68+
AO_USBCONFIG_SYMBOL uint8_t ao_usb_descriptors [] =
6569
{
6670
/* Device descriptor */
6771
0x12,

src/lpc/Makefile-flash.defs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ IDPRODUCT=0x000a
3535

3636
CFLAGS = $(PRODUCT_DEF) $(LPC_CFLAGS)
3737

38-
LDFLAGS=$(CFLAGS) -L$(TOPDIR)/lpc -Wl,-Taltos-loader.ld
38+
LDFLAGS=-nostartfiles $(CFLAGS) -L$(TOPDIR)/lpc -Taltos-loader.ld
3939

4040
PROGNAME=altos-flash
4141
PROG=$(HARDWARE)-$(PROGNAME)-$(VERSION).elf

src/lpc/Makefile-lpc.defs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ vpath % $(TOPDIR)/lpc:$(AO_VPATH)
88

99
CC=$(ARM_CC)
1010

11-
LIBS=-L$(NEWLIB_NANO)/arm-none-eabi/lib/thumb/v6-m -lc -lm -lgcc
11+
LIBS=-lm
1212

1313
LPC_CFLAGS=-mlittle-endian -mcpu=cortex-m0 -mthumb\
14-
-I$(TOPDIR)/lpc $(AO_CFLAGS) $(NEWLIB_CFLAGS)
14+
-I$(TOPDIR)/lpc $(AO_CFLAGS) $(PICOLIBC_CFLAGS)

src/lpc/Makefile.defs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ endif
44

55
include $(TOPDIR)/lpc/Makefile-lpc.defs
66

7-
LDFLAGS=$(CFLAGS) -L$(TOPDIR)/lpc -Wl,-Taltos.ld -n
7+
LDFLAGS=-nostartfiles $(CFLAGS) -L$(TOPDIR)/lpc -Taltos.ld -n
88

99
ao_serial_lpc.h: $(TOPDIR)/lpc/baud_rate ao_pins.h
1010
nickle $(TOPDIR)/lpc/baud_rate `awk '/AO_LPC_CLKOUT/{print $$3}' ao_pins.h` > $@

src/lpc/altos-loader.ld

+6-61
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,11 @@
1616
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
1717
*/
1818

19-
MEMORY {
20-
rom : ORIGIN = 0x00000000, LENGTH = 4K
21-
ram : ORIGIN = 0x10000000, LENGTH = 4k - 128 - 32
22-
usb (!x) : ORIGIN = 0x20004000 + 2K - 256, LENGTH = 256
23-
stack (!w) : ORIGIN = 0x10000000 + 4K - 128 - 32, LENGTH = 128
24-
}
19+
__flash = 0x0;
20+
__flash_size = 4K;
21+
__ram = 0x10000000;
22+
__ram_size = 4k;
23+
__stack_size = 128;
2524

2625
INCLUDE registers.ld
27-
28-
EXTERN (lpc_interrupt_vector)
29-
30-
SECTIONS {
31-
/*
32-
* Rom contents
33-
*/
34-
35-
.interrupt : {
36-
__text_start__ = .;
37-
*(.interrupt) /* Interrupt vectors */
38-
39-
} > rom
40-
41-
.text ORIGIN(rom) + 0x100 : {
42-
ao_romconfig.o(.romconfig*)
43-
ao_product.o(.romconfig*)
44-
45-
*(.text*) /* Executable code */
46-
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
47-
*(.rodata*) /* Constants */
48-
__text_end__ = .;
49-
} > rom
50-
51-
/* Boot data which must live at the start of ram so that
52-
* the application and bootloader share the same addresses.
53-
* This must be all uninitialized data
54-
*/
55-
.boot ORIGIN(ram) + SIZEOF(.interrupt) (NOLOAD) : {
56-
__boot_start__ = .;
57-
*(.boot*)
58-
__boot_end__ = .;
59-
} >ram
60-
61-
/* Data -- relocated to RAM, but written to ROM
62-
*/
63-
.data : {
64-
_start__ = .;
65-
*(.data*) /* initialized data */
66-
_end__ = .;
67-
} >ram AT>rom
68-
69-
70-
.bss : {
71-
__bss_start__ = .;
72-
*(.bss*)
73-
*(COMMON*)
74-
__bss_end__ = .;
75-
} >ram
76-
77-
PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram));
78-
PROVIDE(end = .);
79-
}
80-
81-
ENTRY(start);
26+
INCLUDE picolibc.ld

src/lpc/altos.ld

+6-71
Original file line numberDiff line numberDiff line change
@@ -16,76 +16,11 @@
1616
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
1717
*/
1818

19-
MEMORY {
20-
rom (rx) : ORIGIN = 0x00001000, LENGTH = 28K
21-
ram (!w) : ORIGIN = 0x10000000, LENGTH = 4K - 128
22-
usb (!x) : ORIGIN = 0x20004000 + 2K - 256, LENGTH = 256
23-
stack (!w) : ORIGIN = 0x10000000 + 4K - 128, LENGTH = 128
24-
}
19+
__flash = 0x1000;
20+
__flash_size = 28K;
21+
__ram = 0x10000000;
22+
__ram_size = 4k;
23+
__stack_size = 128;
2524

2625
INCLUDE registers.ld
27-
28-
EXTERN (lpc_interrupt_vector)
29-
30-
SECTIONS {
31-
/*
32-
* Rom contents
33-
*/
34-
35-
.interrupt ORIGIN(ram) : AT (ORIGIN(rom)) {
36-
__interrupt_start__ = .;
37-
__interrupt_rom__ = ORIGIN(rom);
38-
*(.interrupt) /* Interrupt vectors */
39-
__interrupt_end__ = .;
40-
} > ram
41-
42-
.text ORIGIN(rom) + 0x100 : {
43-
__text_start__ = .;
44-
45-
ao_romconfig.o(.romconfig*)
46-
ao_product.o(.romconfig*)
47-
48-
*(.text*) /* Executable code */
49-
*(.rodata*) /* Constants */
50-
51-
} > rom
52-
53-
.ARM.exidx : {
54-
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
55-
__text_end__ = .;
56-
} > rom
57-
58-
/* Boot data which must live at the start of ram so that
59-
* the application and bootloader share the same addresses.
60-
* This must be all uninitialized data
61-
*/
62-
.boot : {
63-
__boot_start__ = .;
64-
*(.boot)
65-
. = ALIGN(4);
66-
__boot_end__ = .;
67-
} >ram
68-
69-
/* Data -- relocated to RAM, but written to ROM
70-
*/
71-
.data : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) {
72-
_start__ = .;
73-
*(.data) /* initialized data */
74-
_end__ = .;
75-
__bss_start__ = .;
76-
} >ram
77-
78-
.bss : {
79-
__bss_start__ = .;
80-
*(.bss)
81-
*(COMMON)
82-
__bss_end__ = .;
83-
} >ram
84-
PROVIDE(end = .);
85-
86-
PROVIDE(__stack__ = ORIGIN(stack) + LENGTH(stack));
87-
}
88-
89-
ENTRY(start);
90-
91-
26+
INCLUDE picolibc.ld

src/lpc/ao_arch.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
* ao_romconfig.c
5454
*/
5555

56-
#define AO_ROMCONFIG_SYMBOL __attribute__((section(".romconfig"))) const
56+
#define AO_ROMCONFIG_SYMBOL __attribute__((section(".init.1"))) const
57+
#define AO_USBCONFIG_SYMBOL __attribute__((section(".init.2"))) const
5758

5859
#define ao_arch_block_interrupts() asm("cpsid i")
5960
#define ao_arch_release_interrupts() asm("cpsie i")

src/lpc/ao_boot_chain.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct ao_boot {
4343
uint32_t check;
4444
};
4545

46-
static struct ao_boot __attribute__ ((section(".boot"))) ao_boot;
46+
struct ao_boot ao_boot __attribute__((section(".preserve.2")));
4747

4848
int
4949
ao_boot_check_chain(void)

src/lpc/ao_interrupt.c

+47-33
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@
2929
#define RELOCATE_INTERRUPT 1
3030
#endif
3131

32-
extern void main(void);
33-
extern char __stack__;
34-
extern char __text_start__, __text_end__;
35-
extern char _start__, _end__;
36-
extern char __bss_start__, __bss_end__;
37-
#if RELOCATE_INTERRUPT
38-
extern char __interrupt_rom__, __interrupt_start__, __interrupt_end__;
39-
#endif
40-
4132
/* Interrupt functions */
4233

4334
void lpc_halt_isr(void)
@@ -49,26 +40,6 @@ void lpc_ignore_isr(void)
4940
{
5041
}
5142

52-
void start(void) {
53-
#ifdef AO_BOOT_CHAIN
54-
if (ao_boot_check_chain()) {
55-
#ifdef AO_BOOT_PIN
56-
if (ao_boot_check_pin())
57-
#endif
58-
{
59-
ao_boot_chain(AO_BOOT_APPLICATION_BASE);
60-
}
61-
}
62-
#endif
63-
#if RELOCATE_INTERRUPT
64-
memcpy(&__interrupt_start__, &__interrupt_rom__, &__interrupt_end__ - &__interrupt_start__);
65-
lpc_scb.sysmemremap = LPC_SCB_SYSMEMREMAP_MAP_RAM << LPC_SCB_SYSMEMREMAP_MAP;
66-
#endif
67-
memcpy(&_start__, &__text_end__, &_end__ - &_start__);
68-
memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__);
69-
main();
70-
}
71-
7243
#define STRINGIFY(x) #x
7344

7445
#define isr(name) \
@@ -122,10 +93,13 @@ isr(usb_wakeup)
12293
#define i(addr,name) [(addr)/4] = lpc_ ## name ## _isr
12394
#define c(addr,value) [(addr)/4] = (value)
12495

125-
__attribute__ ((section(".interrupt")))
126-
const void *lpc_interrupt_vector[] = {
127-
[0] = &__stack__,
128-
[1] = start,
96+
extern char __stack[];
97+
void _start(void) __attribute__((__noreturn__));
98+
99+
__attribute__ ((section(".init")))
100+
const void *const __interrupt_vector[0x30] = {
101+
[0] = __stack,
102+
[1] = _start,
129103
i(0x08, nmi),
130104
i(0x0c, hardfault),
131105
c(0x10, 0),
@@ -178,3 +152,43 @@ const void *lpc_interrupt_vector[] = {
178152
i(0xb8, usb_wakeup),
179153
i(0xbc, hardfault),
180154
};
155+
156+
/*
157+
* Previous versions of this code had a 256 byte interupt vector. Add
158+
* some padding to make sure the other low ROM variables land at the
159+
* same address
160+
*/
161+
162+
__attribute__ ((section(".init.0")))
163+
const void *const __interrupt_pad[0x10];
164+
165+
void main(void) __attribute__((__noreturn__));
166+
167+
void *__interrupt_ram[sizeof(__interrupt_vector)/sizeof(__interrupt_vector[0])] __attribute((section(".preserve.1")));
168+
169+
extern char __data_source[];
170+
extern char __data_start[];
171+
extern char __data_size[];
172+
extern char __bss_start[];
173+
extern char __bss_size[];
174+
175+
void _start(void) {
176+
memcpy(__data_start, __data_source, (uintptr_t) __data_size);
177+
memset(__bss_start, '\0', (uintptr_t) __bss_size);
178+
179+
#ifdef AO_BOOT_CHAIN
180+
if (ao_boot_check_chain()) {
181+
#ifdef AO_BOOT_PIN
182+
if (ao_boot_check_pin())
183+
#endif
184+
{
185+
ao_boot_chain(AO_BOOT_APPLICATION_BASE);
186+
}
187+
}
188+
#endif
189+
#if RELOCATE_INTERRUPT
190+
memcpy(__interrupt_ram, __interrupt_vector, sizeof(__interrupt_ram));
191+
lpc_scb.sysmemremap = LPC_SCB_SYSMEMREMAP_MAP_RAM << LPC_SCB_SYSMEMREMAP_MAP;
192+
#endif
193+
main();
194+
}

src/micropeak-v2.0/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ OBJ=$(SRC:.c=.o)
7171

7272
all: $(PROG) $(HEX)
7373

74-
LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Wl,-Tmicropeak.ld -n
74+
LDFLAGS=-nostartfiles $(CFLAGS) -L$(TOPDIR)/stmf0 -Tmicropeak.ld -n
7575

7676
$(PROG): Makefile $(OBJ) micropeak.ld
77-
$(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS)
77+
$(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) -Wl,-Map=$(PROGNAME)-$(VERSION).map
7878

7979
distclean: clean
8080

0 commit comments

Comments
 (0)