make_flash_header.py

来自「专业汽车级嵌入式操作系统OSEK的源代码」· Python 代码 · 共 52 行

PY
52
字号
#!/usr/bin/env python## Take the flash_routine.bin file, and embed it as an array of bytes# in a flash_routine.h, ready for packaging with the C firmware# flasher.## If a file name is provided on the commandline, load that file as the# firmware flashing routine instead.#from sys import argvif len(argv) == 2:    fname = argv[1]else:    fname = 'flash_write/flash.bin'fwbin = file(fname)# Build the char representation in memorydef char_by_char(f):    while True:        d = f.read(1)        if d == '':            raise StopIteration        yield ddata = []for c in char_by_char(fwbin):    data.append("0x%s" % c.encode('hex'))for i in range(0, len(data), 12):    data[i] = "\n" + data[i]data_str = ', '.join(data)len_data = "0x%X" % len(data)# Read in the templatetplfile = file('flash_routine.h.base')template = tplfile.read()tplfile.close()# Replace the values in the templatetemplate = template.replace('___FLASH_BIN___', data_str)template = template.replace('___FLASH_LEN___', len_data)# Output the done headerout = file('flash_routine.h', 'w')out.write(template)out.close()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?