Add full automotive RTOS project

Add kernel (Cortex-M0/M3/M4, Tricore, S32K, RISC-V ports), drivers,
middleware (CAN stack, diagnostics, safety), applications, board
support, build/test tooling, and documentation.
This commit is contained in:
root
2026-08-23 03:35:29 -04:00
parent f113bf0a05
commit ca13734bf0
151 changed files with 23945 additions and 0 deletions
+212
View File
@@ -0,0 +1,212 @@
#!/bin/bash
/**
* @file build_all.sh
* @brief Build all targets for Automotive RTOS
*/
set -e # Exit on error
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Build configuration
BUILD_DIR="${PROJECT_ROOT}/build"
LOG_DIR="${BUILD_DIR}/logs"
TARGETS=("stm32f407_discovery" "nxp_s32k144_evb" "custom_ecu")
BUILD_TYPES=("debug" "release")
# Create directories
mkdir -p "${BUILD_DIR}"
mkdir -p "${LOG_DIR}"
# Print banner
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Automotive RTOS Build System${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
# Function to build target
build_target() {
local target=$1
local build_type=$2
echo -e "${YELLOW}Building ${target} (${build_type})...${NC}"
local build_dir="${BUILD_DIR}/${target}/${build_type}"
mkdir -p "${build_dir}"
# Change to build directory
cd "${build_dir}"
# Run CMake
cmake "${PROJECT_ROOT}" \
-DTARGET_BOARD=${target} \
-DCMAKE_BUILD_TYPE=${build_type} \
-DCMAKE_TOOLCHAIN_FILE="${PROJECT_ROOT}/cmake/toolchain-${target}.cmake" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
2>&1 | tee "${LOG_DIR}/${target}_${build_type}_configure.log"
# Build
make -j$(nproc) 2>&1 | tee "${LOG_DIR}/${target}_${build_type}_build.log"
# Check build result
if [ $? -eq 0 ]; then
echo -e "${GREEN}${target} (${build_type}) built successfully${NC}"
else
echo -e "${RED}${target} (${build_type}) build failed${NC}"
return 1
fi
# Generate artifacts
echo -e "${YELLOW}Generating artifacts...${NC}"
# Create hex file
arm-none-eabi-objcopy -O ihex "${build_dir}/automotive_rtos.elf" \
"${build_dir}/automotive_rtos.hex"
# Create binary file
arm-none-eabi-objcopy -O binary "${build_dir}/automotive_rtos.elf" \
"${build_dir}/automotive_rtos.bin"
# Generate size report
arm-none-eabi-size "${build_dir}/automotive_rtos.elf" > \
"${build_dir}/size_report.txt"
# Generate map file
arm-none-eabi-nm -n "${build_dir}/automotive_rtos.elf" > \
"${build_dir}/symbols.txt"
echo -e "${GREEN}✓ Artifacts generated${NC}"
echo ""
return 0
}
# Function to run tests
run_tests() {
echo -e "${YELLOW}Running unit tests...${NC}"
local test_dir="${BUILD_DIR}/tests"
mkdir -p "${test_dir}"
# Run each test
for test_file in "${PROJECT_ROOT}"/tests/unit/test_*.c; do
test_name=$(basename "${test_file}" .c)
echo -e " Testing ${test_name}..."
# Compile test
gcc -I"${PROJECT_ROOT}/kernel/include" \
-I"${PROJECT_ROOT}/tests" \
-I"${PROJECT_ROOT}/third_party/unity" \
"${test_file}" \
"${PROJECT_ROOT}/tests/unity/unity.c" \
-o "${test_dir}/${test_name}" \
-Wall -Wextra -g
# Run test
if "${test_dir}/${test_name}" > "${LOG_DIR}/${test_name}.log" 2>&1; then
echo -e "${GREEN}${test_name} passed${NC}"
else
echo -e "${RED}${test_name} failed${NC}"
cat "${LOG_DIR}/${test_name}.log"
return 1
fi
done
echo -e "${GREEN}✓ All tests passed${NC}"
echo ""
}
# Main build process
main() {
local build_failed=0
# Parse arguments
local clean_build=false
local run_all_tests=false
while [[ $# -gt 0 ]]; do
case $1 in
--clean)
clean_build=true
shift
;;
--test)
run_all_tests=true
shift
;;
--target)
TARGETS=("$2")
shift 2
;;
--type)
BUILD_TYPES=("$2")
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Clean build if requested
if [ "${clean_build}" = true ]; then
echo -e "${YELLOW}Cleaning build directory...${NC}"
rm -rf "${BUILD_DIR}"
mkdir -p "${BUILD_DIR}"
echo -e "${GREEN}✓ Clean complete${NC}"
echo ""
fi
# Build all targets
for target in "${TARGETS[@]}"; do
for build_type in "${BUILD_TYPES[@]}"; do
if ! build_target "${target}" "${build_type}"; then
build_failed=1
fi
done
done
# Run tests if requested
if [ "${run_all_tests}" = true ]; then
if ! run_tests; then
build_failed=1
fi
fi
# Print summary
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Build Summary${NC}"
echo -e "${GREEN}========================================${NC}"
if [ ${build_failed} -eq 0 ]; then
echo -e "${GREEN}✓ All builds successful${NC}"
else
echo -e "${RED}✗ Some builds failed${NC}"
exit 1
fi
# Print size reports
echo ""
echo -e "${YELLOW}Size Reports:${NC}"
for target in "${TARGETS[@]}"; do
for build_type in "${BUILD_TYPES[@]}"; do
size_file="${BUILD_DIR}/${target}/${build_type}/size_report.txt"
if [ -f "${size_file}" ]; then
echo -e " ${target} (${build_type}):"
cat "${size_file}" | tail -n 2
fi
done
done
}
# Run main
main "$@"
+219
View File
@@ -0,0 +1,219 @@
#!/bin/bash
/**
* @file build_target.sh
* @brief Build specific target
*/
set -e
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
# Default values
TARGET=""
BUILD_TYPE="debug"
CLEAN=false
VERBOSE=false
JOBS=$(nproc)
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Function to print usage
print_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -t, --target <target> Target board (required)"
echo " Available: stm32f407_discovery"
echo " nxp_s32k144_evb"
echo " custom_ecu"
echo " -b, --build-type <type> Build type (default: debug)"
echo " Available: debug, release"
echo " -c, --clean Clean build"
echo " -v, --verbose Verbose output"
echo " -j, --jobs <number> Number of parallel jobs"
echo " -h, --help Show this help"
echo ""
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-t|--target)
TARGET="$2"
shift 2
;;
-b|--build-type)
BUILD_TYPE="$2"
shift 2
;;
-c|--clean)
CLEAN=true
shift
;;
-v|--verbose)
VERBOSE=true
shift
;;
-j|--jobs)
JOBS="$2"
shift 2
;;
-h|--help)
print_usage
exit 0
;;
*)
echo "Unknown option: $1"
print_usage
exit 1
;;
esac
done
# Validate target
if [ -z "${TARGET}" ]; then
echo -e "${RED}Error: Target not specified${NC}"
print_usage
exit 1
fi
# Validate build type
case "${BUILD_TYPE}" in
debug|release)
;;
*)
echo -e "${RED}Error: Invalid build type: ${BUILD_TYPE}${NC}"
exit 1
;;
esac
# Build directories
BUILD_DIR="${PROJECT_ROOT}/build/${TARGET}/${BUILD_TYPE}"
LOG_DIR="${PROJECT_ROOT}/build/logs"
# Create directories
mkdir -p "${BUILD_DIR}"
mkdir -p "${LOG_DIR}"
# Print build info
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} Building Automotive RTOS${NC}"
echo -e "${BLUE}========================================${NC}"
echo -e " Target: ${YELLOW}${TARGET}${NC}"
echo -e " Build Type: ${YELLOW}${BUILD_TYPE}${NC}"
echo -e " Jobs: ${YELLOW}${JOBS}${NC}"
echo ""
# Clean if requested
if [ "${CLEAN}" = true ]; then
echo -e "${YELLOW}Cleaning build directory...${NC}"
rm -rf "${BUILD_DIR}"/*
echo -e "${GREEN}✓ Clean complete${NC}"
echo ""
fi
# Configure
echo -e "${YELLOW}Configuring build...${NC}"
# Set CMake arguments
CMAKE_ARGS=(
"${PROJECT_ROOT}"
"-DTARGET_BOARD=${TARGET}"
"-DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
"-DCMAKE_TOOLCHAIN_FILE=${PROJECT_ROOT}/cmake/toolchain-${TARGET}.cmake"
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
)
if [ "${VERBOSE}" = true ]; then
CMAKE_ARGS+=("-DCMAKE_VERBOSE_MAKEFILE=ON")
fi
# Run CMake
cd "${BUILD_DIR}"
cmake "${CMAKE_ARGS[@]}" 2>&1 | tee "${LOG_DIR}/${TARGET}_${BUILD_TYPE}_configure.log"
if [ $? -ne 0 ]; then
echo -e "${RED}✗ Configuration failed${NC}"
exit 1
fi
echo -e "${GREEN}✓ Configuration complete${NC}"
echo ""
# Build
echo -e "${YELLOW}Building...${NC}"
make -j${JOBS} 2>&1 | tee "${LOG_DIR}/${TARGET}_${BUILD_TYPE}_build.log"
if [ $? -ne 0 ]; then
echo -e "${RED}✗ Build failed${NC}"
exit 1
fi
echo -e "${GREEN}✓ Build complete${NC}"
echo ""
# Generate artifacts
echo -e "${YELLOW}Generating artifacts...${NC}"
ELF_FILE="${BUILD_DIR}/automotive_rtos.elf"
HEX_FILE="${BUILD_DIR}/automotive_rtos.hex"
BIN_FILE="${BUILD_DIR}/automotive_rtos.bin"
MAP_FILE="${BUILD_DIR}/automotive_rtos.map"
SIZE_FILE="${BUILD_DIR}/size_report.txt"
# Generate hex file
arm-none-eabi-objcopy -O ihex "${ELF_FILE}" "${HEX_FILE}"
# Generate binary file
arm-none-eabi-objcopy -O binary "${ELF_FILE}" "${BIN_FILE}"
# Generate map file
arm-none-eabi-nm -n "${ELF_FILE}" > "${MAP_FILE}"
# Generate size report
arm-none-eabi-size "${ELF_FILE}" > "${SIZE_FILE}"
echo -e "${GREEN}✓ Artifacts generated:${NC}"
echo -e " ELF: ${BLUE}${ELF_FILE}${NC}"
echo -e " HEX: ${BLUE}${HEX_FILE}${NC}"
echo -e " BIN: ${BLUE}${BIN_FILE}${NC}"
echo -e " MAP: ${BLUE}${MAP_FILE}${NC}"
echo ""
# Print size report
echo -e "${YELLOW}Size Report:${NC}"
cat "${SIZE_FILE}"
echo ""
# Run static analysis if available
if command -v cppcheck >/dev/null 2>&1; then
echo -e "${YELLOW}Running static analysis...${NC}"
cppcheck \
--enable=all \
--inconclusive \
--std=c11 \
--platform=arm32 \
-I"${PROJECT_ROOT}/kernel/include" \
-I"${PROJECT_ROOT}/drivers/include" \
-I"${PROJECT_ROOT}/middleware/include" \
"${PROJECT_ROOT}/kernel/src" \
"${PROJECT_ROOT}/drivers/src" \
"${PROJECT_ROOT}/middleware/src" \
2>&1 | tee "${LOG_DIR}/${TARGET}_${BUILD_TYPE}_cppcheck.log"
echo -e "${GREEN}✓ Static analysis complete${NC}"
echo ""
fi
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Build Successful${NC}"
echo -e "${GREEN}========================================${NC}"
+189
View File
@@ -0,0 +1,189 @@
#!/bin/bash
/**
* @file flash_target.sh
* @brief Flash firmware to target board
*/
set -e
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
# Default values
TARGET=""
BUILD_TYPE="debug"
PROGRAMMER=""
INTERFACE=""
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Function to print usage
print_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -t, --target <target> Target board (required)"
echo " -b, --build-type <type> Build type (default: debug)"
echo " -p, --programmer <prog> Programmer type"
echo " Available: stlink, jlink, openocd"
echo " -i, --interface <iface> Debug interface"
echo " Available: swd, jtag"
echo " -h, --help Show this help"
echo ""
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-t|--target)
TARGET="$2"
shift 2
;;
-b|--build-type)
BUILD_TYPE="$2"
shift 2
;;
-p|--programmer)
PROGRAMMER="$2"
shift 2
;;
-i|--interface)
INTERFACE="$2"
shift 2
;;
-h|--help)
print_usage
exit 0
;;
*)
echo "Unknown option: $1"
print_usage
exit 1
;;
esac
done
# Validate target
if [ -z "${TARGET}" ]; then
echo -e "${RED}Error: Target not specified${NC}"
print_usage
exit 1
fi
# Set default programmer based on target
if [ -z "${PROGRAMMER}" ]; then
case "${TARGET}" in
stm32f407_discovery)
PROGRAMMER="stlink"
INTERFACE="swd"
;;
nxp_s32k144_evb)
PROGRAMMER="jlink"
INTERFACE="swd"
;;
custom_ecu)
PROGRAMMER="openocd"
INTERFACE="swd"
;;
esac
fi
# Firmware file
FIRMWARE_FILE="${PROJECT_ROOT}/build/${TARGET}/${BUILD_TYPE}/automotive_rtos.elf"
HEX_FILE="${PROJECT_ROOT}/build/${TARGET}/${BUILD_TYPE}/automotive_rtos.hex"
# Check if firmware exists
if [ ! -f "${FIRMWARE_FILE}" ]; then
echo -e "${RED}Error: Firmware not found: ${FIRMWARE_FILE}${NC}"
echo -e "${YELLOW}Run build_target.sh first${NC}"
exit 1
fi
# Print flash info
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} Flashing Firmware${NC}"
echo -e "${BLUE}========================================${NC}"
echo -e " Target: ${YELLOW}${TARGET}${NC}"
echo -e " Programmer: ${YELLOW}${PROGRAMMER}${NC}"
echo -e " Interface: ${YELLOW}${INTERFACE}${NC}"
echo -e " Firmware: ${YELLOW}${FIRMWARE_FILE}${NC}"
echo ""
# Flash based on programmer
case "${PROGRAMMER}" in
stlink)
echo -e "${YELLOW}Flashing with ST-Link...${NC}"
st-flash --reset write "${HEX_FILE}" 0x08000000
;;
jlink)
echo -e "${YELLOW}Flashing with J-Link...${NC}"
# Create J-Link script
JLINK_SCRIPT="${PROJECT_ROOT}/build/flash.jlink"
cat > "${JLINK_SCRIPT}" << EOF
device ${TARGET}
si ${INTERFACE}
speed 4000
loadfile ${HEX_FILE}
r
g
q
EOF
JLinkExe -CommanderScript "${JLINK_SCRIPT}"
;;
openocd)
echo -e "${YELLOW}Flashing with OpenOCD...${NC}"
# OpenOCD configuration
case "${TARGET}" in
stm32f407_discovery)
OOCD_CFG="board/stm32f4discovery.cfg"
;;
*)
OOCD_CFG="board/${TARGET}.cfg"
;;
esac
openocd \
-f "interface/${INTERFACE}.cfg" \
-f "${OOCD_CFG}" \
-c "program ${FIRMWARE_FILE} verify reset exit"
;;
*)
echo -e "${RED}Error: Unknown programmer: ${PROGRAMMER}${NC}"
exit 1
;;
esac
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Flash successful${NC}"
else
echo -e "${RED}✗ Flash failed${NC}"
exit 1
fi
# Verify flash
echo -e "${YELLOW}Verifying flash...${NC}"
case "${PROGRAMMER}" in
stlink)
st-flash verify "${HEX_FILE}"
;;
*)
echo -e "${YELLOW}Verification not supported for ${PROGRAMMER}${NC}"
;;
esac
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Flash Complete${NC}"
echo -e "${GREEN}========================================${NC}"