From fa93ca4dc0cc3a2951ef9e139db7987b24207079 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 23 Feb 2022 00:03:23 +0100 Subject: [PATCH] link libxiphos and use it for reboot --- bsp_q7s/CMakeLists.txt | 1 - bsp_q7s/core/CoreController.cpp | 52 +++++++++++++++++++++++++------ cmake/Q7SCrossCompileConfig.cmake | 15 +++++++-- 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/bsp_q7s/CMakeLists.txt b/bsp_q7s/CMakeLists.txt index 0a8cffe8..17e4ba2d 100644 --- a/bsp_q7s/CMakeLists.txt +++ b/bsp_q7s/CMakeLists.txt @@ -11,7 +11,6 @@ target_link_libraries(${SIMPLE_OBSW_NAME} PUBLIC target_compile_definitions(${SIMPLE_OBSW_NAME} PRIVATE "Q7S_SIMPLE_MODE") add_subdirectory(simple) - target_sources(${OBSW_NAME} PUBLIC main.cpp ) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index 3d279487..47baa13e 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -16,6 +16,7 @@ #include #include +#include #include @@ -691,7 +692,7 @@ ReturnValue_t CoreController::actionListDirectoryIntoFile(ActionId_t actionId, ReturnValue_t CoreController::initBootCopy() { if (not std::filesystem::exists(CURR_COPY_FILE)) { - // Thils file is created by the systemd service eive-early-config so this should + // This file is created by the systemd service eive-early-config so this should // not happen normally std::string cmd = "xsc_boot_copy > " + std::string(CURR_COPY_FILE); int result = std::system(cmd.c_str()); @@ -773,7 +774,7 @@ ReturnValue_t CoreController::actionPerformReboot(const uint8_t *data, size_t si } return HasActionsIF::EXECUTION_FINISHED; } - if (size < 3) { + if (size < 3 or (data[1] > 1 or data[2] > 1)) { return HasActionsIF::INVALID_PARAMETERS; } #if OBSW_VERBOSE_LEVEL >= 1 @@ -784,21 +785,52 @@ ReturnValue_t CoreController::actionPerformReboot(const uint8_t *data, size_t si // Check that the target chip and copy is writeprotected first generateChipStateFile(); // If any boot copies are unprotected, protect them here + auto tgtChip = static_cast(data[1]); + auto tgtCopy = static_cast(data[2]); + ReturnValue_t retval = setBootCopyProtection( static_cast(data[1]), static_cast(data[2]), true, protOpPerformed, false); if (retval == HasReturnvaluesIF::RETURN_OK and protOpPerformed) { sif::info << "Target slot was writeprotected before reboot" << std::endl; } - // The second byte in data is the target chip, the third byte is the target copy - std::string cmdString = - "xsc_boot_copy " + std::to_string(data[1]) + " " + std::to_string(data[2]); - int result = std::system(cmdString.c_str()); - if (result != 0) { - utility::handleSystemError(result, "CoreController::executeAction"); - return HasReturnvaluesIF::RETURN_FAILED; + switch(tgtChip) { + case(Chip::CHIP_0): { + switch(tgtCopy) { + case(Copy::COPY_0): { + xsc_boot_copy(XSC_LIBNOR_CHIP_0, XSC_LIBNOR_COPY_NOMINAL); + break; + } + case(Copy::COPY_1): { + xsc_boot_copy(XSC_LIBNOR_CHIP_0, XSC_LIBNOR_COPY_GOLD); + break; + } + default: { + break; + } + } + break; } - return HasActionsIF::EXECUTION_FINISHED; + case(Chip::CHIP_1): { + switch(tgtCopy) { + case(Copy::COPY_0): { + xsc_boot_copy(XSC_LIBNOR_CHIP_1, XSC_LIBNOR_COPY_NOMINAL); + break; + } + case(Copy::COPY_1): { + xsc_boot_copy(XSC_LIBNOR_CHIP_1, XSC_LIBNOR_COPY_GOLD); + break; + } + default: { + break; + } + } + break; + } + default: + break; + } + return HasReturnvaluesIF::RETURN_FAILED; } CoreController::~CoreController() {} diff --git a/cmake/Q7SCrossCompileConfig.cmake b/cmake/Q7SCrossCompileConfig.cmake index d4d05f4e..db05c8f0 100644 --- a/cmake/Q7SCrossCompileConfig.cmake +++ b/cmake/Q7SCrossCompileConfig.cmake @@ -81,12 +81,23 @@ set(CMAKE_PREFIX_PATH # "${SYSROOT_PATH}/usr/lib/${CROSS_COMPILE}" ) +set(C_FLAGS + -mcpu=cortex-a9 + -mfpu=neon-vfpv3 + -mfloat-abi=hard + ${COMMON_FLAGS} + -lgpiod + -lxiphos +) + +string (REPLACE ";" " " C_FLAGS "${C_FLAGS}") + set(CMAKE_C_FLAGS - "-mcpu=cortex-a9 -mfpu=neon-vfpv3 -mfloat-abi=hard ${COMMON_FLAGS} -lgpiod" + ${C_FLAGS} CACHE STRING "C flags for Q7S" ) set(CMAKE_CXX_FLAGS - "${CMAKE_C_FLAGS}" + "${CMAKE_C_FLAGS}" CACHE STRING "CPP flags for Q7S" )