Skip to content

Commit

Permalink
Bootloader updater bringup
Browse files Browse the repository at this point in the history
- BMSSW
- BMSB
Added app validation to LIB_app.c/h
Added verbose appDesc DIDread functionality
  • Loading branch information
JoshLafleur committed Nov 29, 2024
1 parent 7e85d8c commit e3d789f
Show file tree
Hide file tree
Showing 30 changed files with 1,025 additions and 156 deletions.
2 changes: 1 addition & 1 deletion components/bms_boss/src/SystemManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern const uint32_t __app_end_addr;
extern const uint32_t __app_crc_addr;

__attribute__((section(".appDescriptor")))
const appDesc_S appDesc = {
const lib_app_appDesc_S appDesc = {
.appStart = (const uint32_t)&__app_start_addr,
.appEnd = (const uint32_t)&__app_end_addr,
// .appCrcLocation = (const uint32_t)&__app_crc_addr,
Expand Down
38 changes: 37 additions & 1 deletion components/bms_boss/src/UDS.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,47 @@ void uds_cb_DIDRead(uint8_t *payload, uint8_t payloadLengthBytes)

switch (did.u16)
{
case 0x00:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&appDesc.appStart, sizeof(appDesc.appStart));
break;
}
case 0x01:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&appDesc.appEnd, sizeof(appDesc.appEnd));
break;
}
case 0x02:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&appDesc.appCrcLocation, sizeof(appDesc.appCrcLocation));
break;
}
case 0x03:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&(*((uint32_t*)appDesc.appCrcLocation)), sizeof(*((uint32_t*)appDesc.appCrcLocation)));
break;
}
case 0x04:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&appDesc.appComponentId, sizeof(appDesc.appComponentId));
break;
}
case 0x05:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&appDesc.appPcbaId, sizeof(appDesc.appPcbaId));
break;
}
case 0x101:
{
// always respond with 0x01 since we're in the app
uint8_t data = 0x01;
uds_sendPositiveResponse(UDS_SID_READ_DID, 0x00, &data, 1);
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, &data, 1);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion components/bms_worker/src/SystemManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern const uint32_t __app_end_addr;
extern const uint32_t __app_crc_addr;

__attribute__((section(".appDescriptor")))
const appDesc_S appDesc = {
const lib_app_appDesc_S appDesc = {
.appStart = (const uint32_t)&__app_start_addr,
.appEnd = (const uint32_t)&__app_end_addr,
// .appCrcLocation = (const uint32_t)&__app_crc_addr,
Expand Down
45 changes: 44 additions & 1 deletion components/bms_worker/src/UDS.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "task.h"
#include "uds.h"
#include "Utility.h"
#include "LIB_app.h"

// system includes
#include <string.h>
Expand Down Expand Up @@ -204,11 +205,53 @@ void uds_cb_DIDRead(uint8_t *payload, uint8_t payloadLengthBytes)

switch (did.u16)
{
case 0x00:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&appDesc.appStart, sizeof(appDesc.appStart));
break;
}
case 0x01:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&appDesc.appEnd, sizeof(appDesc.appEnd));
break;
}
case 0x02:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&appDesc.appCrcLocation, sizeof(appDesc.appCrcLocation));
break;
}
case 0x03:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&(*((uint32_t*)appDesc.appCrcLocation)), sizeof(*((uint32_t*)appDesc.appCrcLocation)));
break;
}
case 0x04:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&appDesc.appComponentId, sizeof(appDesc.appComponentId));
break;
}
case 0x05:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&appDesc.appPcbaId, sizeof(appDesc.appPcbaId));
break;
}
case 0x06:
{
extern const lib_app_appDesc_S appDesc;
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, (uint8_t*)&appDesc.appNodeId, sizeof(appDesc.appNodeId));
break;
}
case 0x101:
{
// always respond with 0x01 since we're in the app
uint8_t data = 0x01;
uds_sendPositiveResponse(UDS_SID_READ_DID, 0x00, &data, 1);
uds_sendPositiveResponse(UDS_SID_READ_DID, UDS_NRC_NONE, &data, 1);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion components/bootloaders/STM/stm32f103/FeatureSels.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
featureDefs: "#/components/bootloaders/STM/stm32f103/FeatureDefs.yaml"
features:
feature_erase_invalid_app: false
feature_can_debug:
feature_can_debug: false
24 changes: 20 additions & 4 deletions components/bootloaders/STM/stm32f103/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ uds_env.Append(
"-Wno-unused-parameter",
"-DBYTE_ORDER=_BYTE_ORDER",
"-DLITTLE_ENDIAN=_LITTLE_ENDIAN",
"-Wno-undef",
]
)

Expand Down Expand Up @@ -181,6 +180,7 @@ 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():
Expand Down Expand Up @@ -222,6 +222,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 +239,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 +264,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);
__appcrc_addr = __BOOT_FLASH_END - 4;
__appdesc_addr = __appcrc_addr - SIZEOF(.appDescriptor);
.appDescriptor __appdesc_addr :
{
__app_desc_addr = .;
. = ALIGN(4);
KEEP(*(.appDescriptor))
} > FLASH
__app_end_addr = __APP_FLASH_ORIGIN - 4;
.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 ( * )
}
}
Loading

0 comments on commit e3d789f

Please sign in to comment.