⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 make_flash_header.py

📁 专业汽车级嵌入式操作系统OSEK的源代码
💻 PY
字号:
#!/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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -