Hoernchen has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/39437?usp=email )


Change subject: add fw update crcstub
......................................................................

add fw update crcstub

Adds a crc stub that lives in front of the dfu bl updater app and checks it.

The whole process is somewhat complicated to ensure we end up not just with
a firmware file that contains the right crc for the right offsets, but the elf
file is updated as well, to ensure the result is debuggable as-is.

The stub is built as part of the firmware code, and ends up in its own section.
Linker script padding and alignment ensures that this works.

Change-Id: I39eae7aaafd5531db6ce48837c9499432caadbed
---
A crc_code.c
A crc_params.c
M gcc/Makefile
M gcc/gcc/same54p20a_dfu.ld
M gcc/gcc/same54p20a_flash.ld
M gcc/gcc/startup_same54.c
M usb_flash_main.c
7 files changed, 218 insertions(+), 101 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/37/39437/1

diff --git a/crc_code.c b/crc_code.c
new file mode 100644
index 0000000..62031a1
--- /dev/null
+++ b/crc_code.c
@@ -0,0 +1,120 @@
+#include <stdint.h>
+#ifndef HOST_TOOL
+#include "atmel_start.h"
+
+#ifdef __clang__
+#define OPTNONE optnone
+#else
+#define OPTNONE optimize(0)
+#endif
+
+extern void _Reset_Handler(void);
+
+__attribute__((used, section(".crc_code")))
+#endif
+static uint32_t
+calculate_crc(const uint8_t *data, uint32_t length) {
+  uint32_t crc = 0xFFFFFFFF;
+  for (uint32_t i = 0; i < length; i++) {
+    crc ^= data[i];
+    for (uint8_t j = 0; j < 8; j++) {
+      crc = (crc & 1) ? (crc >> 1) ^ 0xEDB88320 : crc >> 1;
+    }
+  }
+  return ~crc;
+}
+
+#ifndef HOST_TOOL
+__attribute__((used, section(".crc_code"), OPTNONE)) void Reset_Handler(void) {
+  extern uint32_t __CRC_Checksum;
+  extern uint32_t __CRC_Start;
+  extern uint32_t __CRC_End;
+  extern int main(void);
+
+  /*
+  the old BL will unfortunately enable usb even when booting and not doing 
dfu..
+  we must reset it here, or the host will get really unhappy trying to talk to 
the "attached"
+  dev and reset the bus...
+  */
+  USB->DEVICE.CTRLA.reg = 0x1;
+
+  uint32_t length = (uint32_t)&__CRC_End - (uint32_t)&__CRC_Start;
+  uint32_t calculated_crc = calculate_crc((uint8_t *)&__CRC_Start, length);
+  uint32_t expected_crc = *(uint32_t *)&__CRC_Checksum;
+
+  if (calculated_crc != expected_crc) {
+    static volatile uint32_t *dfu_magic = (uint32_t *)HSRAM_ADDR;
+    *dfu_magic = 0x44465521;
+
+    /* Reset the device if CRC does not match */
+    __DSB();
+    SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | (SCB->AIRCR & 
SCB_AIRCR_PRIGROUP_Msk) |
+                           SCB_AIRCR_SYSRESETREQ_Msk);
+    __DSB();
+  }
+
+  /* Proceed to main application */
+  // main();
+  _Reset_Handler();
+
+  /* Infinite loop if main returns */
+  while (1)
+    ;
+}
+#endif
+
+#ifdef HOST_TOOL
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Usage: ./tool <binary_file> <start_offset_hex> <length_hex>
+   - start_offset_hex and length_hex are hex values indicating where to 
calculate the CRC.
+*/
+int main(int argc, char *argv[]) {
+  if (argc != 4) {
+    fprintf(stderr, "Usage: %s <binary_file> <start_offset_hex> 
<length_hex>\n", argv[0]);
+    return 1;
+  }
+
+  const char *filename = argv[1];
+  // uint32_t start_offset = strtoul(argv[2], NULL, 16);
+  // uint32_t length = strtoul(argv[3], NULL, 16);
+  uint32_t start_offset = strtoul(argv[2], NULL, 10);
+  uint32_t length = strtoul(argv[3], NULL, 10);
+
+  FILE *f = fopen(filename, "rb");
+  if (!f) {
+    perror("fopen");
+    return 1;
+  }
+
+  // Seek to start_offset
+  if (fseek(f, (long)start_offset, SEEK_SET) != 0) {
+    perror("fseek");
+    fclose(f);
+    return 1;
+  }
+
+  uint8_t *buf = (uint8_t *)malloc(length);
+  if (!buf) {
+    fprintf(stderr, "Memory allocation error\n");
+    fclose(f);
+    return 1;
+  }
+
+  size_t read_bytes = fread(buf, 1, length, f);
+  fclose(f);
+
+  if (read_bytes != length) {
+    fprintf(stderr, "Error reading file or not enough data\n");
+    free(buf);
+    return 1;
+  }
+
+  uint32_t crc = calculate_crc(buf, length);
+  free(buf);
+
+  printf("%08X\n", crc);
+  return 0;
+}
+#endif
diff --git a/crc_params.c b/crc_params.c
new file mode 100644
index 0000000..032c71e
--- /dev/null
+++ b/crc_params.c
@@ -0,0 +1,5 @@
+#include <stdint.h>
+
+__attribute__((used, section(".crc_par"))) const uint32_t __CRC_Checksum = 
0xFFFFFFFF; /* Placeholder */
+// __attribute__((used, section(".crc_par"))) const uint32_t __CRC_Start = 
0xFFFFFFFF; /* Placeholder */
+// __attribute__((used, section(".crc_par"))) const uint32_t __CRC_End = 
0xFFFFFFFF; /* Placeholder */
diff --git a/gcc/Makefile b/gcc/Makefile
index 2df931e..9c32616 100644
--- a/gcc/Makefile
+++ b/gcc/Makefile
@@ -1,62 +1,18 @@
-################################################################################
-# User configuration. Can be edited
-################################################################################
-
-# Set for which board the bootloader should be compiled
-# run `make clean` for the change to be effective
 # possible values: SAME54_XPLAINED_PRO, SYSMOOCTSIM
+SHELL := /bin/bash
 BOARD ?= SYSMOOCTSIM
+CROSSCC ?= arm-none-eabi-
+SILENT ?= @

+ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
+
+#DBGFLGS = -fdebug-prefix-map=..=$(readlink -f .)
+DBGFLGS = -fdebug-prefix-map=..=$(ROOT_DIR)/.. -fno-omit-frame-pointer -ggdb3 
-Os # -fdata-sections -fno-common -Wl,--no-undefined -Wl,--strip-discarded 
#-Wl,--gc-debuginfo
 GIT_VERSION=$(shell ../git-version-gen $(TOP)/.tarvers)
+DBGFLGS += -DGIT_VERSION=\"$(GIT_VERSION)\"

-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
+MK_DIR = mkdir -p

-ifdef SystemRoot
-       SHELL = cmd.exe
-       MK_DIR = mkdir
-else
-       ifeq ($(shell uname), Linux)
-               MK_DIR = mkdir -p
-       endif
-
-       ifeq ($(shell uname | cut -d _ -f 1), CYGWIN)
-               MK_DIR = mkdir -p
-       endif
-
-       ifeq ($(shell uname | cut -d _ -f 1), MINGW32)
-               MK_DIR = mkdir -p
-       endif
-
-       ifeq ($(shell uname | cut -d _ -f 1), MINGW64)
-               MK_DIR = mkdir -p
-       endif
-endif
-
-# List the subdirectories for creating object files
-SUB_DIRS +=  \
- \
-hpl/pm \
-gcc \
-hpl/osc32kctrl \
-hpl/ramecc \
-hpl/dmac \
-usb/class/dfu/device \
-hal/src \
-hpl/mclk \
-usb \
-hal/utils/src \
-hpl/gclk \
-usb/device \
-hpl/oscctrl \
-gcc/gcc \
-hpl/nvmctrl \
-hpl/usb \
-hpl/core \
-hpl/cmcc
-
-# List the object files
 OBJS +=  \
 hal/src/hal_io.o \
 hpl/core/hpl_core_m4.o \
@@ -92,6 +48,18 @@
 usb/device/usbdc.o \
 hal/src/hal_atomic.o

+SRC_hosttools = crc_code.c
+SRC_dfu = usb_dfu_main.c crc_code.c crc_params.c
+SRC_flash = usb_flash_main.c
+
+OBJ_dfu := $(SRC_dfu:.c=.o)
+OBJ_flash := $(SRC_flash:.c=.o)
+
+DFU_DEPS := $(OBJ_dfu:.o=.d)
+FLASH_DEPS := $(OBJ_flash:.o=.d)
+
+
+SUB_DIRS := $(sort $(dir $(OBJS)))
 DEPS := $(OBJS:%.o=%.d)
 OBJS_AS_ARGS = $(patsubst %,"%",$(OBJS))
 DEPS_AS_ARGS = $(patsubst %,"%",$(DEPS))
@@ -99,64 +67,81 @@
 BOARD_LC := $(shell echo $(BOARD) | tr A-Z a-z)
 OUTPUT_FILE_NAME := bootloader-$(BOARD_LC)-$(GIT_VERSION)
 QUOTE := "
-# OUTPUT_FILE_PATH +=$(OUTPUT_FILE_NAME).elf
-#OUTPUT_FILE_PATH_AS_ARGS +=$(OUTPUT_FILE_NAME).elf
-BLSIZE_DEF := -D$(QUOTE)$(shell sed 's/;//g' gcc/blsize.ld | tr -d ' ')$(QUOTE)
-
-# .PHONY MAIN_dfu MAIN_flash
-# MAIN_%:
-#      = usb_dfu_main.o
+BLSZ = $(shell sed 's/;//g' gcc/blsize.ld | tr -d ' ' | cut -d '=' -f2)
+CALC_BLSZ = $(shell echo $$(( $(BLSZ) )))
+$(info blsize is $(CALC_BLSZ))
+BLSIZE_DEF := -D$(QUOTE)BL_SIZE_BYTE=$(CALC_BLSZ)$(QUOTE)

 vpath %.c ../
 vpath %.s ../
 vpath %.S ../

-.PHONY: clean-dfu clean-flash
+.PHONY: clean-dfu clean-flash hosttools

-all: $(SUB_DIRS) dfu-merge
+all: $(SUB_DIRS) hosttools dfu-merge
+
+hosttools:
+       $(CC) -DHOST_TOOL ../$(SRC_hosttools) -o crctool

 dfu-merge: $(OUTPUT_FILE_NAME)-dfu

 $(OUTPUT_FILE_NAME)-dfu: $(OUTPUT_FILE_NAME)-flash

-# Linker target
-
-$(OUTPUT_FILE_NAME)-%: $(OBJS) usb_%_main.o
-       @echo Building target: $@
+.SECONDEXPANSION:
+$(OUTPUT_FILE_NAME)-%: $(OBJS) $$(OBJ_$$*)
+       @echo Building target: $@ $^
        @echo Invoking: ARM/GNU Linker
-       $(QUOTE)arm-none-eabi-gcc$(QUOTE) -o $(OUTPUT_FILE_NAME)-$*.elf 
$(OBJS_AS_ARGS) "usb_$*_main.o" \
-       -Wl,--no-undefined -Wl,--print-memory-usage -Wl,--strip-discarded 
-Wl,--start-group -lm -Wl,--end-group -mthumb \
+       $(SILENT)$(QUOTE)$(CROSSCC)gcc$(QUOTE) -o $(OUTPUT_FILE_NAME)-$*.elf 
$(OBJS_AS_ARGS) $(OBJ_$*) \
+       $(DBGFLGS) -Wl,--no-undefined -Wl,--print-memory-usage 
-Wl,--strip-discarded -Wl,--start-group -lm -Wl,--end-group -mthumb \
        -Wl,-Map="$(OUTPUT_FILE_NAME)-$*.map" --specs=nano.specs 
-Wl,--gc-sections -mcpu=cortex-m4 \
        -T"../gcc/gcc/same54p20a_$*.ld" \
        -L"../gcc/gcc"
        @echo Finished building target: $@

-       "arm-none-eabi-objcopy" -O binary "$(OUTPUT_FILE_NAME)-$*.elf" 
"$(OUTPUT_FILE_NAME)-$*.bin"
-#      "arm-none-eabi-objcopy" -O ihex -R .eeprom -R .fuse -R .lock -R 
.signature  "$(OUTPUT_FILE_NAME)-$*.elf" "$(OUTPUT_FILE_NAME)-$*.hex"
-#      "arm-none-eabi-objcopy" -j .eeprom 
--set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 
--no-change-warnings -O binary "$(OUTPUT_FILE_NAME)-$*.elf" 
"$(OUTPUT_FILE_NAME)-$*.eep" || exit 0
-       "arm-none-eabi-objdump" -h -S "$(OUTPUT_FILE_NAME)-$*.elf" > 
"$(OUTPUT_FILE_NAME)-$*.lss"
-       "arm-none-eabi-size" "$(OUTPUT_FILE_NAME)-$*.elf"
-       ln -sf $(OUTPUT_FILE_NAME)-$*.bin bootloader-$(BOARD_LC)-$*.bin
-       ln -sf $(OUTPUT_FILE_NAME)-$*.elf bootloader-$(BOARD_LC)-$*.elf
+       $(SILENT)"$(CROSSCC)objcopy" -O binary "$(OUTPUT_FILE_NAME)-$*.elf" 
"$(OUTPUT_FILE_NAME)-$*.bin"
+#      $(SILENT)"$(CROSSCC)objcopy" -O ihex -R .eeprom -R .fuse -R .lock -R 
.signature  "$(OUTPUT_FILE_NAME)-$*.elf" "$(OUTPUT_FILE_NAME)-$*.hex"
+#      $(SILENT)"$(CROSSCC)objcopy" -j .eeprom 
--set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 
--no-change-warnings -O binary "$(OUTPUT_FILE_NAME)-$*.elf" 
"$(OUTPUT_FILE_NAME)-$*.eep" || exit 0
+       $(SILENT)"$(CROSSCC)objdump" -h -S "$(OUTPUT_FILE_NAME)-$*.elf" > 
"$(OUTPUT_FILE_NAME)-$*.lss"
+       $(SILENT)"$(CROSSCC)size" "$(OUTPUT_FILE_NAME)-$*.elf"
+       $(SILENT)ln -sf $(OUTPUT_FILE_NAME)-$*.bin bootloader-$(BOARD_LC)-$*.bin
+       $(SILENT)ln -sf $(OUTPUT_FILE_NAME)-$*.elf bootloader-$(BOARD_LC)-$*.elf

 .PHONY: dfu-merge
 dfu-merge:
        $(info updating updater section with padded bootloader file..)
-       $(SILENT)dd if=/dev/zero bs=16384 count=1 of=dfu-flash-padded.bin
-       $(SILENT)dd if=$(OUTPUT_FILE_NAME)-flash.bin conv=notrunc 
of=dfu-flash-padded.bin
-       $(SILENT)"arm-none-eabi-objcopy" --update-section 
.blupdate=dfu-flash-padded.bin $(OUTPUT_FILE_NAME)-dfu.elf
-       $(SILENT)"arm-none-eabi-objcopy" -O binary $(OUTPUT_FILE_NAME)-dfu.elf 
$(OUTPUT_FILE_NAME)-dfu.bin
-       rm dfu-flash-padded.bin
+       #$(SILENT)dd status=none if=/dev/zero bs=$(CALC_BLSZ) count=1 
of=dfu-flash-padded.bin
+       #$(SILENT)dd status=none if=$(OUTPUT_FILE_NAME)-flash.bin conv=notrunc 
of=dfu-flash-padded.bin
+       $(SILENT)cp -a $(OUTPUT_FILE_NAME)-flash.bin dfu-flash-padded.bin
+       $(SILENT)truncate -s $(CALC_BLSZ) dfu-flash-padded.bin
+       $(SILENT)"$(CROSSCC)objcopy" --update-section 
.blupdate=dfu-flash-padded.bin $(OUTPUT_FILE_NAME)-dfu.elf
+       $(SILENT)"$(CROSSCC)objcopy" -O binary $(OUTPUT_FILE_NAME)-dfu.elf 
$(OUTPUT_FILE_NAME)-dfu.bin
+       $(SILENT)rm dfu-flash-padded.bin
+
+       @FLASH_START_ADDR=0x$$($(CROSSCC)nm $(OUTPUT_FILE_NAME)-dfu.elf | grep 
' _sfixed$$' | cut -d' ' -f1); \
+       CRC_START_ADDR=0x$$($(CROSSCC)nm $(OUTPUT_FILE_NAME)-dfu.elf | grep ' 
__CRC_Start$$' | cut -d' ' -f1); \
+       CRC_END_ADDR=0x$$($(CROSSCC)nm $(OUTPUT_FILE_NAME)-dfu.elf | grep ' 
_etext$$' | cut -d' ' -f1); \
+       CRC_CHECKSUM_ADDR=0x$$($(CROSSCC)nm $(OUTPUT_FILE_NAME)-dfu.elf | grep 
' __CRC_Checksum$$' | cut -d' ' -f1); \
+       echo $$CRC_START_ADDR $$CRC_END_ADDR $$CRC_CHECKSUM_ADDR; \
+       CRC_START_OFFSET=$$(($$CRC_START_ADDR - $$FLASH_START_ADDR)); \
+       CRC_END_OFFSET=$$(($$CRC_END_ADDR - $$FLASH_START_ADDR)); \
+       CRC_CHECKSUM_OFFSET=$$(($$CRC_CHECKSUM_ADDR - $$FLASH_START_ADDR)); \
+       LENGTH=$$(($$CRC_END_OFFSET - $$CRC_START_OFFSET)); \
+       CRC_HEX=$$(./crctool $(OUTPUT_FILE_NAME)-dfu.bin $$CRC_START_OFFSET 
$$LENGTH ); \
+       echo len $$LENGTH : $$CRC_START_OFFSET-$$CRC_END_OFFSET, crco: 
$$CRC_CHECKSUM_OFFSET, start: $$CRC_START_ADDR crcval: $$CRC_HEX; \
+       [ $$(($$CRC_START_OFFSET - $$CRC_CHECKSUM_OFFSET)) -ne 4 ] && exit 1; \
+       printf $$CRC_HEX | xxd -r -p | xxd -e | xxd -r | dd 
of=$(OUTPUT_FILE_NAME)-dfu.bin bs=1 seek=$$CRC_CHECKSUM_OFFSET conv=notrunc 
2>/dev/null; \
+       xxd -s $$(($$CRC_START_ADDR - $$FLASH_START_ADDR -4)) -l 4 -g 1 
$(OUTPUT_FILE_NAME)-dfu.bin; \
+       "$(CROSSCC)objcopy" -O binary --only-section=.text 
$(OUTPUT_FILE_NAME)-dfu.elf section_text.bin; \
+       printf $$CRC_HEX | xxd -r -p | xxd -e | xxd -r | dd of=section_text.bin 
bs=1 seek=$$CRC_CHECKSUM_OFFSET conv=notrunc 2>/dev/null; \
+       xxd -s $$(($$CRC_START_ADDR - $$FLASH_START_ADDR -4)) -l 4 -g 1 
section_text.bin; \
+       "$(CROSSCC)objcopy" --update-section .text=section_text.bin 
$(OUTPUT_FILE_NAME)-dfu.elf;
+

 # Compiler targets
-
-
-
-
 %.o: %.c
        @echo Building file: $<
        @echo ARM/GNU C Compiler
-       $(QUOTE)arm-none-eabi-gcc$(QUOTE) -x c -mthumb -DDEBUG -Os 
-ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
+       $(QUOTE)$(CROSSCC)gcc$(QUOTE) $(DBGFLGS) -x c -Wstringop-truncation 
-Wformat-truncation -mthumb -DDEBUG  -ffunction-sections -mlong-calls  -Wall -c 
-std=gnu99 \
 $(BLSIZE_DEF) -D__SAME54P19A__ -D$(BOARD) -mcpu=cortex-m4 -mfloat-abi=softfp 
-mfpu=fpv4-sp-d16 \
 -I"../" -I"../config" -I"../hal/include" -I"../hal/utils/include" 
-I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" 
-I"../hpl/nvmctrl" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" 
-I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" 
-I"../config" -I"../usb" -I"../usb/class/dfu" -I"../usb/class/dfu/device" 
-I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include"  \
 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"  -o "$@" "$<"
@@ -165,7 +150,7 @@
 %.o: %.s
        @echo Building file: $<
        @echo ARM/GNU Assembler
-       $(QUOTE)arm-none-eabi-as$(QUOTE) -x c -mthumb -DDEBUG -Os 
-ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
+       $(QUOTE)$(CROSSCC)as$(QUOTE) $(DBGFLGS) -x c -mthumb -DDEBUG  
-ffunction-sections -mlong-calls  -Wall -c -std=gnu99 \
 $(BLSIZE_DEF) -D__SAME54P19A__ -D$(BOARD) -mcpu=cortex-m4 -mfloat-abi=softfp 
-mfpu=fpv4-sp-d16 \
 -I"../" -I"../config" -I"../hal/include" -I"../hal/utils/include" 
-I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" 
-I"../hpl/nvmctrl" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" 
-I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" 
-I"../config" -I"../usb" -I"../usb/class/dfu" -I"../usb/class/dfu/device" 
-I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include"  \
 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"  -o "$@" "$<"
@@ -174,7 +159,7 @@
 %.o: %.S
        @echo Building file: $<
        @echo ARM/GNU Preprocessing Assembler
-       $(QUOTE)arm-none-eabi-gcc$(QUOTE) -x c -mthumb -DDEBUG -Os 
-ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
+       $(QUOTE)$(CROSSCC)gcc$(QUOTE) $(DBGFLGS) -x c -mthumb -DDEBUG  
-ffunction-sections -mlong-calls  -Wall -c -std=gnu99 \
 $(BLSIZE_DEF) -D__SAME54P19A__ -D$(BOARD) -mcpu=cortex-m4 -mfloat-abi=softfp 
-mfpu=fpv4-sp-d16 \
 -I"../" -I"../config" -I"../hal/include" -I"../hal/utils/include" 
-I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" 
-I"../hpl/nvmctrl" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" 
-I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" 
-I"../config" -I"../usb" -I"../usb/class/dfu" -I"../usb/class/dfu/device" 
-I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include"  \
 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"  -o "$@" "$<"
@@ -184,7 +169,8 @@
 ifneq ($(MAKECMDGOALS),clean)
 ifneq ($(strip $(DEPS)),)
 -include $(DEPS)
--include usb_flash_main.d usb_dfu_main.d
+-include $(DFU_DEPS)
+-include $(FLASH_DEPS)
 endif
 endif

@@ -192,20 +178,13 @@
        $(MK_DIR) "$@"

 clean-%:
-       rm -f $(OBJS_AS_ARGS)
-       # rm -f $(OUTPUT_FILE_PATH)
-       rm -f $(DEPS_AS_ARGS)
        rm -f $(OUTPUT_FILE_NAME)-$*.a $(OUTPUT_FILE_NAME)-$*.hex 
$(OUTPUT_FILE_NAME)-$*.bin \
                $(OUTPUT_FILE_NAME)-$*.lss $(OUTPUT_FILE_NAME)-$*.eep 
$(OUTPUT_FILE_NAME)-$*.map \
                $(OUTPUT_FILE_NAME)-$*.srec bootloader-$(BOARD_LC)-$*.bin 
bootloader-$(BOARD_LC)-$*.elf

 clean: clean-dfu clean-flash
        rm -f $(OBJS_AS_ARGS)
-       # rm -f $(OUTPUT_FILE_PATH)
        rm -f $(DEPS_AS_ARGS)
-       # rm -f $(OUTPUT_FILE_NAME).a $(OUTPUT_FILE_NAME).hex 
$(OUTPUT_FILE_NAME).bin \
-       #       $(OUTPUT_FILE_NAME).lss $(OUTPUT_FILE_NAME).eep 
$(OUTPUT_FILE_NAME).map \
-       #       $(OUTPUT_FILE_NAME).srec bootloader-$(BOARD_LC).bin 
bootloader-$(BOARD_LC).elf

 mrproper: clean
        rm -f *.o *.d *.a *.elf *.bin *.hex *.ihex *.eep *.lss *.map *.srec
diff --git a/gcc/gcc/same54p20a_dfu.ld b/gcc/gcc/same54p20a_dfu.ld
index becba88..9a3ff73 100644
--- a/gcc/gcc/same54p20a_dfu.ld
+++ b/gcc/gcc/same54p20a_dfu.ld
@@ -54,6 +54,10 @@
         . = ALIGN(4);
         _sfixed = .;
         KEEP(*(.vectors .vectors.*))
+        KEEP(*(.crc_code))     /* CRC checking code */
+        KEEP(*(.crc_par))      /* CRC parameters */
+        . = ALIGN(4);
+        __CRC_Start = ORIGIN(rom) + .;
         *(.text .text.* .gnu.linkonce.t.*)
         *(.glue_7t) *(.glue_7)
         *(.rodata .rodata* .gnu.linkonce.r.*)
@@ -96,14 +100,14 @@

         . = ALIGN(4);
         _efixed = .;            /* End of text section */
-    } > rom
+    } > rom = 0xff

     /* .ARM.exidx is sorted, so has to go in its own output section.  */
     PROVIDE_HIDDEN (__exidx_start = .);
     .ARM.exidx :
     {
       *(.ARM.exidx* .gnu.linkonce.armexidx.*)
-    } > rom
+    } > rom = 0xff
     PROVIDE_HIDDEN (__exidx_end = .);

     .blupdate :
