Skip to content

Commit

Permalink
Bootloader updater bringup BMSW0
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLafleur committed Oct 21, 2024
1 parent 77d938c commit c1151ac
Show file tree
Hide file tree
Showing 15 changed files with 460 additions and 41 deletions.
5 changes: 2 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ if platform:
PlatformEnv["PLATFORM_ARTIFACTS"] = GlobalEnv["REPO_ROOT_DIR"].Dir(f"platform-artifacts/{platform.upper()}")
PlatformEnv["FEATURE_SELECTIONS"] = platforms["configs"][platform]["options"]["feature-selections"]
if targets:
targets = targets.split('+')
for target in targets:
target_dict[target] = []
# TODO: Handle
pass
else:
for part in platforms["configs"][platform]["ecu"]:
target_dict[part] = platforms["configs"][platform]["ecu"][part]
Expand Down
25 changes: 21 additions & 4 deletions components/bootloaders/STM/stm32f103/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ def make_build_target(variant_dir, file, ext):
configs = env.GenerateVariants(File("variants.yaml"), CONFIG_IDS)
elfs = []
binaries = []
binaries_crced = []
asms = []

for config_id, config in configs.items():
config_env = env.Clone()
feature_selections = config_env["FEATURE_SELECTIONS"]
feature_selections = []
feature_selections += config["features"]["selections"]
feature_selections_files = []
for file in feature_selections:
Expand Down Expand Up @@ -222,6 +223,15 @@ for config_id, config in configs.items():
for src in uds_srcs
]
)
if features["features"]["defs"]["app_function_id"] == "function_id_blu":
config_env["LINKSCRIPT"]=File("STM32F103C8-BLU.ld")
elif features["features"]["defs"]["app_function_id"] == "function_id_bl":
try:
AddOption("--flashable-bootloader", dest="flashable-bootloader", action="store_true")
except Exception:
pass
if GetOption("flashable-bootloader"):
config_env["LINKSCRIPT"]=File("STM32F103C8-BLFLASHABLE.ld")

# link all the compiled objects into an elf
elf, map = config_env.Program(
Expand All @@ -230,11 +240,18 @@ for config_id, config in configs.items():
MAPFILE=variant_dir.File(ARTIFACT_NAME + ".map"),
)
elfs.append(elf)
Depends(elf, env["LINKSCRIPT"])
Depends(elf, config_env["LINKSCRIPT"])
Clean(elf, generated)

# generate a binary
binaries.append(config_env.Bin(source=elf))
binary = config_env.Bin(source=elf)
binaries.append(binary)

crc_env = config_env.Clone(tools=["hextools"])
# generate the CRCd binary
crc_binary = crc_env.InjectMpeg2CRC(source=binary, start_addr=features["features"]["defs"]["app_start_addr"])
binaries_crced.append(crc_binary)
Depends(crc_binary, binary)

# asms target generates disassembled binaries
asms.append(config_env.Asm(source=objs + [elf]))
Expand All @@ -248,7 +265,7 @@ for config_id, config in configs.items():
config_env.Alias("compiledb", compile_db)


Default(binaries)
Default(binaries_crced)
Alias("asms", asms)

# Return artifacts to the caller
Expand Down
163 changes: 163 additions & 0 deletions components/bootloaders/STM/stm32f103/STM32F103C8-BLFLASHABLE.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/**
* STM32F103C8.ld
* Linker script for STM32F103C8
*/

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* bottom of stack (grows down) */

__STACK_SIZE = 0x400;
__HEAP_SIZE = 0x200;

__RAM_SIZE = 20K;
__FLASH_SIZE = 64K;
__BOOT_FLASH_SIZE = 8K;

__RAM_ORIGIN = 0x20000000; /* don't change */
__FLASH_ORIGIN = 0x8000000; /* don't change */
__APP_FLASH_ORIGIN = __FLASH_ORIGIN + __BOOT_FLASH_SIZE;
__FLASH_END = __FLASH_ORIGIN + __FLASH_SIZE;
__BOOT_FLASH_END = __FLASH_ORIGIN + __BOOT_FLASH_SIZE;


