Replace all binary SDK libc functions with newlib
Adds a new build step to remove the SDK object files listed in <libname>.remove. Closes #1.
This commit is contained in:
parent
f0b5bc324c
commit
aaef4b0644
13 changed files with 68 additions and 95 deletions
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* Wrappers for functions called by binary espressif libraries
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Copyright (C) 2015 Superhouse Automation Pty Ltd
|
||||
* BSD Licensed as described in the file LICENSE
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
void *zalloc(size_t nbytes) {
|
||||
return calloc(1, nbytes);
|
||||
}
|
47
common.mk
47
common.mk
|
@ -65,7 +65,7 @@ COMPONENTS ?= core FreeRTOS lwip axtls
|
|||
SDK_LIBS ?= main net80211 phy pp wpa
|
||||
|
||||
# open source libraries linked in
|
||||
LIBS ?= gcc hal
|
||||
LIBS ?= gcc hal cirom
|
||||
|
||||
# Note: this isn't overridable without a not-yet-merged patch to esptool
|
||||
ENTRY_SYMBOL = call_user_start
|
||||
|
@ -186,35 +186,50 @@ endef
|
|||
|
||||
## Linking rules for SDK libraries
|
||||
## SDK libraries are preprocessed to:
|
||||
# - remove object files named in <libname>.remove
|
||||
# - prefix all defined symbols with 'sdk_'
|
||||
# - weaken all global symbols so they can be overriden from the open SDK side
|
||||
|
||||
# SDK binary libraries are preprocessed into build/lib
|
||||
#
|
||||
# SDK binary libraries are preprocessed into build/sdklib
|
||||
SDK_PROCESSED_LIBS = $(addsuffix .a,$(addprefix $(BUILD_DIR)sdklib/lib,$(SDK_LIBS)))
|
||||
|
||||
# Make rule for preprocessing each SDK library
|
||||
#
|
||||
$(BUILD_DIR)sdklib/%.a: $(ROOT)lib/%.a $(BUILD_DIR)sdklib/allsymbols.rename
|
||||
$(vecho) "Pre-processing SDK library $< -> $@"
|
||||
$(Q) $(OBJCOPY) --redefine-syms $(word 2,$^) --weaken $< $@
|
||||
# Make rules for preprocessing each SDK library
|
||||
|
||||
# hacky, but prevents confusing error messages if one of these files disappears
|
||||
$(ROOT)lib/%.remove:
|
||||
touch $@
|
||||
|
||||
# Generate a regex to match symbols we don't want to rename, by parsing
|
||||
# a list of symbol names
|
||||
# Remove comment lines from <libname>.remove files
|
||||
$(BUILD_DIR)sdklib/%.remove: $(ROOT)lib/%.remove | $(BUILD_DIR)sdklib
|
||||
$(Q) grep -v "^#" $< | cat > $@
|
||||
|
||||
# Stage 1: remove unwanted object files listed in <libname>.remove alongside each library
|
||||
$(BUILD_DIR)sdklib/%_stage1.a: $(ROOT)lib/%.a $(BUILD_DIR)sdklib/%.remove | $(BUILD_DIR)sdklib
|
||||
@echo "SDK processing stage 1: Removing unwanted objects from $<"
|
||||
$(Q) cat $< > $@
|
||||
$(Q) $(AR) d $@ @$(word 2,$^)
|
||||
|
||||
# Generate a regex to match symbols we don't want to rename, listed in
|
||||
# symbols_norename.txt
|
||||
$(BUILD_DIR)sdklib/norename.match: $(ROOT)lib/symbols_norename.txt | $(BUILD_DIR)sdklib
|
||||
grep -v "^#" $< | sed ':begin;$!N;s/\n/\\|/;tbegin' > $@
|
||||
cat $< | grep -v "^#" | sed ':begin;$!N;s/\n/\\|/;tbegin' > $@
|
||||
|
||||
# Generate list of defined symbols to rename from a single library. Uses grep & sed.
|
||||
$(BUILD_DIR)sdklib/%.rename: $(ROOT)lib/%.a $(BUILD_DIR)sdklib/norename.match
|
||||
$(vecho) "Building symbol list for $< -> $@"
|
||||
# Stage 2: Build a list of defined symbols per library, renamed with sdk_ prefix
|
||||
$(BUILD_DIR)sdklib/%.rename: $(BUILD_DIR)sdklib/%_stage1.a $(BUILD_DIR)sdklib/norename.match
|
||||
@echo "SDK processing stage 2: Building symbol list for $< -> $@"
|
||||
$(Q) $(OBJDUMP) -t $< | grep ' g ' \
|
||||
| sed -r 's/^.+ ([^ ]+)$$/\1 sdk_\1/' \
|
||||
| grep -v `cat $(BUILD_DIR)sdklib/norename.match` > $@
|
||||
|
||||
# Build master list of all SDK-defined symbols to rename
|
||||
# Build a master list of all SDK-defined symbols to rename across all libraries
|
||||
$(BUILD_DIR)sdklib/allsymbols.rename: $(patsubst %.a,%.rename,$(SDK_PROCESSED_LIBS))
|
||||
cat $^ > $@
|
||||
|
||||
# Stage 3: Redefine all SDK symbols as sdk_, weaken all symbols.
|
||||
$(BUILD_DIR)sdklib/%.a: $(BUILD_DIR)sdklib/%_stage1.a $(BUILD_DIR)sdklib/allsymbols.rename
|
||||
@echo "SDK processing stage 3: Renaming symbols in SDK library $< -> $@"
|
||||
$(Q) $(OBJCOPY) --redefine-syms $(word 2,$^) --weaken $< $@
|
||||
|
||||
# include "dummy component" for the 'program' object files, defined in the Makefile
|
||||
PROGRAM_SRC_DIR ?= $(PROGRAM_DIR)
|
||||
PROGRAM_ROOT ?= $(PROGRAM_DIR)
|
||||
|
@ -227,7 +242,7 @@ $(foreach component,$(COMPONENTS), $(eval include $(ROOT)$(component)/component.
|
|||
# final linking step to produce .elf
|
||||
$(PROGRAM_OUT): $(COMPONENT_ARS) $(SDK_PROCESSED_LIBS) $(LINKER_SCRIPTS)
|
||||
$(vecho) "LD $@"
|
||||
$(Q) $(LD) $(LDFLAGS) -Wl,--start-group $(SDK_LIB_ARGS) $(LIB_ARGS) $(COMPONENT_ARS) -Wl,--end-group -o $@
|
||||
$(Q) $(LD) $(LDFLAGS) -Wl,--start-group $(LIB_ARGS) $(SDK_LIB_ARGS) $(COMPONENT_ARS) -Wl,--end-group -o $@
|
||||
|
||||
$(BUILD_DIR) $(FW_BASE) $(BUILD_DIR)sdklib:
|
||||
$(Q) mkdir -p $@
|
||||
|
|
28
core/sdk_compat.c
Normal file
28
core/sdk_compat.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Wrappers for functions called by binary espressif libraries
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Copyright (C) 2015 Superhouse Automation Pty Ltd
|
||||
* BSD Licensed as described in the file LICENSE
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void *zalloc(size_t nbytes)
|
||||
{
|
||||
return calloc(1, nbytes);
|
||||
}
|
||||
|
||||
/* this is currently just a stub to see where in the SDK it gets
|
||||
called, and with what arguments...
|
||||
|
||||
In the binary SDK printf & ets_printf are aliased together, most
|
||||
references appear to be to printf but libphy, libwpa & libnet80211
|
||||
all call ets_printf sometimes... Seems to not be in common code
|
||||
paths, haven't investigated exactly where.
|
||||
*/
|
||||
int ets_printf(const char *format, ...) {
|
||||
return printf("ets_printf format=%s\r\n", format);
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@
|
|||
#include "espressif/esp_common.h"
|
||||
#include "espressif/sdk_private.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#include "espressif/esp_common.h"
|
||||
#include "espressif/sdk_private.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "ssl.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
struct test_vector {
|
||||
const uint8_t *key;
|
||||
const uint8_t key_len;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "esp_libc.h"
|
||||
#include "esp_misc.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_softap.h"
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2010 - 2011 Espressif System
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __ESP_LIBC_H__
|
||||
#define __ESP_LIBC_H__
|
||||
|
||||
char *strcpy(char *dst, const char *src);
|
||||
char *strncpy(char *dst, const char *src, size_t n);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
int strncmp(const char *s1, const char *s2, size_t n);
|
||||
size_t strlen(const char *s);
|
||||
char *strstr(const char *s1, const char *s2);
|
||||
char *strcat(char *dst, const char *src);
|
||||
char *strncat(char *dst, const char *src, size_t count);
|
||||
size_t strspn(const char *s, const char *accept);
|
||||
size_t strcspn(const char *s, const char *reject);
|
||||
char *strtok_r(char *s, const char *delim, char **ptrptr);
|
||||
char *strtok(char *s, const char *delim);
|
||||
char *strrchr(const char *s, int c);
|
||||
char *strdup(const char *s);
|
||||
char *strchr(const char *s, int c);
|
||||
long strtol(const char *str, char **endptr, int base);
|
||||
|
||||
void bzero(void *s, size_t n);
|
||||
|
||||
void *memcpy(void *dst, const void *src, size_t n);
|
||||
void *memset(void *dst, int c, size_t n);
|
||||
int memcmp(const void *m1, const void *m2, size_t n);
|
||||
void *memmove(void *dst, const void *src, size_t n);
|
||||
|
||||
int rand_r(unsigned int *seed);
|
||||
int rand(void);
|
||||
void srand(unsigned int i);
|
||||
|
||||
int printf(const char *format, ...);
|
||||
int sprintf(char *out, const char *format, ...);
|
||||
int snprintf(char *buf, unsigned int count, const char *format, ...);
|
||||
int puts(const char *str);
|
||||
int putchar(int c);
|
||||
|
||||
void *malloc(size_t n);
|
||||
void free(void *p);
|
||||
void *calloc(size_t c, size_t n);
|
||||
void *zalloc(size_t n);
|
||||
void *realloc(void *p, size_t n);
|
||||
|
||||
int atoi(const char *s);
|
||||
long atol(const char *s);
|
||||
|
||||
/* NOTE: don't use printf_opt in irq handler, for test */
|
||||
#define printf_opt(fmt, ...) do { \
|
||||
static const char flash_str[] ICACHE_RODATA_ATTR = fmt; \
|
||||
printf(flash_str, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
/* NOTE: don't use printf_opt in irq handler, for test */
|
||||
#define sprintf_opt(out, fmt, ...) do { \
|
||||
static const char flash_str[] ICACHE_RODATA_ATTR = fmt; \
|
||||
sprintf(out, flash_str, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#endif /* __LIBC_H__ */
|
3
lib/libmain.remove
Normal file
3
lib/libmain.remove
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Object files to be removed from libmain
|
||||
printf-stdarg.o
|
||||
libc.o
|
0
lib/libnet80211.remove
Normal file
0
lib/libnet80211.remove
Normal file
0
lib/libphy.remove
Normal file
0
lib/libphy.remove
Normal file
0
lib/libpp.remove
Normal file
0
lib/libpp.remove
Normal file
0
lib/libwpa.remove
Normal file
0
lib/libwpa.remove
Normal file
Loading…
Reference in a new issue