Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ target_link_libraries(${OUTPUT_NAME} PRIVATE c arith64 freertos_kernel pc xbox t

# Create a binary from the elf
add_custom_command(TARGET ${OUTPUT_NAME} POST_BUILD
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/scripts/calculate_usage.py ${CMAKE_BINARY_DIR}/${OUTPUT_NAME}
COMMAND ${CMAKE_CURRENT_LIST_DIR}/scripts/calculate_usage.py ${CMAKE_BINARY_DIR}/${OUTPUT_NAME}

# Copy the original elf for debugging
COMMAND cp ${CMAKE_BINARY_DIR}/${OUTPUT_NAME} ${CMAKE_BINARY_DIR}/original.elf

COMMAND echo "Compressing ROM..."
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/scripts/compress_rom.py
${CMAKE_BINARY_DIR}/${OUTPUT_NAME} ${CMAKE_BINARY_DIR}/compressed.bin
COMMAND ${CMAKE_CURRENT_LIST_DIR}/scripts/compress_rom.py
${CMAKE_BINARY_DIR}/${OUTPUT_NAME} ${CMAKE_BINARY_DIR}/compressed.bin

# Push the compressed blob back into the elf
COMMAND ${CMAKE_OBJCOPY} --update-section .compressed=${CMAKE_BINARY_DIR}/compressed.bin ${OUTPUT_NAME}
Expand All @@ -91,7 +91,7 @@ add_custom_command(TARGET ${OUTPUT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} --remove-section=.text --remove-section=.data --remove-section=.rodata ${OUTPUT_NAME}

# Calculate the final size ROM usage
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/scripts/calculate_usage.py ${CMAKE_BINARY_DIR}/${OUTPUT_NAME}
COMMAND ${CMAKE_CURRENT_LIST_DIR}/scripts/calculate_usage.py ${CMAKE_BINARY_DIR}/${OUTPUT_NAME}

# Convert the elf to a binary 0x100000000 is 256kB from ROM base which makes 256Kb output size
COMMAND ${CMAKE_OBJCOPY} -O binary --pad-to 0x100000000 --gap-fill 0xFF ${OUTPUT_NAME} ${CMAKE_BINARY_DIR}/rom.bin
Expand Down
2 changes: 2 additions & 0 deletions scripts/calculate_usage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

import argparse
from elftools.elf.elffile import ELFFile

Expand Down
2 changes: 2 additions & 0 deletions scripts/compress_rom.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

from elftools.elf.elffile import ELFFile
import lz4.block
import struct
Expand Down