From 614736cbb23fd71794d489a22a2a78a2d45e2a1b Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 21 Sep 2017 11:09:44 -0700 Subject: [PATCH] Add code to detect if Cortex M series and disable architecture specific code in `armtarget.c`. Improved `Makefile.common` to include toolchain prefix. --- IDE/GCC-ARM/Makefile.common | 31 ++++++++++++++++++++----------- IDE/GCC-ARM/README.md | 6 +++++- IDE/GCC-ARM/Source/armtarget.c | 12 ++++++++++++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/IDE/GCC-ARM/Makefile.common b/IDE/GCC-ARM/Makefile.common index b64fc7c41..beab49806 100755 --- a/IDE/GCC-ARM/Makefile.common +++ b/IDE/GCC-ARM/Makefile.common @@ -3,7 +3,9 @@ CMD_ECHO = # Important directories BUILD_DIR = ./Build -TOOLCHAIN_DIR = /opt/gcc-arm-none-eabi/bin + +# Toolchain location and prefix +TOOLCHAIN = /opt/gcc-arm-none-eabi/bin/arm-none-eabi- INC = -I./Header \ -I./Source \ @@ -26,9 +28,16 @@ CFLAGS = $(ARCHFLAGS) -std=gnu99 -Wall -Wno-cpp \ -ffunction-sections -fdata-sections \ -Os -flto $(DBGFLAGS) -# LD: Remove unused sections, link with newlib-nano implementation, generate map -LDFLAGS = $(ARCHFLAGS) -Wl,--gc-sections --specs=nano.specs --specs=nosys.specs +# LD: Remove unused sections +LDFLAGS = $(ARCHFLAGS) -Wl,--gc-sections + +# LD: Link with newlib-nano implementation +LDFLAGS += --specs=nano.specs --specs=nosys.specs + +# LD: generate map LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(BIN).map $(DBGFLAGS) + +# LD: Entry point LDFLAGS += -Wl,-ereset_handler # Math lib (for DH) @@ -42,14 +51,14 @@ OBJS_C = $(addprefix $(BUILD_DIR)/, $(FILENAMES_C:.c=.o)) vpath %.c $(dir $(SRC_C)) # Tools selection -CC = $(TOOLCHAIN_DIR)/arm-none-eabi-gcc -AS = $(TOOLCHAIN_DIR)/arm-none-eabi-gcc -LD = $(TOOLCHAIN_DIR)/arm-none-eabi-gcc -AR = $(TOOLCHAIN_DIR)/arm-none-eabi-ar -NM = $(TOOLCHAIN_DIR)/arm-none-eabi-nm -OBJCOPY = $(TOOLCHAIN_DIR)/arm-none-eabi-objcopy -OBJDUMP = $(TOOLCHAIN_DIR)/arm-none-eabi-objdump -SIZE = $(TOOLCHAIN_DIR)/arm-none-eabi-size +CC = $(TOOLCHAIN)gcc +AS = $(TOOLCHAIN)gcc +LD = $(TOOLCHAIN)gcc +AR = $(TOOLCHAIN)ar +NM = $(TOOLCHAIN)nm +OBJCOPY = $(TOOLCHAIN)objcopy +OBJDUMP = $(TOOLCHAIN)objdump +SIZE = $(TOOLCHAIN)size build_hex: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).hex @echo "" diff --git a/IDE/GCC-ARM/README.md b/IDE/GCC-ARM/README.md index 00eb0d26e..34119dc43 100755 --- a/IDE/GCC-ARM/README.md +++ b/IDE/GCC-ARM/README.md @@ -1,5 +1,7 @@ # Example Project for GCC ARM +This example is for Cortex M series, but can be adopted for other architectures. + ## Design * All library options are defined in `Header/user_settings.h`. @@ -10,7 +12,9 @@ ## Building 1. Make sure you have `gcc-arm-none-eabi` installed. -2. Modify the `Makefile.common` to use correct toolchain directory `TOOLCHAIN_DIR` and architecture 'ARCHFLAGS' (default is cortex-m0 / thumb). See [GCC ARM Options](https://gcc.gnu.org/onlinedocs/gcc-4.7.3/gcc/ARM-Options.html) `-mcpu=name`. +2. Modify the `Makefile.common`: + * Use correct toolchain path `TOOLCHAIN`. + * Use correct architecture 'ARCHFLAGS' (default is cortex-m0 / thumb). See [GCC ARM Options](https://gcc.gnu.org/onlinedocs/gcc-4.7.3/gcc/ARM-Options.html) `-mcpu=name`. 3. Use `make` and it will build the static library and wolfCrypt test/benchmark and wolfSSL TLS client targets as `.elf` and `.hex` in `/Build`. Example: diff --git a/IDE/GCC-ARM/Source/armtarget.c b/IDE/GCC-ARM/Source/armtarget.c index c090f5a7e..13c830a39 100755 --- a/IDE/GCC-ARM/Source/armtarget.c +++ b/IDE/GCC-ARM/Source/armtarget.c @@ -28,6 +28,13 @@ #include #include +/* Test to determine if ARM Cortex M */ +#if defined(__arm__) && defined(__ARM_ARCH) && (__ARM_ARCH == 6 || __ARM_ARCH == 7) + #define CORTEX_M_SERIES +#endif + + +#ifdef CORTEX_M_SERIES /* Memory initialization */ extern uint32_t __data_load_start__[]; extern uint32_t __data_start__[]; @@ -55,10 +62,12 @@ void meminit32(uint32_t* start, uint32_t* end) *start++ = 0; } } +#endif /* CORTEX_M_SERIES */ /* Entry Point */ void reset_handler(void) { +#ifdef CORTEX_M_SERIES /* Init sections */ memcpy32(__data_load_start__, __data_start__, __data_end__); meminit32(__bss_start__, __bss_end__); @@ -66,6 +75,7 @@ void reset_handler(void) /* Init heap */ __heap_start__[0] = 0; __heap_start__[1] = ((uint32_t)__heap_end__ - (uint32_t)__heap_start__); +#endif /* CORTEX_M_SERIES */ /* Start main */ extern int main(void); @@ -75,6 +85,7 @@ void reset_handler(void) while(1); } +#ifdef CORTEX_M_SERIES // Vector Exception/Interrupt Handlers static void Default_Handler(void) { @@ -199,6 +210,7 @@ const vector_entry vectors[] __attribute__ ((section(".vectors"),used)) = /* remainder go below */ }; +#endif /* CORTEX_M_SERIES */ /* TIME CODE */