Skip to content

Commit 94e1ac0

Browse files
committed
Add files syscall.c and sysmem.c
This files solve building warnings for newer compilers, for example, arm-none-eabi-gcc v13.3.1 or newer Warnings: warning: _close is not implemented and will always fail warning: _lseek is not implemented and will always fail warning: _read is not implemented and will always fail warning: _write is not implemented and will always fail
1 parent 41b98cb commit 94e1ac0

File tree

3 files changed

+251
-0
lines changed

3 files changed

+251
-0
lines changed

Bootloader/STM32/Src/syscalls.c

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/**
2+
******************************************************************************
3+
* @file syscalls.c
4+
* @author Auto-generated by STM32CubeMX
5+
* @brief Minimal System calls file
6+
*
7+
* For more information about which c-functions
8+
* need which of these lowlevel functions
9+
* please consult the Newlib libc-manual
10+
******************************************************************************
11+
* @attention
12+
*
13+
* Copyright (c) 2020-2024 STMicroelectronics.
14+
* All rights reserved.
15+
*
16+
* This software is licensed under terms that can be found in the LICENSE file
17+
* in the root directory of this software component.
18+
* If no LICENSE file comes with this software, it is provided AS-IS.
19+
*
20+
******************************************************************************
21+
*/
22+
23+
/* Includes */
24+
#include <sys/stat.h>
25+
#include <stdlib.h>
26+
#include <errno.h>
27+
#include <stdio.h>
28+
#include <signal.h>
29+
#include <time.h>
30+
#include <sys/time.h>
31+
#include <sys/times.h>
32+
33+
34+
/* Variables */
35+
extern int __io_putchar(int ch) __attribute__((weak));
36+
extern int __io_getchar(void) __attribute__((weak));
37+
38+
39+
char* __env[1] = { 0 };
40+
char** environ = __env;
41+
42+
43+
/* Functions */
44+
void
45+
initialise_monitor_handles() {
46+
}
47+
48+
int
49+
_getpid(void) {
50+
return 1;
51+
}
52+
53+
int
54+
_kill(int pid, int sig) {
55+
(void)pid;
56+
(void)sig;
57+
errno = EINVAL;
58+
return -1;
59+
}
60+
61+
void
62+
_exit (int status) {
63+
_kill(status, -1);
64+
while (1) {} /* Make sure we hang here */
65+
}
66+
67+
__attribute__((weak)) int _read(int file, char* ptr, int len) {
68+
(void)file;
69+
int DataIdx;
70+
71+
for (DataIdx = 0; DataIdx < len; DataIdx++) {
72+
*ptr++ = __io_getchar();
73+
}
74+
75+
return len;
76+
}
77+
78+
__attribute__((weak)) int _write(int file, char* ptr, int len) {
79+
(void)file;
80+
int DataIdx;
81+
82+
for (DataIdx = 0; DataIdx < len; DataIdx++) {
83+
__io_putchar(*ptr++);
84+
}
85+
return len;
86+
}
87+
88+
int
89+
_close(int file) {
90+
(void)file;
91+
return -1;
92+
}
93+
94+
95+
int
96+
_fstat(int file, struct stat* st) {
97+
(void)file;
98+
st->st_mode = S_IFCHR;
99+
return 0;
100+
}
101+
102+
int
103+
_isatty(int file) {
104+
(void)file;
105+
return 1;
106+
}
107+
108+
int
109+
_lseek(int file, int ptr, int dir) {
110+
(void)file;
111+
(void)ptr;
112+
(void)dir;
113+
return 0;
114+
}
115+
116+
int
117+
_open(char* path, int flags, ...) {
118+
(void)path;
119+
(void)flags;
120+
/* Pretend like we always fail */
121+
return -1;
122+
}
123+
124+
int
125+
_wait(int* status) {
126+
(void)status;
127+
errno = ECHILD;
128+
return -1;
129+
}
130+
131+
int
132+
_unlink(char* name) {
133+
(void)name;
134+
errno = ENOENT;
135+
return -1;
136+
}
137+
138+
int
139+
_times(struct tms* buf) {
140+
(void)buf;
141+
return -1;
142+
}
143+
144+
int
145+
_stat(char* file, struct stat* st) {
146+
(void)file;
147+
st->st_mode = S_IFCHR;
148+
return 0;
149+
}
150+
151+
int
152+
_link(char* old, char* new) {
153+
(void)old;
154+
(void)new;
155+
errno = EMLINK;
156+
return -1;
157+
}
158+
159+
int
160+
_fork(void) {
161+
errno = EAGAIN;
162+
return -1;
163+
}
164+
165+
int
166+
_execve(char* name, char** argv, char** env) {
167+
(void)name;
168+
(void)argv;
169+
(void)env;
170+
errno = ENOMEM;
171+
return -1;
172+
}

