kopia lustrzana https://github.com/piotr022/UV_K5_playground
replacing-second-vector-table
rodzic
1762929fb0
commit
d20e89afea
|
@ -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")
|
||||
|
|
|
@ -6,14 +6,14 @@ Hardware::THardware Hw;
|
|||
|
||||
int main()
|
||||
{
|
||||
Hw.Power.EnableDbg();
|
||||
__BKPT();
|
||||
System::JumpToOrginalFw();
|
||||
while(1);
|
||||
Hw.Power.EnableDbg();
|
||||
System::JumpToOrginalFw();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void MultiIrq_Handler(unsigned int u32IrqSource)
|
||||
__attribute__ ((interrupt)) void MultiIrq_Handler(unsigned int u32IrqSource)
|
||||
{
|
||||
while(1);
|
||||
Hw.Power.EnableDbg();
|
||||
}
|
|
@ -6,11 +6,17 @@ 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);
|
||||
|
@ -18,10 +24,10 @@ SECTIONS
|
|||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.org_fw :
|
||||
.org_fw_part1 :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.org_fw))
|
||||
KEEP(*(.org_fw_part1))
|
||||
} > FLASH
|
||||
|
||||
.org_vectors :
|
||||
|
|
|
@ -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)
|
||||
|
@ -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}
|
||||
)
|
|
@ -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(self.vector_table_size, 0)
|
||||
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_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])
|
|
@ -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])
|
||||
|
@ -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>,
|
||||
|
|
Ładowanie…
Reference in New Issue