/* Memory definition */
MEMORY
{
RAM (rwx) : ORIGIN = __RAM_ORIGIN, LENGTH = __RAM_SIZE
FLASH (rx) : ORIGIN = __FLASH_ORIGIN, LENGTH = __BOOT_FLASH_SIZE
}

SECTIONS
{
.isr_vector : ALIGN(0x100)
{
__app_start_addr = .;
KEEP(*(.isr_vector)) /* interrupt vector table */
} > FLASH

/* The program code and other data into "FLASH" Rom type memory */
.text :
{
. = ALIGN(4);
*(.text .text.* .gnu.linkonce.t.*) /* .text sections (code) */
*(.rodata .rodata.* .gnu.linkonce.r.*) /* .rodata sections (constants, strings, etc.) */
*(.eh_frame) /* https://stackoverflow.com/questions/26300819/why-gcc-compiled-c-program-needs-eh-frame-section */

. = ALIGN(4);
KEEP (*(.init))

. = ALIGN(4);
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

. = ALIGN(4);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(.init_array))
KEEP (*(SORT(.init_array.*)))
PROVIDE_HIDDEN (__init_array_end = .);

. = ALIGN(4);
KEEP (*(.fini))

. = ALIGN(4);
_etext = .; /* address of end of text section */
} > FLASH

.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH

.ARM.exidx :
{
PROVIDE (__exidx_start = .);
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
PROVIDE (__exidx_end = .);
} > FLASH

/* .ARM.attributes 0 : */
/* { */
/* *(.ARM.attributes) */
/* } */

/* Initialized data sections into "RAM" Ram type memory */
.relocate :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at start of section */
*(.data .data.*) /* .data sections */
*(.ramfunc .ramfunc.*) /* .ramfunc sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at end of section */

} > RAM AT> FLASH
/* Used by the startup to initialize data */
_sidata = LOADADDR(.relocate);
__app_end_addr = LOADADDR(.relocate) + SIZEOF(.relocate);
__appcrc_addr = __BOOT_FLASH_END - 4;
__appdesc_addr = __appcrc_addr - SIZEOF(.appDescriptor);
.appDescriptor __appdesc_addr :
{
__app_desc_addr = .;
. = ALIGN(4);
KEEP(*(.appDescriptor))
} > FLASH
.crc __appcrc_addr :
{
__app_crc_addr = .;
KEEP(*(.appCrc))
} > FLASH


