Skip to content

Commit 68b1dae

Browse files
iabdalkaderdpgeorge
authored andcommitted
alif: Link with libnosys.
This allows the correct start up functions to be called by the stdlib. Signed-off-by: iabdalkader <[email protected]>
1 parent 182b5f3 commit 68b1dae

File tree

3 files changed

+58
-12
lines changed

3 files changed

+58
-12
lines changed

ports/alif/alif.mk

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ CFLAGS += $(INC) \
6868
-mtune=cortex-m55 \
6969
$(CFLAGS_FPU) \
7070
-march=armv8.1-m.main+fp+mve.fp \
71-
-nostdlib \
7271
-fdata-sections \
7372
-ffunction-sections \
73+
--specs=nosys.specs \
7474
-D$(MCU_CORE)=1 \
7575
-DCORE_$(MCU_CORE) \
7676
-DALIF_CMSIS_H="\"$(MCU_CORE).h\""
@@ -95,18 +95,17 @@ CFLAGS += $(CFLAGS_EXTRA)
9595

9696
AFLAGS = -mthumb -march=armv8.1-m.main+fp+mve.fp $(CFLAGS_FPU)
9797

98-
LDFLAGS += -nostdlib \
99-
-T$(BUILD)/ensemble.ld \
100-
-Map=$@.map \
101-
--cref \
102-
--gc-sections \
103-
--print-memory-usage
98+
CFLAGS += -Wl,-T$(BUILD)/ensemble.ld \
99+
-Wl,-Map=$@.map \
100+
-Wl,--cref \
101+
-Wl,--gc-sections \
102+
-Wl,--print-memory-usage \
103+
-Wl,--no-warn-rwx-segment
104+
104105
ifeq ($(MCU_CORE),M55_HP)
105-
LDFLAGS += --wrap=dcd_event_handler
106+
CFLAGS += -Wl,--wrap=dcd_event_handler
106107
endif
107108

108-
LIBS += "$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)"
109-
110109
################################################################################
111110
# Source files and libraries
112111

@@ -126,6 +125,7 @@ SRC_C = \
126125
mpu.c \
127126
mpuart.c \
128127
msc_disk.c \
128+
nosys_stubs.c \
129129
ospi_ext.c \
130130
ospi_flash.c \
131131
pendsv.c \
@@ -256,7 +256,7 @@ $(BUILD)/ensemble.ld: $(LD_FILE)
256256

257257
$(BUILD)/firmware.elf: $(OBJ) $(BUILD)/ensemble.ld
258258
$(ECHO) "Link $@"
259-
$(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
259+
$(Q)$(CC) $(CFLAGS) -o $@ $(OBJ) $(LIBS)
260260
$(Q)$(SIZE) $@
261261

262262
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf

ports/alif/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ NORETURN void panic(const char *msg) {
5555
}
5656
}
5757

58-
void _start(void) {
58+
int main(void) {
5959
system_tick_init();
6060

6161
MICROPY_BOARD_STARTUP();

ports/alif/nosys_stubs.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2024 OpenMV LLC.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#include <errno.h>
27+
28+
int _write(int handle, char *buffer, int size) {
29+
errno = ENOSYS;
30+
return -1;
31+
}
32+
33+
int _read(int handle, char *buffer, int size) {
34+
errno = ENOSYS;
35+
return -1;
36+
}
37+
38+
int _close(int f) {
39+
errno = ENOSYS;
40+
return -1;
41+
}
42+
43+
int _lseek(int f, int ptr, int dir) {
44+
errno = ENOSYS;
45+
return -1;
46+
}

0 commit comments

Comments
 (0)