flashrom读写flash bin文件
1、设备树中添加spidev0.0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | &spi0 { /* Disable SPI NOR by default: it optional on Orange Pi Zero boards */ pinctrl-names = "default" ; pinctrl-0 = <&spi0_pins>; status = "okay" ; spidev@0{ compatible = "Allwinner,sun8i-h2-spi0" ; reg = <0>; spi-max-frequency = <40000000>; // 128M spi-nor flash layout partition@00000000 { label = "u-boot" ; reg = <0x00000000 0x000C0000>; }; partition@000C0000 { label = "bootenv" ; reg = <0x000C0000 0x00020000>; }; partition@000E0000 { label = "dtb" ; reg = <0x000E0000 0x00020000>; }; partition@00100000 { label = "kernel" ; reg = <0x00100000 0x00500000>; }; partition@00600000 { label = "rootfs" ; reg = <0x00600000 0x00A00000>; }; }; }; |
2、驱动中添加compatiable
3、uboot配置
u-boot/configs/nano_c1_defconfig:
1 2 | CONFIG_SPI_SUNXI=y CONFIG_SPL_SPI_FLASH_SUPPORT=y |
4、make menuconfig -->utils-配置flashrom包
1 | CONFIG_PACKAGE_flashrom=y |
5、(查看读写的flash型号flashrom是否已经添加,没有添加自己需要添加)增加要读写的flash信息(以XMC为例)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | //flashchips.c文件 { .vendor = "XinXin" , .name = "XM25QH128C" , .bustype = BUS_SPI, .manufacture_id = ST_ID, .model_id = ST_XM25QH128C, .total_size = 16384, .page_size = 256, /* OTP: 1536B total; read 0x48; write 0x42, erase 0x44 */ /* QPI: enable 0x38, disable 0xFF */ .feature_bits = FEATURE_WRSR_WREN | FEATURE_OTP | FEATURE_QPI, .tested = TEST_OK_PREW, .probe = probe_spi_rdid, .probe_timing = TIMING_ZERO, .block_erasers = { { .eraseblocks = { {4 * 1024, 4096} }, .block_erase = spi_block_erase_20, }, { .eraseblocks = { {32 * 1024, 512} }, .block_erase = spi_block_erase_52, }, { .eraseblocks = { {64 * 1024, 256} }, .block_erase = spi_block_erase_d8, }, { .eraseblocks = { {16 * 1024 * 1024, 1} }, .block_erase = spi_block_erase_60, }, { .eraseblocks = { {16 * 1024 * 1024, 1} }, .block_erase = spi_block_erase_c7, } }, /* TODO: 2nd status reg (read 0x35, write 0x31) and 3rd status reg (read 0x15, write 0x11) */ .printlock = spi_prettyprint_status_register_bp4_srwd, .unlock = spi_disable_blockprotect_bp4_srwd, .write = spi_chip_write_256, .read = spi_chip_read, /* Fast read (0x0B) and multi I/O supported */ .voltage = {2700, 3600}, }, |
定义设备和厂商ID
1 | //flashchips.h文件#define ST_XM25QH128C 0x4018 |
6、系统编译成功后会在/usr/sbin下生成flashrom工具
根据一下命令读写:
1 2 | read flash: flashrom -p linux_spi:dev= /dev/spidev0 .0 -r flash.bin write flash: flashrom -p linux_spi:dev= /dev/spidev0 .0 -w flash.bin |
其他命令也可以flashrom -h去查看
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | root@OpenWrt:/ # flashrom -h flashrom v1.2 on Linux 5.4.124 (armv7l) flashrom is free software, get the source code at https: //flashrom .org Usage: flashrom [-h|-R|-L| -p <programmername>[:<parameters>] [-c <chipname>] (--flash-name|--flash-size| [-E|(-r|-w|- v ) < file >] [(-l <layoutfile>|--ifd| --fmap|--fmap- file < file >) [-i <imagename>]...] [-n] [-N] [-f])] [-V[V[V]]] [-o <logfile>] -h | --help print this help text -R | --version print version (release) -r | -- read < file > read flash and save to < file > -w | --write < file > write < file > to flash - v | --verify < file > verify flash against < file > -E | --erase erase flash memory -V | --verbose more verbose output -c | --chip <chipname> probe only for specified flash chip -f | --force force specific operations (see man page) -n | --noverify don't auto-verify -N | --noverify-all verify included regions only (cf. -i) -l | --layout <layoutfile> read ROM layout from <layoutfile> --flash-name read out the detected flash name --flash-size read out the detected flash size --fmap read ROM layout from fmap embedded in ROM --fmap- file <fmapfile> read ROM layout from fmap in <fmapfile> --ifd read layout from an Intel Firmware Descriptor -i | --image <name> only flash image <name> from flash layout -o | --output <logfile> log output to <logfile> --flash-contents <ref- file > assume flash contents to be <ref- file > -L | --list-supported print supported devices -p | --programmer <name>[:<param>] specify the programmer device. One of internal, dummy, gfxnvidia, drkaiser, satasii, atavia, it8212, ft2232_spi, serprog, buspirate_spi, dediprog, developerbox, pony_spi, nicintel, nicintel_spi, nicintel_eeprom, ogp_spi, linux_mtd, linux_spi, usbblaster_spi, mstarddc_spi, pickit2_spi, ch341a_spi, digilent_spi, stlinkv3_spi. You can specify one of -h, -R, -L, -E, -r, -w, - v or no operation. If no operation is specified, flashrom will only probe for flash chips. |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)