Bootloader/STM32/Src/sysmem.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
******************************************************************************
3+
* @file sysmem.c
4+
* @author Generated by STM32CubeMX
5+
* @brief System Memory calls file
6+
*
7+
* For more information about which C functions
8+
* need which of these lowlevel functions
9+
* please consult the newlib libc manual
10+
******************************************************************************
11+
* @attention
12+
*
13+
* Copyright (c) 2024 STMicroelectronics.
14+
* All rights reserved.
15+
*
16+
* This software is licensed under terms that can be found in the LICENSE file
17+
* in the root directory of this software component.
18+
* If no LICENSE file comes with this software, it is provided AS-IS.
19+
*
20+
******************************************************************************
21+
*/
22+
23+
/* Includes */
24+
#include <errno.h>
25+
#include <stdint.h>
26+
27+
/**
28+
* Pointer to the current high watermark of the heap usage
29+
*/
30+
static uint8_t* __sbrk_heap_end = NULL;
31+
32+
/**
33+
* @brief _sbrk() allocates memory to the newlib heap and is used by malloc
34+
* and others from the C library
35+
*
36+
* @verbatim
37+
* ############################################################################
38+
* # .data # .bss # newlib heap # MSP stack #
39+
* # # # # Reserved by _Min_Stack_Size #
40+
* ############################################################################
41+
* ^-- RAM start ^-- _end _estack, RAM end --^
42+
* @endverbatim
43+
*
44+
* This implementation starts allocating at the '_end' linker symbol
45+
* The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
46+
* The implementation considers '_estack' linker symbol to be RAM end
47+
* NOTE: If the MSP stack, at any point during execution, grows larger than the
48+
* reserved size, please increase the '_Min_Stack_Size'.
49+
*
50+
* @param incr Memory size
51+
* @return Pointer to allocated memory
52+
*/
53+
void*
54+
_sbrk(ptrdiff_t incr) {
55+
extern uint8_t _end; /* Symbol defined in the linker script */
56+
extern uint8_t _estack; /* Symbol defined in the linker script */
57+
extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
58+
const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
59+
const uint8_t* max_heap = (uint8_t*)stack_limit;
60+
uint8_t* prev_heap_end;
61+
62+
/* Initialize heap end at first call */
63+
if (NULL == __sbrk_heap_end) {
64+
__sbrk_heap_end = &_end;
65+
}
66+
67+
/* Protect heap from growing into the reserved MSP stack */
68+
if (__sbrk_heap_end + incr > max_heap) {
69+
errno = ENOMEM;
70+
return (void*) -1;
71+
}
72+
73+
prev_heap_end = __sbrk_heap_end;
74+
__sbrk_heap_end += incr;
75+
76+
return (void*)prev_heap_end;
77+
}

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Bootloader/Adapters/Src/security_adapter.c \
3636
Bootloader/Adapters/Src/system_adapter.c \
3737
Bootloader/Adapters/Src/system_clock_adapter.c \
3838
Bootloader/Library/Src/software_info.c \
39+
Bootloader/STM32/Src/syscalls.c \
40+
Bootloader/STM32/Src/sysmem.c \
3941
Bootloader/Utility/Src/base64.c \
4042
Bootloader/Utility/Src/crc/crc32_base.c \
4143
Bootloader/Utility/Src/crc/crc32_variants/crc32_bzip2.c \

0 commit comments

Comments
 (0)