Skip to content

Commit

Permalink
replacing-second-vector-table
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr022 committed Jun 25, 2023
1 parent 1762929 commit d20e89a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)

set(OPTI_FLAG g)
set(OPTI_FLAG s)
set(CMAKE_BUILD_TYPE Debug)

set(STM32_DEFINES "-DSTM32F0 -DSTM32F030x8 -DSTM32")
Expand Down
8 changes: 4 additions & 4 deletions src/par_runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Hardware::THardware Hw;

int main()
{
while(1);
Hw.Power.EnableDbg();
__BKPT();
System::JumpToOrginalFw();
while(1);
return 0;
}
}

void MultiIrq_Handler(unsigned int u32IrqSource)
__attribute__ ((interrupt)) void MultiIrq_Handler(unsigned int u32IrqSource)
{
while(1);
Hw.Power.EnableDbg();
}
12 changes: 9 additions & 3 deletions src/par_runner/memory.ld
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@ MEMORY
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 64K
}

_estack = 0x20001000;
_estack = 0x20001388;

SECTIONS
{
. = 0x0;
.org_fw_part0 :
{
. = ALIGN(4);
KEEP(*(.org_fw_part0))
} > FLASH

.isr_vectors :
{
. = ALIGN(4);
KEEP(*(.isr_vectors))
. = ALIGN(4);
} >FLASH

.org_fw :
.org_fw_part1 :
{
. = ALIGN(4);
KEEP(*(.org_fw))
KEEP(*(.org_fw_part1))
} > FLASH

.org_vectors :
Expand Down
26 changes: 16 additions & 10 deletions src/par_runner/orginal_fw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@ set(ORGINAL_FW_BIN orginal_fw.bin)
set(ORGINAL_FW_VECTORS_BIN org_vectors.bin)
set(ORGINAL_FW_VECTORS_OBJ org_vectors.o)

set(ORGINAL_FW_REST_BIN org_rest.bin)
set(ORGINAL_FW_REST_OBJ org_rest.o)
set(ORGINAL_FW_REST0_BIN org_rest0.bin)
set(ORGINAL_FW_REST0_OBJ org_rest0.o)

add_custom_command(OUTPUT ${ORGINAL_FW_VECTORS_BIN} ${ORGINAL_FW_REST_BIN}
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/fw_decomposer.py 48 ${CMAKE_CURRENT_SOURCE_DIR}/${ORGINAL_FW_BIN} ${ORGINAL_FW_VECTORS_BIN} ${ORGINAL_FW_REST_BIN}
set(ORGINAL_FW_REST1_BIN org_rest1.bin)
set(ORGINAL_FW_REST1_OBJ org_rest1.o)

add_custom_command(OUTPUT ${ORGINAL_FW_VECTORS_BIN} ${ORGINAL_FW_REST0_BIN} ${ORGINAL_FW_REST1_BIN}
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/fw_decomposer.py 48 4096 ${CMAKE_CURRENT_SOURCE_DIR}/${ORGINAL_FW_BIN} ${ORGINAL_FW_VECTORS_BIN} ${ORGINAL_FW_REST0_BIN} ${ORGINAL_FW_REST1_BIN}
DEPENDS ${ORGINAL_FW_BIN}
COMMENT "parsing orginal fw ${ORGINAL_FW_BIN}"
)

add_custom_command(OUTPUT ${ORGINAL_FW_VECTORS_OBJ} ${ORGINAL_FW_REST_OBJ}
add_custom_command(OUTPUT ${ORGINAL_FW_VECTORS_OBJ} ${ORGINAL_FW_REST0_OBJ} ${ORGINAL_FW_REST1_OBJ}
COMMAND arm-none-eabi-objcopy -I binary -O elf32-littlearm -B arm --rename-section .data=.org_vectors ${ORGINAL_FW_VECTORS_BIN} ${ORGINAL_FW_VECTORS_OBJ}
COMMAND arm-none-eabi-objcopy -I binary -O elf32-littlearm -B arm --rename-section .data=.org_fw ${ORGINAL_FW_REST_BIN} ${ORGINAL_FW_REST_OBJ}
DEPENDS ${ORGINAL_FW_VECTORS_BIN} ${ORGINAL_FW_REST_BIN}
COMMAND arm-none-eabi-objcopy -I binary -O elf32-littlearm -B arm --rename-section .data=.org_fw_part0 ${ORGINAL_FW_REST0_BIN} ${ORGINAL_FW_REST0_OBJ}
COMMAND arm-none-eabi-objcopy -I binary -O elf32-littlearm -B arm --rename-section .data=.org_fw_part1 ${ORGINAL_FW_REST1_BIN} ${ORGINAL_FW_REST1_OBJ}
DEPENDS ${ORGINAL_FW_VECTORS_BIN} ${ORGINAL_FW_REST0_BIN} ${ORGINAL_FW_REST1_BIN}
COMMENT "generating vector table and fw object files"
)

add_custom_target(generate_obj_files
DEPENDS ${ORGINAL_FW_VECTORS_OBJ} ${ORGINAL_FW_REST_OBJ}
DEPENDS ${ORGINAL_FW_VECTORS_OBJ} ${ORGINAL_FW_REST0_OBJ} ${ORGINAL_FW_REST1_OBJ}
)

add_library(${LIB_NAME} OBJECT)
Expand All @@ -31,10 +35,12 @@ add_dependencies(${LIB_NAME} generate_obj_files)

target_sources(${LIB_NAME} PRIVATE
${ORGINAL_FW_VECTORS_OBJ}
${ORGINAL_FW_REST_OBJ}
${ORGINAL_FW_REST0_OBJ}
${ORGINAL_FW_REST1_OBJ}
)

target_link_libraries(${LIB_NAME}
${CMAKE_CURRENT_BINARY_DIR}/${ORGINAL_FW_VECTORS_OBJ}
${CMAKE_CURRENT_BINARY_DIR}/${ORGINAL_FW_REST_OBJ}
${CMAKE_CURRENT_BINARY_DIR}/${ORGINAL_FW_REST0_OBJ}
${CMAKE_CURRENT_BINARY_DIR}/${ORGINAL_FW_REST1_OBJ}
)
22 changes: 15 additions & 7 deletions src/par_runner/orginal_fw/fw_decomposer.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import sys
class FwDecompozer:
def __init__(self, vector_table_size, file):
def __init__(self, vector_table_size, vector_table_address, file):
self.vector_table_size = vector_table_size * 4
self.vector_table_address = vector_table_address
self.file = open(file, 'rb')

def save_vector_table(self, filename):
output = open(filename, 'wb')
self.file.seek(0)
self.file.seek(self.vector_table_address, 0)
output.write(self.file.read(self.vector_table_size))
output.close()

def save_stripped_fw(self, filename):
def save_part1(self, filename):
output = open(filename, 'wb')
self.file.seek(0)
output.write(self.file.read(self.vector_table_address))
output.close()

def save_part2(self, filename):
output = open(filename, 'wb')
self.file.seek(self.vector_table_size, 0)
self.file.seek(self.vector_table_address + self.vector_table_size, 0)
output.write(self.file.read())
output.close()

if __name__ == '__main__':
args = sys.argv
fw = FwDecompozer(int(args[1]), args[2])
fw.save_vector_table(args[3])
fw.save_stripped_fw(args[4])
fw = FwDecompozer(int(args[1]), int(args[2]), args[3])
fw.save_vector_table(args[4])
fw.save_part1(args[5])
fw.save_part2(args[6])
6 changes: 3 additions & 3 deletions src/par_runner/system/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ extern "C" void Reset_Handler();
extern "C" unsigned int _estack;

extern "C" const unsigned int __org_vectors_start;
static const auto* pOrgVectors = (const TVectorTable*)&__org_vectors_start;
volatile static const auto* pOrgVectors = (const TVectorTable*)&__org_vectors_start;

extern void MultiIrq_Handler(unsigned int);

template <int VectorNr>
static void CommonIrqWrapper()
__attribute__ ((interrupt)) static void CommonIrqWrapper()
{
MultiIrq_Handler(VectorNr);
if (pOrgVectors->Vectors[VectorNr])
Expand All @@ -27,7 +27,7 @@ void System::JumpToOrginalFw()
TVectorTable __attribute__ ((section(".isr_vectors"))) VectorTable =
{
(VoidFxPointer)&_estack,
&Reset_Handler,
(VoidFxPointer)0xD5,//&Reset_Handler,
&CommonIrqWrapper<2>,
&CommonIrqWrapper<3>,
&CommonIrqWrapper<4>,
Expand Down

0 comments on commit d20e89a

Please sign in to comment.