Skip to content

Commit

Permalink
Bootloader APP Feature bringup
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLafleur committed Oct 27, 2024
1 parent 350537d commit fce8290
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 48 deletions.
5 changes: 5 additions & 0 deletions components/bootloaders/STM/stm32f103/FeatureDefs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
config:
prefix: feature
description: Feature definitions for the Bootloader
defs:
can_debug:
2 changes: 2 additions & 0 deletions components/bootloaders/STM/stm32f103/FeatureSels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
featureDefs: "#/components/bootloaders/STM/stm32f103/FeatureDefs.yaml"
features:
40 changes: 28 additions & 12 deletions components/bootloaders/STM/stm32f103/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ SRC_DIR = Dir("src")
LIBS_DIR = Dir("#/embedded/libs")
UDS_DIR = LIBS_DIR.Dir("uds")
ISOTP_DIR = LIBS_DIR.Dir("isotp")
SHARED_CODE = Dir("#/components/shared/code")
SHARED_LIBS = SHARED_CODE.Dir("libs")

ARTIFACT_NAME = "bootloader"
BUILDS_DIR = Dir(f"build")
Expand Down Expand Up @@ -68,6 +70,7 @@ c_flags = [
"-Wreturn-type",
"-Wshadow",
"-Wunused",
"-Wundef",
]

if not GetOption("release"):
Expand All @@ -92,6 +95,7 @@ inc_paths = [
UDS_DIR.Dir("include"),
ISOTP_DIR.Dir("include"),
LIBS_DIR.Dir("libcrc"),
SHARED_LIBS,
]

