Skip to content

Commit

Permalink
Padding safe mode binary to 32KB at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
Novakov committed Nov 17, 2017
1 parent 5632ef0 commit 69ca1b5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions integration_tests/tools/crc.py
Expand Up @@ -55,6 +55,9 @@ def read_content(path):


def pad(content, multiply_of, pad_with):
if len(content) % multiply_of == 0:
return content

pad_length = multiply_of - len(content) % multiply_of

return content + bytearray([pad_with] * pad_length)
Expand Down
2 changes: 1 addition & 1 deletion safe_mode/CMakeLists.txt
Expand Up @@ -38,7 +38,7 @@ target_link_libraries(${NAME}

target_include_directories(${NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/gen)

target_generate_bin(${NAME})
target_generate_padded_bin(${NAME} 32768 0x00)

target_memory_report(${NAME})

Expand Down
14 changes: 14 additions & 0 deletions utils/functions.cmake
Expand Up @@ -26,6 +26,20 @@ function(target_generate_bin TARGET)
add_custom_target (${TARGET}.bin DEPENDS ${BIN_OBJ})
endfunction(target_generate_bin)

function(target_generate_padded_bin TARGET SIZE PADDING)
set (EXEC_OBJ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET})
set (BIN_OBJ ${EXEC_OBJ}.bin)

set_target_properties(${TARGET} PROPERTIES BIN_FILE ${BIN_OBJ})

add_custom_command(OUTPUT ${BIN_OBJ}
COMMAND ${CMAKE_OBJCOPY} -R .boot_params -O binary ${EXEC_OBJ} ${BIN_OBJ}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/integration_tests/tools/pad_file.py ${BIN_OBJ} ${SIZE} ${PADDING}
DEPENDS ${TARGET}
)

add_custom_target (${TARGET}.bin DEPENDS ${BIN_OBJ})
endfunction(target_generate_padded_bin)

function(target_jlink_flash TARGET BASE_ADDRESS)
set(COMMAND_FILE ${CMAKE_BINARY_DIR}/jlink/${TARGET}.flash.jlink)
Expand Down

0 comments on commit 69ca1b5

Please sign in to comment.