@@ -112,10 +116,11 @@
         _blupdate_start = .;
         KEEP(*(.fwupdate .fwupdate.*));
         _blupdate_end = .;
-    } > rom
+    } > rom = 0xff

     . = ALIGN(4);
     _etext = .;
+    __CRC_End = .;

     .relocate : AT (_etext)
     {
diff --git a/gcc/gcc/same54p20a_flash.ld b/gcc/gcc/same54p20a_flash.ld
index f2c5124..354105b 100644
--- a/gcc/gcc/same54p20a_flash.ld
+++ b/gcc/gcc/same54p20a_flash.ld
@@ -96,14 +96,14 @@

         . = ALIGN(4);
         _efixed = .;            /* End of text section */
-    } > rom
+    } > rom = 0xff

     /* .ARM.exidx is sorted, so has to go in its own output section.  */
     PROVIDE_HIDDEN (__exidx_start = .);
     .ARM.exidx :
     {
       *(.ARM.exidx* .gnu.linkonce.armexidx.*)
-    } > rom
+    } > rom = 0xff
     PROVIDE_HIDDEN (__exidx_end = .);

     . = ALIGN(4);
@@ -162,4 +162,11 @@

     . = ALIGN(4);
     _end = . ;
+
+    /DISCARD/ :
+    {
+        *(.crc_code*)
+        *(.crc_par*)
+    }
+
 }
diff --git a/gcc/gcc/startup_same54.c b/gcc/gcc/startup_same54.c
index b943e54..4796f30 100644
--- a/gcc/gcc/startup_same54.c
+++ b/gcc/gcc/startup_same54.c
@@ -668,7 +668,7 @@
                ;
 }

-__attribute__((naked,noreturn)) void Reset_Handler(void)
+__attribute__((naked,noreturn,weak)) void Reset_Handler(void)
 {
 // errata 2.6.10, do not remove this, ever.
 // WDT->CTRLA.reg = 0;
diff --git a/usb_flash_main.c b/usb_flash_main.c
index b057d0a..dd2523f 100644
--- a/usb_flash_main.c
+++ b/usb_flash_main.c
@@ -20,6 +20,7 @@
  */

 #include <errno.h>
+#include <stdio.h>
 #include "atmel_start.h"
 #include "atmel_start_pins.h"
 #include "hpl_user_area.h"

--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/39437?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: I39eae7aaafd5531db6ce48837c9499432caadbed
Gerrit-Change-Number: 39437
Gerrit-PatchSet: 1
Gerrit-Owner: Hoernchen <[email protected]>

Reply via email to