/* Uninitialized data section into "RAM" Ram type memory */
.bss(NOLOAD) :
{
/* This is used by the startup in order to initialize the .bss section */
. = ALIGN(4);
_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

/* Heap and Stack definitions, if needed */
.heap (COPY) :
{
. = ALIGN(8);
__HeapLimit = .;
. = . + __HEAP_SIZE;
. = ALIGN(8);
__HeapTop = .;
PROVIDE(end = .);
} > RAM

.stack (ORIGIN(RAM) + LENGTH(RAM) - __STACK_SIZE) (COPY) :
{
. = ALIGN(8);
__StackLimit = .;
. = . + __STACK_SIZE;
. = ALIGN(8);
__StackTop = .;
_estack = .;
PROVIDE(__stack = __StackTop);
} > RAM

ASSERT(__HeapTop < __StackLimit, "RAM overflowed stack")

/* Remove information from the compiler libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
libc_nano.a ( * )
libg_nano.a ( * )
}
}
162 changes: 162 additions & 0 deletions components/bootloaders/STM/stm32f103/STM32F103C8-BLU.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/**
* STM32F103C8.ld
* Linker script for STM32F103C8
*/

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* bottom of stack (grows down) */

__STACK_SIZE = 0x400;
__HEAP_SIZE = 0x200;

__RAM_SIZE = 20K;
__FLASH_SIZE = 64K;
__BOOT_FLASH_SIZE = 8K;
__APP_FLASH_SIZE = __FLASH_SIZE - __BOOT_FLASH_SIZE;

__RAM_ORIGIN = 0x20000000; /* don't change */
__FLASH_ORIGIN = 0x8000000; /* don't change */
__APP_FLASH_ORIGIN = __FLASH_ORIGIN + __BOOT_FLASH_SIZE;
__FLASH_END = __FLASH_ORIGIN + __FLASH_SIZE;
__BOOT_FLASH_END = __FLASH_ORIGIN + __BOOT_FLASH_SIZE;


/* Memory definition */
MEMORY
{
RAM (rwx) : ORIGIN = __RAM_ORIGIN, LENGTH = __RAM_SIZE
FLASH (rx) : ORIGIN = __APP_FLASH_ORIGIN, LENGTH = __APP_FLASH_SIZE
}

SECTIONS
{
.appDescriptor :
{
. = ALIGN(4);
KEEP(*(.appDescriptor))
} > FLASH
.isr_vector : ALIGN(0x100)
{
__app_start_addr = .;
KEEP(*(.isr_vector)) /* interrupt vector table */
} > FLASH

/* The program code and other data into "FLASH" Rom type memory */
.text :
{
. = ALIGN(4);
*(.text .text.* .gnu.linkonce.t.*) /* .text sections (code) */
*(.rodata .rodata.* .gnu.linkonce.r.*) /* .rodata sections (constants, strings, etc.) */
*(.eh_frame) /* https://stackoverflow.com/questions/26300819/why-gcc-compiled-c-program-needs-eh-frame-section */

. = ALIGN(4);
KEEP (*(.init))

. = ALIGN(4);
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

. = ALIGN(4);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(.init_array))
KEEP (*(SORT(.init_array.*)))
PROVIDE_HIDDEN (__init_array_end = .);

. = ALIGN(4);
KEEP (*(.fini))

. = ALIGN(4);
_etext = .; /* address of end of text section */
} > FLASH

.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH

.ARM.exidx :
{
PROVIDE (__exidx_start = .);
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
PROVIDE (__exidx_end = .);
} > FLASH

/* .ARM.attributes 0 : */
/* { */
/* *(.ARM.attributes) */
/* } */

/* Initialized data sections into "RAM" Ram type memory */
.relocate :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at start of section */
*(.data .data.*) /* .data sections */
*(.ramfunc .ramfunc.*) /* .ramfunc sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at end of section */

} > RAM AT> FLASH
__app_end_addr = LOADADDR(.relocate) + SIZEOF(.relocate);
.crc __app_end_addr :
{
__app_crc_addr = .;
KEEP(*(.appCrc))
} > FLASH

/* Used by the startup to initialize data */
_sidata = LOADADDR(.relocate);


/* Uninitialized data section into "RAM" Ram type memory */
.bss(NOLOAD) :
{
/* This is used by the startup in order to initialize the .bss section */
. = ALIGN(4);
_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

/* Heap and Stack definitions, if needed */
.heap (COPY) :
{
. = ALIGN(8);
__HeapLimit = .;
. = . + __HEAP_SIZE;
. = ALIGN(8);
__HeapTop = .;
PROVIDE(end = .);
} > RAM

.stack (ORIGIN(RAM) + LENGTH(RAM) - __STACK_SIZE) (COPY) :
{
. = ALIGN(8);
__StackLimit = .;
. = . + __STACK_SIZE;
. = ALIGN(8);
__StackTop = .;
_estack = .;
PROVIDE(__stack = __StackTop);
} > RAM

ASSERT(__HeapTop < __StackLimit, "RAM overflowed stack")

/* Remove information from the compiler libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
libc_nano.a ( * )
libg_nano.a ( * )
}
}
Loading

0 comments on commit c1151ac

Please sign in to comment.