Add mksunxi tool to make flashable image
This commit is contained in:
parent
96979a2c4a
commit
75f7fb3d9d
|
@ -182,10 +182,12 @@ flash-jlink: $(BUILD)/$(PROJECT).hex
|
||||||
flash-stlink: $(BUILD)/$(PROJECT).elf
|
flash-stlink: $(BUILD)/$(PROJECT).elf
|
||||||
STM32_Programmer_CLI --connect port=swd --write $< --go
|
STM32_Programmer_CLI --connect port=swd --write $< --go
|
||||||
|
|
||||||
flash-xfel: $(BUILD)/$(PROJECT).bin
|
$(BUILD)/$(PROJECT)-sunxi.bin: $(BUILD)/$(PROJECT).bin
|
||||||
xfel ddr
|
$(PYTHON) $(TOP)/tools/mksunxi.py $< $@
|
||||||
xfel write 0x80000000 $<
|
|
||||||
xfel exec 0x80000000
|
flash-xfel: $(BUILD)/$(PROJECT)-sunxi.bin
|
||||||
|
xfel spinor write 0 $<
|
||||||
|
xfel reset
|
||||||
|
|
||||||
# Flash using pyocd
|
# Flash using pyocd
|
||||||
PYOCD_OPTION ?=
|
PYOCD_OPTION ?=
|
||||||
|
|
|
@ -41,5 +41,10 @@ INC += \
|
||||||
$(TOP)/$(MCU_DIR)/include \
|
$(TOP)/$(MCU_DIR)/include \
|
||||||
$(TOP)/$(BOARD_PATH)
|
$(TOP)/$(BOARD_PATH)
|
||||||
|
|
||||||
# flash target using on-board stlink
|
# flash target using xfel
|
||||||
flash: flash-xfel
|
flash: flash-xfel
|
||||||
|
|
||||||
|
exec: $(BUILD)/$(PROJECT).bin
|
||||||
|
xfel ddr
|
||||||
|
xfel write 0x80000000 $<
|
||||||
|
xfel exec 0x80000000
|
|
@ -21,15 +21,15 @@ SECTIONS
|
||||||
PROVIDE(__bootloader_start = .);
|
PROVIDE(__bootloader_start = .);
|
||||||
PROVIDE(__image_start = .);
|
PROVIDE(__image_start = .);
|
||||||
PROVIDE(__text_start = .);
|
PROVIDE(__text_start = .);
|
||||||
*/machine/start.o (.text)
|
_build/*/obj/hw/mcu/allwinner/*/machine/start_asm.o (.text)
|
||||||
*/lib/memcpy.o (.text)
|
_build/*/obj/hw/mcu/allwinner/*/lib/memcpy_asm.o (.text)
|
||||||
*/lib/memset.o (.text)
|
_build/*/obj/hw/mcu/allwinner/*/lib/memset_asm.o (.text)
|
||||||
*/machine/sys-uart.o (.text)
|
_build/*/obj/hw/mcu/allwinner/*/machine/sys-uart.o (.text*)
|
||||||
*/machine/sys-clock.o (.text)
|
_build/*/obj/hw/mcu/allwinner/*/machine/sys-clock.o (.text*)
|
||||||
*/machine/sys-dram.o (.text)
|
_build/*/obj/hw/mcu/allwinner/*/machine/sys-dram.o (.text*)
|
||||||
*/machine/sys-mmu.o (.text)
|
_build/*/obj/hw/mcu/allwinner/*/machine/sys-mmu.o (.text*)
|
||||||
*/machine/sys-spi-flash.o (.text)
|
_build/*/obj/hw/mcu/allwinner/*/machine/sys-spi-flash.o (.text*)
|
||||||
*/machine/sys-copyself.o (.text)
|
_build/*/obj/hw/mcu/allwinner/*/machine/sys-copyself.o (.text*)
|
||||||
PROVIDE(__bootloader_end = .);
|
PROVIDE(__bootloader_end = .);
|
||||||
} > ram
|
} > ram
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ SECTIONS
|
||||||
|
|
||||||
.text :
|
.text :
|
||||||
{
|
{
|
||||||
*/main.o (.text)
|
|
||||||
*(.text*)
|
*(.text*)
|
||||||
*(.glue*)
|
*(.glue*)
|
||||||
*(.note.gnu.build-id)
|
*(.note.gnu.build-id)
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import sys
|
||||||
|
import struct
|
||||||
|
|
||||||
|
def align(num, alignment):
|
||||||
|
if num % alignment != 0:
|
||||||
|
num += (alignment - num % alignment)
|
||||||
|
return num
|
||||||
|
|
||||||
|
|
||||||
|
def process_file(input, output):
|
||||||
|
with open(input, 'rb') as fin:
|
||||||
|
content = bytearray(fin.read())
|
||||||
|
|
||||||
|
align_value = 512
|
||||||
|
padded_length = align(len(content), align_value)
|
||||||
|
# pad file to actual length
|
||||||
|
content += b'\x00' * (padded_length - len(content))
|
||||||
|
|
||||||
|
struct_format = '<L8sLL'
|
||||||
|
(instruction, magic, checksum, length) = struct.unpack_from(struct_format, content)
|
||||||
|
|
||||||
|
if magic != b'eGON.BT0':
|
||||||
|
print("Magic is invalid:", magic)
|
||||||
|
return 2
|
||||||
|
|
||||||
|
checksum = 0x5F0A6C39
|
||||||
|
length = align(length, align_value)
|
||||||
|
|
||||||
|
struct.pack_into(struct_format, content, 0, instruction, magic, checksum, length)
|
||||||
|
|
||||||
|
checksum = 0
|
||||||
|
for i in range(0, length, 4):
|
||||||
|
(n, ) = struct.unpack_from('<L', content, i)
|
||||||
|
checksum += n
|
||||||
|
checksum %= 4294967296
|
||||||
|
|
||||||
|
struct.pack_into(struct_format, content, 0, instruction, magic, checksum, length)
|
||||||
|
|
||||||
|
with open(output, 'wb') as fout:
|
||||||
|
fout.write(content)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
print("Usage: mksunxi.py input.bin output.bin")
|
||||||
|
exit(1)
|
||||||
|
exit(process_file(sys.argv[1], sys.argv[2]))
|
Loading…
Reference in New Issue