src_files = [
Expand All @@ -109,6 +113,7 @@ src_files = [
SRC_DIR.File("HW/HW_TIM.c"),
SRC_DIR.File("c_only_startup.S"),
SRC_DIR.File("cortexm3_macro.S"),
SHARED_LIBS.File("LIB_app.c"),
]

uds_srcs = [
Expand All @@ -133,17 +138,19 @@ uds_env.Append(
"-Wno-unused-parameter",
"-DBYTE_ORDER=_BYTE_ORDER",
"-DLITTLE_ENDIAN=_LITTLE_ENDIAN",
"-Wno-undef",
]
)

renderers = [
File("renderers/BuildDefines_generated.h.mako"),
]
renderers = {
"buildDefs": [File("renderers/BuildDefines_generated.h.mako")],
"featureDefs": [File("#/shared/renderers/mako/FeatureDefines_generated.h.mako")],
}


def render_generated_files(options, output_dir):
def render_generated_files(options, renderer, output_dir):
targets = []
for template in renderers:
for template in renderer:
renderer = Template(filename=template.abspath)
rendered = renderer.render(**options)
if not isinstance(rendered, str):
Expand Down Expand Up @@ -177,18 +184,27 @@ binaries = []
asms = []

for config_id, config in configs.items():
config_env = env.Clone()
feature_selections = config_env["FEATURE_SELECTIONS"]
feature_selections += config["features"]["selections"]
feature_selections_files = []
for file in feature_selections:
feature_selections_files += [ File(file) ]

variant_dir = BUILDS_DIR.Dir(
"_".join(config["description"].split(" ")) + f"_{config_id}"
)
generated_dir = variant_dir.Dir("generated")
makedirs(generated_dir.abspath, exist_ok=True)

generated = render_generated_files(config["options"], generated_dir)
features = {"features": config_env.GenerateFeatures(feature_selections_files, config["features"]["overrides"]) }
generated_features = render_generated_files(features, renderers["featureDefs"], generated_dir)
generated = render_generated_files(config["options"], renderers["buildDefs"], generated_dir)

objs = []
objs.extend(
[
env.Object(
config_env.Object(
target=make_build_target(variant_dir, src, ".obj"),
source=src,
CPPPATH=inc_paths + [generated_dir],
Expand All @@ -208,7 +224,7 @@ for config_id, config in configs.items():
)

# link all the compiled objects into an elf
elf, map = env.Program(
elf, map = config_env.Program(
variant_dir.File(ARTIFACT_NAME + ".elf"),
objs,
MAPFILE=variant_dir.File(ARTIFACT_NAME + ".map"),
Expand All @@ -218,18 +234,18 @@ for config_id, config in configs.items():
Clean(elf, generated)

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

# asms target generates disassembled binaries
asms.append(env.Asm(source=objs + [elf]))
asms.append(config_env.Asm(source=objs + [elf]))

# build compilation database
compile_db = env.CompilationDatabase(variant_dir.File("compile_commands.json"))
compile_db = config_env.CompilationDatabase(variant_dir.File("compile_commands.json"))
Depends(compile_db, objs)
# always generate compilation database
Default(compile_db)
# use compiledb alias to _only_ build the compiledb
env.Alias("compiledb", compile_db)
config_env.Alias("compiledb", compile_db)


Default(binaries)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* BuildDefines.h
*
*/

#pragma once

#include "FeatureDefines_generated.h"
#include "BuildDefines_generated.h"
9 changes: 1 addition & 8 deletions components/bootloaders/STM/stm32f103/include/HW/HW_SYS.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,12 @@

#include "Types.h"

#include "LIB_app.h"

/******************************************************************************
* T Y P E D E F S
******************************************************************************/

typedef struct
{
uint32_t appStart;
uint32_t appEnd;
uint32_t appCrcLocation;
} appDesc_S;


typedef enum
{
RESET_TYPE_NONE = 0U,
Expand Down
10 changes: 5 additions & 5 deletions components/bootloaders/STM/stm32f103/include/HW/HW_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* I N C L U D E S
******************************************************************************/

#include "BuildDefines_generated.h"
#include "BuildDefines.h"
#include "Types.h"


Expand All @@ -21,7 +21,7 @@

#define HSE_STARTUP_TIMEOUT 0x0500UL // Time out for HSE start up

#if PCB_ID == 0
#if APP_PCBA_ID == 0

# define CAN_AFIO_REMAP true
# define CAN_RX_PORT GPIOB
Expand All @@ -30,7 +30,7 @@
# define CAN_TX_PORT GPIOB
# define CAN_TX_PIN 9U

#elif PCB_ID == 10
#elif APP_PCBA_ID == 10

# define CAN_AFIO_REMAP false
# define CAN_RX_PORT GPIOA
Expand All @@ -48,9 +48,9 @@
#define LED_PORT GPIOC
#define LED_PIN 13U
#define LED_ON_STATE 0U // this can probably be refactored
#if PCB_ID == 0
#if APP_PCBA_ID == 0
# define LED_MODE GPIO_CFG_OUTPUT_OPEN_DRAIN
#elif PCB_ID == 10
#elif APP_PCBA_ID == 10
# define LED_MODE GPIO_CFG_OUTPUT_PUSH_PULL
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#pragma once

#define PCB_ID ${pcbId}
#define UDS_REQUEST_ID ${udsRequestId}
#define UDS_RESPONSE_ID ${udsResponseId}
%if nodeId is not UNDEFINED:
#define NODE_ID ${nodeId}U
%endif
#define UDS_REQUEST_ID ${udsRequestId}U
#define UDS_RESPONSE_ID ${udsResponseId}U
21 changes: 17 additions & 4 deletions components/bootloaders/STM/stm32f103/src/HW/HW_SYS.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
#include "UDS.h"
#include "Utilities.h"

#include "BuildDefines.h"

__attribute__((section(".appDescriptor")))
const appDesc_S hwDesc = {
.appStart = (const uint32_t)&__app_start_addr,
.appEnd = (const uint32_t)&__app_end_addr,
.appCrcLocation = (const uint32_t)&__app_end_addr,
.appComponentId = APP_COMPONENT_ID,
.appPcbaId = APP_PCBA_ID,
#if FEATURE_IS_ENABLED(APP_NODE_ID)
.appNodeId = APP_NODE_ID,
#endif // APP_NODE_ID
};

/******************************************************************************
* P R I V A T E F U N C T I O N S
Expand Down Expand Up @@ -59,21 +72,21 @@ void bootApp(uint32_t appAddr)
static bool checkAppDescValid(appDesc_S *appDesc)
{
// TODO: clean this up
uint8_t valid = 0b111;
uint8_t valid = 0b11111;

if (appDesc->appStart < APP_FLASH_START)
{
valid &= 0b110;
valid &= 0b11110;
}

if (appDesc->appEnd >= APP_FLASH_END)
{
valid &= 0b101;
valid &= 0b11101;
}

if ((appDesc->appCrcLocation & 0x0FF00000) != 0x08000000)
{
valid &= 0b011;
valid &= 0b11011;
}

CAN_TxMessage_S msg = {
Expand Down
3 changes: 3 additions & 0 deletions components/bootloaders/STM/stm32f103/src/UDS.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
// system includes
#include <string.h>

#ifndef ISO_TP_USER_DEBUG_ENABLED
#define ISO_TP_USER_DEBUG_ENABLED 0U
#endif

/******************************************************************************
* E X T E R N S
Expand Down
2 changes: 1 addition & 1 deletion components/bootloaders/STM/stm32f103/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

#include <string.h> // memset

#include "LIB_app.h"

/******************************************************************************
* P R I V A T E V A R S
******************************************************************************/

appDesc_S *appDesc;


/******************************************************************************
* P R I V A T E F U N C T I O N S
******************************************************************************/
Expand Down
Loading

0 comments on commit fce8290

Please sign in to comment.