本帖最后由 lzy871238103 于 2024-9-9 14:55 编辑
flashrom
flashrom作为一款强大的flash编程工具,集检测、读取、写入、验证和擦除功能为一体,通常用于擦写主板中闪存BIOS/EFI/coreboot/固件,同时也支持网卡(NIC)、SATA控制器卡和其他可以编程闪存芯片。
项目地址:https://github.com/flashrom/flashrom
CH347简介
CH347是一款高速USB总线转接芯片,通过USB总线提供异步串口、I2C同步串行接口、SPI同步串行接口和JTAG接口等。芯片资源如下:
1. 2个高速串口,最高波特率达9Mbps
2. 1个2线I2C接口,最高速率1MHz
3. 1个4线SPI接口,最高速率60MHz
4. 1个JTAG接口,最高速率60MHz
5. 1个SWD接口
作为CH341的升级款,CH347的功能更加强大,特别是CH347F,无需进行模式切换,即可使用所有功能。
具体可参考:
https://www.wch.cn/products/CH347.html
软件编译
代码的编译在项目中有所介绍这里不多赘述:
flashrom编译方式
而这里为了Windows系统下使用方便,特别将Windows下驱动改为官方驱动,并编译好版本,上传至GitHub仓库。
Windows版本:
https://github.com/ZhiyuanYuanNJ/flashrom/releases
软件使用
flashrom除基本的读写功能外,还可以解除芯片的读写保护,设置写保护区域以及读取芯片的Layout,具体可使用-h指令查看详情。
- .\flashrom.exe -h
- flashrom 1.4.0-devel (git:) on Windows 10.0 (x86_64) Dreg's mod https://www.rootkit.es v3.3
- flashrom is free software, get the source code at https://flashrom.org
- Using clock_gettime for delay loops (clk_id: 1, resolution: 100ns).
- Usage: flashrom.exe [-h|-R|-L|
- -p <programmername>[:<parameters>] [-c <chipname>]
- (--flash-name|--flash-size|
- [-E|-x|(-r|-w|-v) <file>]
- [(-l <layoutfile>|--ifd| --fmap|--fmap-file <file>) [-i <region>[:<file>]]...]
- [-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> or the content provided
- on the standard input to flash
- -v | --verify (<file>|-) verify flash against <file>
- or the content provided on the standard input
- -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)
- -x | --extract extract regions to files
- -l | --layout <layoutfile> read ROM layout from <layoutfile>
- --wp-disable disable write protection
- --wp-enable enable write protection
- --wp-list list supported write protection ranges
- --wp-status show write protection status
- --wp-range=<start>,<len> set write protection range (use --wp-range=0,0
- to unprotect the entire flash)
- --wp-region <region> set write protection region
- --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 | --include <region>[:<file>] only read/write image <region> from layout
- (optionally with data from <file>)
- --image <region>[:<file>] deprecated, please use --include
- -o | --output <logfile> log output to <logfile>
- --flash-contents <ref-file> assume flash contents to be <ref-file>
- -L | --list-supported print supported devices
- --progress show progress percentage on the standard output
- -p | --programmer <name>[:<param>] specify the programmer device. One of
- dummy, raiden_debug_spi, ft2232_spi, serprog, buspirate_spi, dediprog,
- developerbox, pony_spi, usbblaster_spi, pickit2_spi, ch341a_spi, ch347_spi,
- digilent_spi, stlinkv3_spi, dirtyjtag_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.
Detect当前的flash:
如当前连接flash为W25Q16.V
- # -p指定当前adapter为CH347
- .\flashrom.exe -p ch347_spi
- flashrom 1.4.0-devel (git:) on Windows 10.0 (x86_64) Dreg's mod https://www.rootkit.es v3.3
- flashrom is free software, get the source code at https://flashrom.org
- Using clock_gettime for delay loops (clk_id: 1, resolution: 100ns).
- Open CH347 device success.
- Invalid SPI speed, using defaul(60M clock spi).
- Found Winbond flash chip "W25Q16.V" (2048 kB, SPI) on ch347_spi.
- No operations were specified.
读取flash内容:
- # 指定spi速度为15M
- .\flashrom.exe -p ch347_spi:spispeed=15M -r data.bin
写入flash:
- # 默认SPI速度为60M
- .\flashrom.exe -p ch347_spi -w data.bin
|