From f5ff6a11f04d5251de1343c0f4321c7dba1ca554 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Wed, 20 Mar 2019 14:26:47 -0400 Subject: [PATCH 01/14] rewrite base linker script --- targets/stm32l432/linker/stm32l4xx.ld | 242 ++++++-------------------- 1 file changed, 57 insertions(+), 185 deletions(-) diff --git a/targets/stm32l432/linker/stm32l4xx.ld b/targets/stm32l432/linker/stm32l4xx.ld index d44d5d6..5601d6c 100644 --- a/targets/stm32l432/linker/stm32l4xx.ld +++ b/targets/stm32l432/linker/stm32l4xx.ld @@ -1,202 +1,74 @@ -/* -***************************************************************************** -** +/* Copyright 2019 SoloKeys Developers */ +/* */ +/* Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be */ +/* copied, modified, or distributed except according to those terms. */ -** File : LinkerScript.ld -** -** Abstract : Linker script for STM32L432KCUx Device with -** 256KByte FLASH, 64KByte RAM -** -** Set heap size, stack size and stack location according -** to application requirements. -** -** Set memory bank area and size if external memory is used. -** -** Target : STMicroelectronics STM32 -** -** -** Distribution: The file is distributed as is, without any warranty -** of any kind. -** -** (c)Copyright Ac6. -** You may use this file as-is or modify it according to the needs of your -** project. Distribution of this file (unmodified or modified) is not -** permitted. Ac6 permit registered System Workbench for MCU users the -** rights to distribute the assembled, compiled & linked contents of this -** file as part of an application binary file, provided that it is built -** using the System Workbench for MCU toolchain. -** -***************************************************************************** -*/ - -/* Entry Point */ ENTRY(Reset_Handler) -/* Highest address of the user mode stack */ -_estack = 0x2000c000; /* end of RAM */ -/* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0x200; /* required amount of heap */ -_Min_Stack_Size = 0x400; /* required amount of stack */ +/* End of RAM */ +_estack = 0x2000c000; + +_MIN_STACK_SIZE = 0x400; -/* Specify the memory areas */ MEMORY { -/* First 20 KB is bootloader */ -FLASH (rx) : ORIGIN = 0x08005000, LENGTH = 198K-8 /* Leave out 38 Kb at end for data */ -RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K -SRAM2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K + flash (rx) : ORIGIN = 0x08005000, LENGTH = 190K + ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K + sram2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K } -/* Define output sections */ SECTIONS { - /* The startup code goes first into FLASH */ - .isr_vector : - { - . = ALIGN(8); - KEEP(*(.isr_vector)) /* Startup code */ - . = ALIGN(8); - } >FLASH + .isr_vector : + { + . = ALIGN(8); + KEEP(*(.isr_vector)) + . = ALIGN(8); + } >flash - /* The program code and other data goes into FLASH */ - .text : - { - . = ALIGN(8); - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ - *(.glue_7) /* glue arm to thumb code */ - *(.glue_7t) /* glue thumb to arm code */ - *(.eh_frame) + .text : + { + . = ALIGN(8); + *(.text*) + *(.rodata*) + KEEP(*(.init)) + KEEP(*(.finit)) + . = ALIGN(8); + _etext = .; + } >flash - KEEP (*(.init)) - KEEP (*(.fini)) + _sidata = LOADADDR(.data); - . = ALIGN(8); - _etext = .; /* define a global symbols at end of code */ - } >FLASH + .data : + { + . = ALIGN(8); + _sdata = .; + *(.data*) + . = ALIGN(8); + _edata = .; + } >ram AT> flash - /* Constant data goes into FLASH */ - .rodata : - { - . = ALIGN(8); - *(.rodata) /* .rodata sections (constants, strings, etc.) */ - *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ - . = ALIGN(8); - } >FLASH + .bss : + { + . = ALIGN(4); + _sbss = .; + __bss_start__ = _sbss; + *(.bss*) + *(COMMON) + . = ALIGN(4); + _ebss = .; + __bss_end__ = _ebss; + } > ram - .ARM.extab : - { - . = ALIGN(8); - *(.ARM.extab* .gnu.linkonce.armextab.*) - . = ALIGN(8); - } >FLASH - .ARM : { - . = ALIGN(8); - __exidx_start = .; - *(.ARM.exidx*) - __exidx_end = .; - . = ALIGN(8); - } >FLASH + ._stack : + { + . = ALIGN(8); + end = .; + _end = .; + . = . + _MIN_STACK_SIZE; + . = ALIGN(8); + } > ram - .preinit_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array*)) - PROVIDE_HIDDEN (__preinit_array_end = .); - . = ALIGN(8); - } >FLASH - - .init_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array*)) - PROVIDE_HIDDEN (__init_array_end = .); - . = ALIGN(8); - } >FLASH - .fini_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array*)) - PROVIDE_HIDDEN (__fini_array_end = .); - . = ALIGN(8); - } >FLASH - - /* used by the startup to initialize data */ - _sidata = LOADADDR(.data); - - /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : - { - . = ALIGN(8); - _sdata = .; /* create a global symbol at data start */ - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ - - . = ALIGN(8); - _edata = .; /* define a global symbol at data end */ - } >RAM AT> FLASH - - _sisram2 = LOADADDR(.sram2); - - /* CCM-RAM section - * - * IMPORTANT NOTE! - * If initialized variables will be placed in this section, - * the startup code needs to be modified to copy the init-values. - */ - .sram2 : - { - . = ALIGN(8); - _ssram2 = .; /* create a global symbol at sram2 start */ - *(.sram2) - *(.sram2*) - - . = ALIGN(8); - _esram2 = .; /* create a global symbol at sram2 end */ - } >SRAM2 AT> FLASH - - - /* Uninitialized data section */ - . = ALIGN(4); - .bss : - { - /* This is used by the startup in order to initialize the .bss secion */ - _sbss = .; /* define a global symbol at bss start */ - __bss_start__ = _sbss; - *(.bss) - *(.bss*) - *(COMMON) - - . = ALIGN(4); - _ebss = .; /* define a global symbol at bss end */ - __bss_end__ = _ebss; - } >RAM - - /* User_heap_stack section, used to check that there is enough RAM left */ - ._user_heap_stack : - { - . = ALIGN(8); - PROVIDE ( end = . ); - PROVIDE ( _end = . ); - . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; - . = ALIGN(8); - } >RAM - - - - /* Remove information from the standard libraries */ - /DISCARD/ : - { - libc.a ( * ) - libm.a ( * ) - libgcc.a ( * ) - } - - .ARM.attributes 0 : { *(.ARM.attributes) } } From 175f59d20617acbdf74fbc2493cf50478ae683a9 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Wed, 20 Mar 2019 14:35:30 -0400 Subject: [PATCH 02/14] paste into other linker scripts --- .../stm32l432/linker/bootloader_stm32l4xx.ld | 241 ++++------------- .../linker/bootloader_stm32l4xx_extra.ld | 241 ++++------------- targets/stm32l432/linker/stm32l4xx_extra.ld | 243 ++++-------------- 3 files changed, 171 insertions(+), 554 deletions(-) diff --git a/targets/stm32l432/linker/bootloader_stm32l4xx.ld b/targets/stm32l432/linker/bootloader_stm32l4xx.ld index 333501a..58bad83 100644 --- a/targets/stm32l432/linker/bootloader_stm32l4xx.ld +++ b/targets/stm32l432/linker/bootloader_stm32l4xx.ld @@ -1,201 +1,74 @@ -/* -***************************************************************************** -** +/* Copyright 2019 SoloKeys Developers */ +/* */ +/* Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be */ +/* copied, modified, or distributed except according to those terms. */ -** File : LinkerScript.ld -** -** Abstract : Linker script for STM32L432KCUx Device with -** 256KByte FLASH, 64KByte RAM -** -** Set heap size, stack size and stack location according -** to application requirements. -** -** Set memory bank area and size if external memory is used. -** -** Target : STMicroelectronics STM32 -** -** -** Distribution: The file is distributed as is, without any warranty -** of any kind. -** -** (c)Copyright Ac6. -** You may use this file as-is or modify it according to the needs of your -** project. Distribution of this file (unmodified or modified) is not -** permitted. Ac6 permit registered System Workbench for MCU users the -** rights to distribute the assembled, compiled & linked contents of this -** file as part of an application binary file, provided that it is built -** using the System Workbench for MCU toolchain. -** -***************************************************************************** -*/ - -/* Entry Point */ ENTRY(Reset_Handler) -/* Highest address of the user mode stack */ -_estack = 0x2000c000; /* end of RAM */ -/* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0x200; /* required amount of heap */ -_Min_Stack_Size = 0x400; /* required amount of stack */ +/* End of RAM */ +_estack = 0x2000c000; + +_MIN_STACK_SIZE = 0x400; -/* Specify the memory areas */ MEMORY { -FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 20K -RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K -SRAM2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K + flash (rx) : ORIGIN = 0x08000000, LENGTH = 20K + ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K + sram2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K } -/* Define output sections */ SECTIONS { - /* The startup code goes first into FLASH */ - .isr_vector : - { - . = ALIGN(8); - KEEP(*(.isr_vector)) /* Startup code */ - . = ALIGN(8); - } >FLASH + .isr_vector : + { + . = ALIGN(8); + KEEP(*(.isr_vector)) + . = ALIGN(8); + } >flash - /* The program code and other data goes into FLASH */ - .text : - { - . = ALIGN(8); - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ - *(.glue_7) /* glue arm to thumb code */ - *(.glue_7t) /* glue thumb to arm code */ - *(.eh_frame) + .text : + { + . = ALIGN(8); + *(.text*) + *(.rodata*) + KEEP(*(.init)) + KEEP(*(.finit)) + . = ALIGN(8); + _etext = .; + } >flash - KEEP (*(.init)) - KEEP (*(.fini)) + _sidata = LOADADDR(.data); - . = ALIGN(8); - _etext = .; /* define a global symbols at end of code */ - } >FLASH + .data : + { + . = ALIGN(8); + _sdata = .; + *(.data*) + . = ALIGN(8); + _edata = .; + } >ram AT> flash - /* Constant data goes into FLASH */ - .rodata : - { - . = ALIGN(8); - *(.rodata) /* .rodata sections (constants, strings, etc.) */ - *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ - . = ALIGN(8); - } >FLASH + .bss : + { + . = ALIGN(4); + _sbss = .; + __bss_start__ = _sbss; + *(.bss*) + *(COMMON) + . = ALIGN(4); + _ebss = .; + __bss_end__ = _ebss; + } > ram - .ARM.extab : - { - . = ALIGN(8); - *(.ARM.extab* .gnu.linkonce.armextab.*) - . = ALIGN(8); - } >FLASH - .ARM : { - . = ALIGN(8); - __exidx_start = .; - *(.ARM.exidx*) - __exidx_end = .; - . = ALIGN(8); - } >FLASH + ._stack : + { + . = ALIGN(8); + end = .; + _end = .; + . = . + _MIN_STACK_SIZE; + . = ALIGN(8); + } > ram - .preinit_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array*)) - PROVIDE_HIDDEN (__preinit_array_end = .); - . = ALIGN(8); - } >FLASH - - .init_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array*)) - PROVIDE_HIDDEN (__init_array_end = .); - . = ALIGN(8); - } >FLASH - .fini_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array*)) - PROVIDE_HIDDEN (__fini_array_end = .); - . = ALIGN(8); - } >FLASH - - /* used by the startup to initialize data */ - _sidata = LOADADDR(.data); - - /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : - { - . = ALIGN(8); - _sdata = .; /* create a global symbol at data start */ - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ - - . = ALIGN(8); - _edata = .; /* define a global symbol at data end */ - } >RAM AT> FLASH - - _sisram2 = LOADADDR(.sram2); - - /* CCM-RAM section - * - * IMPORTANT NOTE! - * If initialized variables will be placed in this section, - * the startup code needs to be modified to copy the init-values. - */ - .sram2 : - { - . = ALIGN(8); - _ssram2 = .; /* create a global symbol at sram2 start */ - *(.sram2) - *(.sram2*) - - . = ALIGN(8); - _esram2 = .; /* create a global symbol at sram2 end */ - } >SRAM2 AT> FLASH - - - /* Uninitialized data section */ - . = ALIGN(4); - .bss : - { - /* This is used by the startup in order to initialize the .bss secion */ - _sbss = .; /* define a global symbol at bss start */ - __bss_start__ = _sbss; - *(.bss) - *(.bss*) - *(COMMON) - - . = ALIGN(4); - _ebss = .; /* define a global symbol at bss end */ - __bss_end__ = _ebss; - } >RAM - - /* User_heap_stack section, used to check that there is enough RAM left */ - ._user_heap_stack : - { - . = ALIGN(8); - PROVIDE ( end = . ); - PROVIDE ( _end = . ); - . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; - . = ALIGN(8); - } >RAM - - - - /* Remove information from the standard libraries */ - /DISCARD/ : - { - libc.a ( * ) - libm.a ( * ) - libgcc.a ( * ) - } - - .ARM.attributes 0 : { *(.ARM.attributes) } } diff --git a/targets/stm32l432/linker/bootloader_stm32l4xx_extra.ld b/targets/stm32l432/linker/bootloader_stm32l4xx_extra.ld index 59a0907..09cbf68 100644 --- a/targets/stm32l432/linker/bootloader_stm32l4xx_extra.ld +++ b/targets/stm32l432/linker/bootloader_stm32l4xx_extra.ld @@ -1,201 +1,74 @@ -/* -***************************************************************************** -** +/* Copyright 2019 SoloKeys Developers */ +/* */ +/* Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be */ +/* copied, modified, or distributed except according to those terms. */ -** File : LinkerScript.ld -** -** Abstract : Linker script for STM32L432KCUx Device with -** 256KByte FLASH, 64KByte RAM -** -** Set heap size, stack size and stack location according -** to application requirements. -** -** Set memory bank area and size if external memory is used. -** -** Target : STMicroelectronics STM32 -** -** -** Distribution: The file is distributed as is, without any warranty -** of any kind. -** -** (c)Copyright Ac6. -** You may use this file as-is or modify it according to the needs of your -** project. Distribution of this file (unmodified or modified) is not -** permitted. Ac6 permit registered System Workbench for MCU users the -** rights to distribute the assembled, compiled & linked contents of this -** file as part of an application binary file, provided that it is built -** using the System Workbench for MCU toolchain. -** -***************************************************************************** -*/ - -/* Entry Point */ ENTRY(Reset_Handler) -/* Highest address of the user mode stack */ -_estack = 0x2000c000; /* end of RAM */ -/* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0x200; /* required amount of heap */ -_Min_Stack_Size = 0x400; /* required amount of stack */ +/* End of RAM */ +_estack = 0x2000c000; + +_MIN_STACK_SIZE = 0x400; -/* Specify the memory areas */ MEMORY { -FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K -RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K -SRAM2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K + flash (rx) : ORIGIN = 0x08000000, LENGTH = 32K + ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K + sram2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K } -/* Define output sections */ SECTIONS { - /* The startup code goes first into FLASH */ - .isr_vector : - { - . = ALIGN(8); - KEEP(*(.isr_vector)) /* Startup code */ - . = ALIGN(8); - } >FLASH + .isr_vector : + { + . = ALIGN(8); + KEEP(*(.isr_vector)) + . = ALIGN(8); + } >flash - /* The program code and other data goes into FLASH */ - .text : - { - . = ALIGN(8); - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ - *(.glue_7) /* glue arm to thumb code */ - *(.glue_7t) /* glue thumb to arm code */ - *(.eh_frame) + .text : + { + . = ALIGN(8); + *(.text*) + *(.rodata*) + KEEP(*(.init)) + KEEP(*(.finit)) + . = ALIGN(8); + _etext = .; + } >flash - KEEP (*(.init)) - KEEP (*(.fini)) + _sidata = LOADADDR(.data); - . = ALIGN(8); - _etext = .; /* define a global symbols at end of code */ - } >FLASH + .data : + { + . = ALIGN(8); + _sdata = .; + *(.data*) + . = ALIGN(8); + _edata = .; + } >ram AT> flash - /* Constant data goes into FLASH */ - .rodata : - { - . = ALIGN(8); - *(.rodata) /* .rodata sections (constants, strings, etc.) */ - *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ - . = ALIGN(8); - } >FLASH + .bss : + { + . = ALIGN(4); + _sbss = .; + __bss_start__ = _sbss; + *(.bss*) + *(COMMON) + . = ALIGN(4); + _ebss = .; + __bss_end__ = _ebss; + } > ram - .ARM.extab : - { - . = ALIGN(8); - *(.ARM.extab* .gnu.linkonce.armextab.*) - . = ALIGN(8); - } >FLASH - .ARM : { - . = ALIGN(8); - __exidx_start = .; - *(.ARM.exidx*) - __exidx_end = .; - . = ALIGN(8); - } >FLASH + ._stack : + { + . = ALIGN(8); + end = .; + _end = .; + . = . + _MIN_STACK_SIZE; + . = ALIGN(8); + } > ram - .preinit_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array*)) - PROVIDE_HIDDEN (__preinit_array_end = .); - . = ALIGN(8); - } >FLASH - - .init_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array*)) - PROVIDE_HIDDEN (__init_array_end = .); - . = ALIGN(8); - } >FLASH - .fini_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array*)) - PROVIDE_HIDDEN (__fini_array_end = .); - . = ALIGN(8); - } >FLASH - - /* used by the startup to initialize data */ - _sidata = LOADADDR(.data); - - /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : - { - . = ALIGN(8); - _sdata = .; /* create a global symbol at data start */ - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ - - . = ALIGN(8); - _edata = .; /* define a global symbol at data end */ - } >RAM AT> FLASH - - _sisram2 = LOADADDR(.sram2); - - /* CCM-RAM section - * - * IMPORTANT NOTE! - * If initialized variables will be placed in this section, - * the startup code needs to be modified to copy the init-values. - */ - .sram2 : - { - . = ALIGN(8); - _ssram2 = .; /* create a global symbol at sram2 start */ - *(.sram2) - *(.sram2*) - - . = ALIGN(8); - _esram2 = .; /* create a global symbol at sram2 end */ - } >SRAM2 AT> FLASH - - - /* Uninitialized data section */ - . = ALIGN(4); - .bss : - { - /* This is used by the startup in order to initialize the .bss secion */ - _sbss = .; /* define a global symbol at bss start */ - __bss_start__ = _sbss; - *(.bss) - *(.bss*) - *(COMMON) - - . = ALIGN(4); - _ebss = .; /* define a global symbol at bss end */ - __bss_end__ = _ebss; - } >RAM - - /* User_heap_stack section, used to check that there is enough RAM left */ - ._user_heap_stack : - { - . = ALIGN(8); - PROVIDE ( end = . ); - PROVIDE ( _end = . ); - . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; - . = ALIGN(8); - } >RAM - - - - /* Remove information from the standard libraries */ - /DISCARD/ : - { - libc.a ( * ) - libm.a ( * ) - libgcc.a ( * ) - } - - .ARM.attributes 0 : { *(.ARM.attributes) } } diff --git a/targets/stm32l432/linker/stm32l4xx_extra.ld b/targets/stm32l432/linker/stm32l4xx_extra.ld index 8e69379..b96409f 100644 --- a/targets/stm32l432/linker/stm32l4xx_extra.ld +++ b/targets/stm32l432/linker/stm32l4xx_extra.ld @@ -1,203 +1,74 @@ -/* -***************************************************************************** -** +/* Copyright 2019 SoloKeys Developers */ +/* */ +/* Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be */ +/* copied, modified, or distributed except according to those terms. */ -** File : LinkerScript.ld -** -** Abstract : Linker script for STM32L432KCUx Device with -** 256KByte FLASH, 64KByte RAM -** -** Set heap size, stack size and stack location according -** to application requirements. -** -** Set memory bank area and size if external memory is used. -** -** Target : STMicroelectronics STM32 -** -** -** Distribution: The file is distributed as is, without any warranty -** of any kind. -** -** (c)Copyright Ac6. -** You may use this file as-is or modify it according to the needs of your -** project. Distribution of this file (unmodified or modified) is not -** permitted. Ac6 permit registered System Workbench for MCU users the -** rights to distribute the assembled, compiled & linked contents of this -** file as part of an application binary file, provided that it is built -** using the System Workbench for MCU toolchain. -** -***************************************************************************** -*/ - -/* Entry Point */ ENTRY(Reset_Handler) -/* Highest address of the user mode stack */ -_estack = 0x2000c000; /* end of RAM */ -/* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0x200; /* required amount of heap */ -_Min_Stack_Size = 0x400; /* required amount of stack */ +/* End of RAM */ +_estack = 0x2000c000; + +_MIN_STACK_SIZE = 0x400; -/* Specify the memory areas */ MEMORY { -/* First 32 KB is bootloader */ -/*FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 238K-8 [> Leave out 38 Kb at end for data <]*/ -FLASH (rx) : ORIGIN = 0x08008000, LENGTH = 186K-8 /* Leave out 38 Kb at end for data */ -RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K -SRAM2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K + flash (rx) : ORIGIN = 0x08008000, LENGTH = 186K-8 /* Leave out 38 Kb at end for data */ + ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K + sram2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K } -/* Define output sections */ SECTIONS { - /* The startup code goes first into FLASH */ - .isr_vector : - { - . = ALIGN(8); - KEEP(*(.isr_vector)) /* Startup code */ - . = ALIGN(8); - } >FLASH + .isr_vector : + { + . = ALIGN(8); + KEEP(*(.isr_vector)) + . = ALIGN(8); + } >flash - /* The program code and other data goes into FLASH */ - .text : - { - . = ALIGN(8); - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ - *(.glue_7) /* glue arm to thumb code */ - *(.glue_7t) /* glue thumb to arm code */ - *(.eh_frame) + .text : + { + . = ALIGN(8); + *(.text*) + *(.rodata*) + KEEP(*(.init)) + KEEP(*(.finit)) + . = ALIGN(8); + _etext = .; + } >flash - KEEP (*(.init)) - KEEP (*(.fini)) + _sidata = LOADADDR(.data); - . = ALIGN(8); - _etext = .; /* define a global symbols at end of code */ - } >FLASH + .data : + { + . = ALIGN(8); + _sdata = .; + *(.data*) + . = ALIGN(8); + _edata = .; + } >ram AT> flash - /* Constant data goes into FLASH */ - .rodata : - { - . = ALIGN(8); - *(.rodata) /* .rodata sections (constants, strings, etc.) */ - *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ - . = ALIGN(8); - } >FLASH + .bss : + { + . = ALIGN(4); + _sbss = .; + __bss_start__ = _sbss; + *(.bss*) + *(COMMON) + . = ALIGN(4); + _ebss = .; + __bss_end__ = _ebss; + } > ram - .ARM.extab : - { - . = ALIGN(8); - *(.ARM.extab* .gnu.linkonce.armextab.*) - . = ALIGN(8); - } >FLASH - .ARM : { - . = ALIGN(8); - __exidx_start = .; - *(.ARM.exidx*) - __exidx_end = .; - . = ALIGN(8); - } >FLASH + ._stack : + { + . = ALIGN(8); + end = .; + _end = .; + . = . + _MIN_STACK_SIZE; + . = ALIGN(8); + } > ram - .preinit_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array*)) - PROVIDE_HIDDEN (__preinit_array_end = .); - . = ALIGN(8); - } >FLASH - - .init_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array*)) - PROVIDE_HIDDEN (__init_array_end = .); - . = ALIGN(8); - } >FLASH - .fini_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array*)) - PROVIDE_HIDDEN (__fini_array_end = .); - . = ALIGN(8); - } >FLASH - - /* used by the startup to initialize data */ - _sidata = LOADADDR(.data); - - /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : - { - . = ALIGN(8); - _sdata = .; /* create a global symbol at data start */ - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ - - . = ALIGN(8); - _edata = .; /* define a global symbol at data end */ - } >RAM AT> FLASH - - _sisram2 = LOADADDR(.sram2); - - /* CCM-RAM section - * - * IMPORTANT NOTE! - * If initialized variables will be placed in this section, - * the startup code needs to be modified to copy the init-values. - */ - .sram2 : - { - . = ALIGN(8); - _ssram2 = .; /* create a global symbol at sram2 start */ - *(.sram2) - *(.sram2*) - - . = ALIGN(8); - _esram2 = .; /* create a global symbol at sram2 end */ - } >SRAM2 AT> FLASH - - - /* Uninitialized data section */ - . = ALIGN(4); - .bss : - { - /* This is used by the startup in order to initialize the .bss secion */ - _sbss = .; /* define a global symbol at bss start */ - __bss_start__ = _sbss; - *(.bss) - *(.bss*) - *(COMMON) - - . = ALIGN(4); - _ebss = .; /* define a global symbol at bss end */ - __bss_end__ = _ebss; - } >RAM - - /* User_heap_stack section, used to check that there is enough RAM left */ - ._user_heap_stack : - { - . = ALIGN(8); - PROVIDE ( end = . ); - PROVIDE ( _end = . ); - . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; - . = ALIGN(8); - } >RAM - - - - /* Remove information from the standard libraries */ - /DISCARD/ : - { - libc.a ( * ) - libm.a ( * ) - libgcc.a ( * ) - } - - .ARM.attributes 0 : { *(.ARM.attributes) } } From f3b591e570f550df52d6dd0f5472ea1412816987 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Thu, 21 Mar 2019 21:03:49 -0400 Subject: [PATCH 03/14] Apply suggestions from code review Co-Authored-By: conorpp --- targets/stm32l432/linker/bootloader_stm32l4xx.ld | 2 +- targets/stm32l432/linker/bootloader_stm32l4xx_extra.ld | 2 +- targets/stm32l432/linker/stm32l4xx.ld | 2 +- targets/stm32l432/linker/stm32l4xx_extra.ld | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/targets/stm32l432/linker/bootloader_stm32l4xx.ld b/targets/stm32l432/linker/bootloader_stm32l4xx.ld index 58bad83..cccd9c6 100644 --- a/targets/stm32l432/linker/bootloader_stm32l4xx.ld +++ b/targets/stm32l432/linker/bootloader_stm32l4xx.ld @@ -15,7 +15,7 @@ _MIN_STACK_SIZE = 0x400; MEMORY { flash (rx) : ORIGIN = 0x08000000, LENGTH = 20K - ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K + ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K sram2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K } diff --git a/targets/stm32l432/linker/bootloader_stm32l4xx_extra.ld b/targets/stm32l432/linker/bootloader_stm32l4xx_extra.ld index 09cbf68..3e1efd7 100644 --- a/targets/stm32l432/linker/bootloader_stm32l4xx_extra.ld +++ b/targets/stm32l432/linker/bootloader_stm32l4xx_extra.ld @@ -15,7 +15,7 @@ _MIN_STACK_SIZE = 0x400; MEMORY { flash (rx) : ORIGIN = 0x08000000, LENGTH = 32K - ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K + ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K sram2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K } diff --git a/targets/stm32l432/linker/stm32l4xx.ld b/targets/stm32l432/linker/stm32l4xx.ld index 5601d6c..9b010ed 100644 --- a/targets/stm32l432/linker/stm32l4xx.ld +++ b/targets/stm32l432/linker/stm32l4xx.ld @@ -15,7 +15,7 @@ _MIN_STACK_SIZE = 0x400; MEMORY { flash (rx) : ORIGIN = 0x08005000, LENGTH = 190K - ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K + ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K sram2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K } diff --git a/targets/stm32l432/linker/stm32l4xx_extra.ld b/targets/stm32l432/linker/stm32l4xx_extra.ld index b96409f..e58b1c8 100644 --- a/targets/stm32l432/linker/stm32l4xx_extra.ld +++ b/targets/stm32l432/linker/stm32l4xx_extra.ld @@ -14,8 +14,8 @@ _MIN_STACK_SIZE = 0x400; MEMORY { - flash (rx) : ORIGIN = 0x08008000, LENGTH = 186K-8 /* Leave out 38 Kb at end for data */ - ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K + flash (rx) : ORIGIN = 0x08008000, LENGTH = 178K + ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K sram2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K } From 3a10427bd9a64fb58a8f76f56222cc09954bb9be Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Fri, 22 Mar 2019 13:45:13 -0400 Subject: [PATCH 04/14] remove unused files --- targets/stm32l432/Makefile.test.mk | 73 ------------ targets/stm32l432/src/script.ld | 183 ----------------------------- 2 files changed, 256 deletions(-) delete mode 100644 targets/stm32l432/Makefile.test.mk delete mode 100644 targets/stm32l432/src/script.ld diff --git a/targets/stm32l432/Makefile.test.mk b/targets/stm32l432/Makefile.test.mk deleted file mode 100644 index 88a02ab..0000000 --- a/targets/stm32l432/Makefile.test.mk +++ /dev/null @@ -1,73 +0,0 @@ -CC=arm-none-eabi-gcc -CP=arm-none-eabi-objcopy -SZ=arm-none-eabi-size -AR=arm-none-eabi-ar - -# ST related -SRC = src/main.c src/init.c src/flash.c src/led.c -SRC += src/startup_stm32l432xx.s src/system_stm32l4xx.c -SRC += lib/stm32l4xx_ll_gpio.c lib/stm32l4xx_ll_pwr.c lib/stm32l4xx_ll_rcc.c lib/stm32l4xx_ll_tim.c lib/stm32l4xx_ll_utils.c - -OBJ1=$(SRC:.c=.o) -OBJ=$(OBJ1:.s=.o) - -INC = -Isrc/ -Isrc/cmsis/ -Ilib/ -Ilib/usbd/ -I../../fido2/ -I../../fido2/extensions -INC += -I../../tinycbor/src -I../../crypto/sha256 -I../../crypto/micro-ecc -INC += -I../../crypto/tiny-AES-c - -SEARCH=-L../../tinycbor/lib - -LDSCRIPT=stm32l432xx.ld - -CFLAGS= $(INC) - -TARGET=solo -HW=-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb - -# Solo or Nucleo board -CHIP=STM32L432xx - -DEFINES = -D$(CHIP) -DAES256=1 -DUSE_FULL_LL_DRIVER -DEFINES += -DTEST_SOLO_STM32 -DTEST - -CFLAGS=$(INC) -c $(DEFINES) -Wall -fdata-sections -ffunction-sections $(HW) -LDFLAGS_LIB=$(HW) $(SEARCH) -specs=nano.specs -specs=nosys.specs -Wl,--gc-sections -lnosys -LDFLAGS=$(HW) $(LDFLAGS_LIB) -T$(LDSCRIPT) -Wl,-Map=$(TARGET).map,--cref - - -.PRECIOUS: %.o - -all: $(TARGET).elf - $(SZ) $^ - -%.o: %.c - $(CC) $^ $(HW) -Os $(CFLAGS) -o $@ - -../../crypto/micro-ecc/uECC.o: ../../crypto/micro-ecc/uECC.c - $(CC) $^ $(HW) -O3 $(CFLAGS) -o $@ - -%.o: %.s - $(CC) $^ $(HW) -Os $(CFLAGS) -o $@ - -%.elf: $(OBJ) - $(CC) $^ $(HW) $(LDFLAGS) -o $@ - -%.hex: %.elf - $(CP) -O ihex $^ $(TARGET).hex - $(CP) -O binary $^ $(TARGET).bin - -clean: - rm -f *.o src/*.o src/*.elf *.elf *.hex $(OBJ) - -flash: $(TARGET).hex - STM32_Programmer_CLI -c port=SWD -halt -e all --readunprotect - STM32_Programmer_CLI -c port=SWD -halt -d $(TARGET).hex -rst - -detach: - STM32_Programmer_CLI -c port=usb1 -ob nBOOT0=1 - -cbor: - cd ../../tinycbor/ && make clean - cd ../../tinycbor/ && make CC="$(CC)" AR=$(AR) \ -LDFLAGS="$(LDFLAGS_LIB)" \ -CFLAGS="$(CFLAGS)" diff --git a/targets/stm32l432/src/script.ld b/targets/stm32l432/src/script.ld deleted file mode 100644 index 0db581f..0000000 --- a/targets/stm32l432/src/script.ld +++ /dev/null @@ -1,183 +0,0 @@ -/* -***************************************************************************** -** - -** File : LinkerScript.ld -** -** Abstract : Linker script for STM32L432KCUx Device with -** 256KByte FLASH, 64KByte RAM -** -** Set heap size, stack size and stack location according -** to application requirements. -** -** Set memory bank area and size if external memory is used. -** -** Target : STMicroelectronics STM32 -** -** -** Distribution: The file is distributed as is, without any warranty -** of any kind. -** -** (c)Copyright Ac6. -** You may use this file as-is or modify it according to the needs of your -** project. Distribution of this file (unmodified or modified) is not -** permitted. Ac6 permit registered System Workbench for MCU users the -** rights to distribute the assembled, compiled & linked contents of this -** file as part of an application binary file, provided that it is built -** using the System Workbench for MCU toolchain. -** -***************************************************************************** -*/ - -/* Entry Point */ -ENTRY(Reset_Handler) - -/* Highest address of the user mode stack */ -_estack = 0x20010000; /* end of RAM */ -/* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0x200; /* required amount of heap */ -_Min_Stack_Size = 0x400; /* required amount of stack */ - -/* Specify the memory areas */ -MEMORY -{ -RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K -FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 256K -} - -/* Define output sections */ -SECTIONS -{ - /* The startup code goes first into FLASH */ - .isr_vector : - { - . = ALIGN(8); - KEEP(*(.isr_vector)) /* Startup code */ - . = ALIGN(8); - } >FLASH - - /* The program code and other data goes into FLASH */ - .text : - { - . = ALIGN(8); - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ - *(.glue_7) /* glue arm to thumb code */ - *(.glue_7t) /* glue thumb to arm code */ - *(.eh_frame) - - KEEP (*(.init)) - KEEP (*(.fini)) - - . = ALIGN(8); - _etext = .; /* define a global symbols at end of code */ - } >FLASH - - /* Constant data goes into FLASH */ - .rodata : - { - . = ALIGN(8); - *(.rodata) /* .rodata sections (constants, strings, etc.) */ - *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ - . = ALIGN(8); - } >FLASH - - .ARM.extab : - { - . = ALIGN(8); - *(.ARM.extab* .gnu.linkonce.armextab.*) - . = ALIGN(8); - } >FLASH - .ARM : { - . = ALIGN(8); - __exidx_start = .; - *(.ARM.exidx*) - __exidx_end = .; - . = ALIGN(8); - } >FLASH - - .preinit_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array*)) - PROVIDE_HIDDEN (__preinit_array_end = .); - . = ALIGN(8); - } >FLASH - - .init_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array*)) - PROVIDE_HIDDEN (__init_array_end = .); - . = ALIGN(8); - } >FLASH - .fini_array : - { - . = ALIGN(8); - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array*)) - PROVIDE_HIDDEN (__fini_array_end = .); - . = ALIGN(8); - } >FLASH - - /* used by the startup to initialize data */ - _sidata = LOADADDR(.data); - - /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : - { - . = ALIGN(8); - _sdata = .; /* create a global symbol at data start */ - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ - - . = ALIGN(8); - _edata = .; /* define a global symbol at data end */ - } >RAM AT> FLASH - - - /* Uninitialized data section */ - . = ALIGN(4); - .bss : - { - /* This is used by the startup in order to initialize the .bss secion */ - _sbss = .; /* define a global symbol at bss start */ - __bss_start__ = _sbss; - *(.bss) - *(.bss*) - *(COMMON) - - . = ALIGN(4); - _ebss = .; /* define a global symbol at bss end */ - __bss_end__ = _ebss; - } >RAM - - /* User_heap_stack section, used to check that there is enough RAM left */ - ._user_heap_stack : - { - . = ALIGN(8); - PROVIDE ( end = . ); - PROVIDE ( _end = . ); - . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; - . = ALIGN(8); - } >RAM - - - - /* Remove information from the standard libraries */ - /DISCARD/ : - { - libc.a ( * ) - libm.a ( * ) - libgcc.a ( * ) - } - - .ARM.attributes 0 : { *(.ARM.attributes) } -} - - From a0d27c2c569c5afd6e9753f7508186b2e786d47b Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Fri, 22 Mar 2019 13:54:42 -0400 Subject: [PATCH 05/14] add memory layout commment, undo -8 simplification --- targets/stm32l432/linker/stm32l4xx.ld | 8 +++++++- targets/stm32l432/linker/stm32l4xx_extra.ld | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/targets/stm32l432/linker/stm32l4xx.ld b/targets/stm32l432/linker/stm32l4xx.ld index 9b010ed..4e43df7 100644 --- a/targets/stm32l432/linker/stm32l4xx.ld +++ b/targets/stm32l432/linker/stm32l4xx.ld @@ -12,9 +12,15 @@ _estack = 0x2000c000; _MIN_STACK_SIZE = 0x400; +/* + Memory layout of device: + 20 KB 198KB-8 38 KB + | bootloader | application | secrets/data | + */ + MEMORY { - flash (rx) : ORIGIN = 0x08005000, LENGTH = 190K + flash (rx) : ORIGIN = 0x08005000, LENGTH = 198K - 8 ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K sram2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K } diff --git a/targets/stm32l432/linker/stm32l4xx_extra.ld b/targets/stm32l432/linker/stm32l4xx_extra.ld index e58b1c8..6948c90 100644 --- a/targets/stm32l432/linker/stm32l4xx_extra.ld +++ b/targets/stm32l432/linker/stm32l4xx_extra.ld @@ -14,7 +14,7 @@ _MIN_STACK_SIZE = 0x400; MEMORY { - flash (rx) : ORIGIN = 0x08008000, LENGTH = 178K + flash (rx) : ORIGIN = 0x08008000, LENGTH = 186K - 8 ram (xrw) : ORIGIN = 0x20000000, LENGTH = 48K sram2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K } From 8f6ae29163936c144242fc940c25d0a995a311ec Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Tue, 12 Mar 2019 00:28:29 +0100 Subject: [PATCH 06/14] Fix ModemManager udev rule for some distros --- udev/Makefile | 8 ++++++++ udev/ModemManager-override.conf | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 udev/ModemManager-override.conf diff --git a/udev/Makefile b/udev/Makefile index 7bf6961..acd6991 100644 --- a/udev/Makefile +++ b/udev/Makefile @@ -26,3 +26,11 @@ install-legacy: # install-symlinks: # sudo cp $(PWD)/71-solokeys-symlinks.rules ${RULES_PATH}/71-solokeys-symlinks.rules + +# The ID_MM_DEVICE_IGNORE tag in our udev rules are ignored +# if ModemManager is running with "strict" filter policy. +# Debian Buster for instance does this. +# One solution is to run ModemManager with "paranoid" filter policy. +paranoid-modemmanager: dropin-paranoid-modemmanager activate +dropin-paranoid-modemmanager: + test -f /usr/sbin/ModemManager && sudo cp ModemManager-override.conf /etc/systemd/system/ModemManager.service.d/override.conf diff --git a/udev/ModemManager-override.conf b/udev/ModemManager-override.conf new file mode 100644 index 0000000..7621100 --- /dev/null +++ b/udev/ModemManager-override.conf @@ -0,0 +1,3 @@ +[Service] +ExecStart= +ExecStart=/usr/sbin/ModemManager --filter-policy=paranoid From 84d1629aa35d9d5857f6b43f03fd6c63ac2df37c Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Wed, 13 Mar 2019 02:25:49 +0100 Subject: [PATCH 07/14] Allow toggling between strict and paranoid ModemManager filter-policy --- udev/Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/udev/Makefile b/udev/Makefile index acd6991..a1b38e2 100644 --- a/udev/Makefile +++ b/udev/Makefile @@ -10,6 +10,8 @@ setup: install activate legacy-setup: install-legacy activate + +# Symlinks can be setup, we don't officially supply any # symlinks: install-symlinks activate RULES_PATH=/etc/udev/rules.d @@ -31,6 +33,14 @@ install-legacy: # if ModemManager is running with "strict" filter policy. # Debian Buster for instance does this. # One solution is to run ModemManager with "paranoid" filter policy. -paranoid-modemmanager: dropin-paranoid-modemmanager activate +paranoid-modemmanager: dropin-paranoid-modemmanager restart-modemmanager dropin-paranoid-modemmanager: test -f /usr/sbin/ModemManager && sudo cp ModemManager-override.conf /etc/systemd/system/ModemManager.service.d/override.conf + +strict-modemmanager: dropin-strict-modemmanager restart-modemmanager +dropin-strict-modemmanager: + sudo rm -f /etc/systemd/system/ModemManager.service.d/override.conf + +restart-modemmanager: + sudo systemctl daemon-reload + sudo systemctl restart ModemManager.service From c851807376ecb80adbc34dc3993d1aa102bb6757 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Fri, 22 Mar 2019 00:46:01 +0100 Subject: [PATCH 08/14] Do not advertise AT modem capabilities --- targets/stm32l432/lib/usbd/usbd_composite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/stm32l432/lib/usbd/usbd_composite.c b/targets/stm32l432/lib/usbd/usbd_composite.c index 7a3d6f1..a1a868c 100644 --- a/targets/stm32l432/lib/usbd/usbd_composite.c +++ b/targets/stm32l432/lib/usbd/usbd_composite.c @@ -110,7 +110,7 @@ __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_ 0x03, /* bNumEndpoints: 3 endpoints used */ 0x02, /* bInterfaceClass: Communication Interface Class */ 0x02, /* bInterfaceSubClass: Abstract Control Model */ - 0x01, /* bInterfaceProtocol: Common AT commands */ + 0x00, /* bInterfaceProtocol: Common AT commands */ 0x00, /* iInterface: */ /*Header Functional Descriptor*/ From 349ea5343aa3707994d1871b03506c87492264a3 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Fri, 22 Mar 2019 20:01:31 +0100 Subject: [PATCH 09/14] Remove paranoid MM stuff, not signaling AT modem is enough + better --- udev/Makefile | 16 ---------------- udev/ModemManager-override.conf | 3 --- 2 files changed, 19 deletions(-) delete mode 100644 udev/ModemManager-override.conf diff --git a/udev/Makefile b/udev/Makefile index a1b38e2..e716c1b 100644 --- a/udev/Makefile +++ b/udev/Makefile @@ -28,19 +28,3 @@ install-legacy: # install-symlinks: # sudo cp $(PWD)/71-solokeys-symlinks.rules ${RULES_PATH}/71-solokeys-symlinks.rules - -# The ID_MM_DEVICE_IGNORE tag in our udev rules are ignored -# if ModemManager is running with "strict" filter policy. -# Debian Buster for instance does this. -# One solution is to run ModemManager with "paranoid" filter policy. -paranoid-modemmanager: dropin-paranoid-modemmanager restart-modemmanager -dropin-paranoid-modemmanager: - test -f /usr/sbin/ModemManager && sudo cp ModemManager-override.conf /etc/systemd/system/ModemManager.service.d/override.conf - -strict-modemmanager: dropin-strict-modemmanager restart-modemmanager -dropin-strict-modemmanager: - sudo rm -f /etc/systemd/system/ModemManager.service.d/override.conf - -restart-modemmanager: - sudo systemctl daemon-reload - sudo systemctl restart ModemManager.service diff --git a/udev/ModemManager-override.conf b/udev/ModemManager-override.conf deleted file mode 100644 index 7621100..0000000 --- a/udev/ModemManager-override.conf +++ /dev/null @@ -1,3 +0,0 @@ -[Service] -ExecStart= -ExecStart=/usr/sbin/ModemManager --filter-policy=paranoid From a2a774125fac9f7499c8e4e4c5e305cb3cd15515 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Fri, 22 Mar 2019 21:40:55 +0100 Subject: [PATCH 10/14] Fix usage and display fido2-ext in it --- tools/ctap_test.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/ctap_test.py b/tools/ctap_test.py index 984879a..8697de9 100755 --- a/tools/ctap_test.py +++ b/tools/ctap_test.py @@ -2004,8 +2004,19 @@ def test_find_brute_force(): if __name__ == "__main__": + tests = ( + "solo", + "u2f", + "fido2", + "fido2-ext", + "rk", + "hid", + "ping", + "bootloader", + ) + if len(sys.argv) < 2: - print("Usage: %s [sim] <[u2f]|[fido2]|[rk]|[hid]|[ping]>") + print(f"Usage: {sys.argv[0]} [sim] <{'|'.join(sorted(tests))}>") sys.exit(0) t = Tester() From 9d3144e9b1fdd9a1e51f9b0562adf61f6e4da6e6 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Fri, 22 Mar 2019 21:56:18 +0100 Subject: [PATCH 11/14] oops. black --- tools/ctap_test.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tools/ctap_test.py b/tools/ctap_test.py index 8697de9..f96c0f9 100755 --- a/tools/ctap_test.py +++ b/tools/ctap_test.py @@ -2004,16 +2004,7 @@ def test_find_brute_force(): if __name__ == "__main__": - tests = ( - "solo", - "u2f", - "fido2", - "fido2-ext", - "rk", - "hid", - "ping", - "bootloader", - ) + tests = ("solo", "u2f", "fido2", "fido2-ext", "rk", "hid", "ping", "bootloader") if len(sys.argv) < 2: print(f"Usage: {sys.argv[0]} [sim] <{'|'.join(sorted(tests))}>") From d3b5fb68ee47a76ceb47c5c2b7d8774aa05cb651 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Sat, 23 Mar 2019 13:52:47 +0100 Subject: [PATCH 12/14] Build debug 1/2 versions of hacker firmware and bundle --- in-docker-build.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/in-docker-build.sh b/in-docker-build.sh index e2b9c44..631d359 100755 --- a/in-docker-build.sh +++ b/in-docker-build.sh @@ -35,6 +35,8 @@ function build() { build bootloader nonverifying build bootloader verifying build firmware hacker solo +build firmware hacker-debug-1 solo +build firmware hacker-debug-2 solo build firmware secure solo pip install -U pip @@ -43,3 +45,7 @@ cd ${out_dir} bundle="bundle-hacker-${version}" /opt/conda/bin/solo mergehex bootloader-nonverifying-${version}.hex firmware-hacker-${version}.hex ${bundle}.hex sha256sum ${bundle}.hex > ${bundle}.sha2 +bundle="bundle-hacker-debug-1-${version}" +/opt/conda/bin/solo mergehex bootloader-nonverifying-${version}.hex firmware-hacker-debug-1-${version}.hex ${bundle}.hex +bundle="bundle-hacker-debug-2-${version}" +/opt/conda/bin/solo mergehex bootloader-nonverifying-${version}.hex firmware-hacker-debug-2-${version}.hex ${bundle}.hex From 98a209e330bec962563deb8e1c07ffda23b4ce18 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Sat, 23 Mar 2019 13:54:04 +0100 Subject: [PATCH 13/14] make target to flash firmware via bootloader --- targets/stm32l432/Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/targets/stm32l432/Makefile b/targets/stm32l432/Makefile index 24a57c1..f325b57 100644 --- a/targets/stm32l432/Makefile +++ b/targets/stm32l432/Makefile @@ -93,6 +93,11 @@ flashboot: solo.hex bootloader.hex STM32_Programmer_CLI -c port=SWD -halt -e all --readunprotect STM32_Programmer_CLI -c port=SWD -halt -d bootloader.hex -rst +flash-firmware: + arm-none-eabi-size -A solo.elf + solo program aux enter-bootloader + solo program bootloader solo.hex + # tell ST DFU to enter application detach: STM32_Programmer_CLI -c port=usb1 -ob nBOOT0=1 From 40b9dae38a0b99e84dd47201eacbe1d9f0c90f29 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Tue, 26 Mar 2019 01:55:42 +0100 Subject: [PATCH 14/14] Fix buffer overrun and use correct size for random u32 --- targets/stm32l432/src/rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/stm32l432/src/rng.c b/targets/stm32l432/src/rng.c index 5adb474..86b4aca 100644 --- a/targets/stm32l432/src/rng.c +++ b/targets/stm32l432/src/rng.c @@ -17,7 +17,7 @@ int __errno = 0; void rng_get_bytes(uint8_t * dst, size_t sz) { - uint8_t r[8]; + uint8_t r[4]; unsigned int i,j; for (i = 0; i < sz; i += 4) { @@ -33,7 +33,7 @@ void rng_get_bytes(uint8_t * dst, size_t sz) for (j = 0; j < 4; j++) { - if ((i + j) > sz) + if ((i + j) >= sz) { return; }