|
本帖最后由 jiuweiljp 于 2023-11-4 10:13 编辑
一、前言:
这几天有点时间,研究了下ftdi 2232H,这个设备是一个通用性较强的MCU,速度也比较快,比STM32容易上手。
在路由器设备上这可以用于 :
1、高速可靠的 ttl (1Mbps我测试过的 ) 下载程序飞快;
2、读、写spi nor flash(使用程序flashrom(开源),windows,linux都有);
3、Jtag (使用 openocd)水平有限没有能力研究;
4、 读、写nand Flash(这篇文章的主题)
二、硬件:
这次使用的硬件非常简单,不需要焊接,不需要其它附加电容、电阻,上手简单
1、Ftdi 2232
2、连接线
3、弹跳座
4、完成图
5、参考接线图(被覆盖的数值是36)
注意:这个图只做为参考,如果你写完nand复制出来的文件与原文件不同,就参考下面的6、的接线图
(后期补充:我测试过如果将2232的BDBUS 4 接GND也可以安全的写入nand)
6、也可以用下面的接线图,这个图在我的2232H下能用yand安全的写入nand flash
二、软件部分
本文章参考了网文“NANDReader(用ft2232h做的nand读取器)研究了一番 发发成果” 但该文没有写详细,特别是软件这部分。
2.1 安装厂商驱动
下载: http://www.ftdichip.com/Drivers/CDM/CDM21228_Setup.zip
驱动正常安装完后图片,端口号(com3,com4)会有所不同
厂商:FTDI ; 版本:2.12.28.0
VID 0403 PID 6010
2.2 NandToos
如果你之前没有使用“Ftdi FT Prog 程序”修改过2232H参数,就可以直接使用下面的软件
项目介绍 http://spritesmods.com/?art=ftdinand&page=1
源码网址 https://github.com/bkerler/NANDReader_FTDI
如果硬件连接正常并且驱动安装没有问题
- >NandTool.exe -i #可以查看nand芯片的信息
- FT2232H-based NAND readerNand type: NAND 128MiB 3,3V 8-bit
- Manufacturer: Toshiba
- ID: D1
- Chip: 90
- Size: 128MB, pagesize 2048 bytes, OOB size 64 bytes
- Large page, needs 4 addr bytes.
- All done.
复制代码 NandToos 可以查看帮助信息
- >NandTool
- FT2232H-based NAND reader
- Usage: [-i|-r file|-v file] [-t main|oob|both] [-s]
- -i - Identify chip
- -r file - Read chip to file
- -v file - Verify chip from file data
- -t reg - Select region to read/write (main mem, oob ('spare') data or both, interleaved)
- -s - clock FTDI chip at 12MHz instead of 60MHz
- -u vid:pid - use different FTDI USB vid/pid. Vid and pid are in hex.
复制代码 参数说明:
-r 读nand flash到文件
- >cls
- >NandTool -r i:\temp.bin
- FT2232H-based NAND reader
- Nand type: NAND 128MiB 3,3V 8-bit
- Manufacturer: Toshiba
- ID: D1
- Chip: 90
- 2622/65536B, pagesize 2048 bytes, OOB size 64 bytes
- Large page, needs 4 addr bytes.
- Reading 65536 pages of 2048 bytes...
- 656/65536
复制代码 -v 校验文件是否与芯片的内容相同
-t 指定区域(main 或 oob 或 both),指定读 主数据 或 oob 数据或都读取。
注:该软件功能较简单,好像没有写数据的功能,有源代码有能力的朋友可自行研究。
并且执行该软件前要清理下屏幕(cls)不然没法看清反馈信息。
2.3 dumpflash(旧版本)
项目地址:https://github.com/ohjeongwook/dumpflash
该软件需要libusb 及 python支持,(我测试过直接下载该项目,在windows、linux中有在特定nand芯片下不能运行,如果不会使用git log 和 git checkout最好使用本文的下载地址。
下载
2.3.1 下载 zadig
https://zadig.akeo.ie/
2.3.1.1 目前最新的是版本是2.5,双击运行后,选择option->list all devices
2.3.1.2 选择 interface 0
2.3.1.3 选择libusb-win32 然后点击replace driver,测试过选择 libusbK (v3.0.7.0) 也可以
2.3.1.4 成功提示
可以看见在上文2.1安装厂商驱动后出现的com3没有了,多了一个USB<-->SerialConverter (Interface 0)
USB <-> SerialConverter (Interface 0)
注意事项:
(1)FTDI 2232H有2个高速端口,在步骤(2)这里只能选择interface 0,并且只需要更换interface0 的驱动,interface 1 保持厂商驱动就好。
(2)安装libusb后上文的nandtool 软件就不能正常运行了。
(3)如果你用Ft prog 修改过2232H的参数,在使用原厂驱动的环境下使用“FT Prog”将A和B两个端口的参数均修改如下图:
2.3.2下载及安装Python2.7
提示:安装的路径最好简单点 比如c:\python27
2.3.2.1 安装python2.7中的插件
在命令行提示符下(运行 cmd)输入 (注意这个步骤需要连接互联网)
- C:\Users\Administrator>pip2 install pyftdi==*
- 显示结果如下
- Cache entry deserialization failed, entry ignored
- Could not find a version that satisfies the requirement pyftdi==* (from versions: 0.42.0.macosx-10.14-x86_64, 0.4.5, 0
- .5.1, 0.5.2, 0.6.3, 0.13.2, 0.13.4, 0.22.1, 0.25.0, 0.25.2, 0.26.3, 0.26.4, 0.27.0, 0.28.0, 0.28.2, 0.28.3, 0.28.8, 0.28
- .9, 0.28.10, 0.29.0, 0.29.1, 0.29.2, 0.29.3, 0.29.4, 0.29.6, 0.30.0, 0.30.1, 0.30.2, 0.30.3, 0.40.5, 0.40.6, 0.42.2, 0.4
- 3.0, 0.44.0, 0.44.1, 0.44.2, 0.47.2, 0.48.2, 0.48.3, 0.50.0, 0.50.1, 0.50.2, 0.51.0, 0.51.2)
- No matching distribution found for pyftdi==*
- You are using pip version 8.1.1, however version 20.1.1 is available.
- You should consider upgrading via the 'python -m pip install --upgrade pip' command.
复制代码 可以看见好多版本可以选择(从0.4.5直到0.51.2),注意pyftdi 0.13.4以上的 版本就不支持 python2.7了。
2.3.2.2指定版本号安装
- pip2 install pyftdi==0.13.4
复制代码 正常情况下在安装pyftdi时会安装附带 pyserial 、pyusb、six等软件
查看已安装软件方法如下:
- C:\Users\Administrator>pip2 list
- astroid (1.4.9)
- backports.functools-lru-cache (1.6.1)
- colorama (0.4.3)
- futures (3.3.0)
- isort (4.3.21)
- lazy-object-proxy (1.5.0)
- mccabe (0.6.1)
- pip (8.1.1)
- pyftdi (0.13.4)
- pyserial (3.4)
- pyusb (1.0.2)
- setuptools (20.10.1)
- six (1.15.0)
- tqdm (4.46.1)
- wrapt (1.12.1)
复制代码 可以看见在python中已经安装了pyftdi (0.13.4)、pyserial (3.4)、six(1.15.0)、pyusb(1.0.2),括号后面是各插件的版本;
如果没有这几个插件可使用下面的命令分别安装:
- pip2 install pyusb==1.0.2
- pip2 install six==1.15.0
- pip2 install pyserial==3.4
复制代码
如果不小心安装了高版本的插件有可能无法用低版本的覆盖,先卸载它
然后指定版本号安装
- pip2 install pyftdi==0.13.4
复制代码
2.3.3 Dumpflash的使用
在软件目录中输入Dumpflash -i 可以看见nand芯片信息
- c:\DumpFlash-master>python2 DumpFlash.py -i
- Full ID: 98D19015761410
- ID Length: 7
- Name: NAND 128MiB 3,3V 8-bit
- ID: 0xd1
- Page size: 0x800 (2048 Byte)
- OOB size: 0x40 (64 Byte)
- Page count: 0x10000 (65536 Page)
- Size: 0x80 (128 MB)
- Erase size: 0x20000 (131072)
- Block count: 1024
- Options: 1
- Address cycle: 4
- Bits per Cell: 1
- Manufacturer: Toshiba
复制代码
使用-h 可以看见帮助信息
- >python2 DumpFlash.py -h
- Usage: DumpFlash.py [options]
- Options:
- -h, --help show this help message and exit
- -i Display NAND information
- -r Read NAND Flash to a file
- -w Write file to a NAND Flash
- -e Erase
- -B Check bad blocks
- -R Raw mode - skip bad block before reading/writing
- -c Check ECC
- -O Add OOB to the source
- --OJ Add JFFS2 OOB to the source
- -o Remove OOB from the source
- -u Find U-Boot images
- -U Dump U-Boot images
- -j Find JFFS2 Image
- -J Dump JFFS2 Image
- -n NAME_PREFIX Set output file name prefix
- -s Set sequential row read mode - some NAND models
- supports
- -S Set clock FTDI chip at 12MHz instead of 60MHz
- -f FILENAME Use file instead of device for operations
- -C COMPARE_TARGET_FILENAME
- When writing a file compare with this file before
- writing and write only differences
- -t OFFSET default 0
- -p PAGES eg: -p 0 10
- -b BLOCKS eg: -b 0 10
- -P PAGE_SIZE eg: -P 2048
- -E OOB_SIZE eg: -E 64
- -K PAGES_PER_BLOCK eg: -K 64
复制代码
a 简单的读写:
- python2 DumpFlash.py -r read.bin #可读取整个Flash 数据到read.bin文件
- python2 DumpFlash.py -w data.bin #可将data.bin文件写入到Flash
复制代码
b 擦除整个整个芯片
提示:有一部分芯片在使用过程中产生假坏块,使用擦除命令可以消除这些坏块
c 检测坏块
- python2 DumpFlash.py -B
- Checking Bad Blocks 0% Block: 1/1024 at offset 0x0
- Checking Bad Blocks 0% Block: 2/1024 at offset 0x20000
- Checking Bad Blocks 0% Block: 3/1024 at offset 0x40000
- Checking Bad Blocks 0% Block: 4/1024 at offset 0x60000
- Checking Bad Blocks 0% Block: 5/1024 at offset 0x80000
- Checking Bad Blocks 99% Block: 1023/1024 at offset 0x7fc0000
- Checking Bad Blocks 100% Block: 1024/1024 at offset 0x7fe0000
- Checked 1024 blocks and found 0 errors
复制代码
d 其它部分功能
- -p PAGES eg: -p 0 10 # 指定页操作 -p 起始页 结束页,nand芯片的第一页是0 开始计数,如果擦除芯片 结束页 必须是块大小的倍数 ,比如这个我的toshiba芯片的块大小是64
- -b BLOCKS eg: -b 0 10 # 指定块操作 -b 起始块 结束块
- -P PAGE_SIZE eg: -P 2048 #指定每页的大小,应该配合 -f 参数使用针对文件操作 (不是很确定)
- -E OOB_SIZE eg: -E 64 #指定oob的大小,应该配合 -f 参数使用针对文件操作(不是很确定)
- -K PAGES_PER_BLOCK eg: -K 64 #指定块的大小,应该配合 -f 参数使用针对文件操作(不是很确定)
复制代码
e 该软件有软件ecc功能,使用的是一种通用算法,好像博通的芯片用这种ecc算法。
另外可以使用-R 参数切换到RAW模式
f 更高级的功能推荐看下面的网文
如何逆向嵌入式设备的NAND Flash
其它说明:
1、速度问题,该软件在windows 下读的速度能到700KB/秒-800KB/秒,写nandflash好像不是很稳定。linux正常下能读150K/秒左右,写不到100K/秒(后期测试在特定情况下读写能到700KB/秒)。
2、另外 -S参数在我的电脑中 windows 及linux 下都好像有问题,读完nand后的存盘文件总是缺少几个字节,按道理说是速度慢更可靠,不知道什么原因。
3、有部分芯片第一次运行时会出现
- \DumpFlash>python2 DumpFlash.py -i
- Device not ready, aborting...
复制代码 这是软件的问题,运行下面介绍的yand的软件
- C:\Python37\Scripts>yand_cli.py
- Chip info: Chip model & Manufacturer: MT29F2G08ABAEAWP (MICRON)
- Page Size : 2112 (2048 + 64)
- Blocks number : 2048
- Device Size: 264MiB
复制代码 再次运行软件就好了,我也不知道什么原因
- DumpFlash>python2 DumpFlash.py -i
- Full ID: 2CDA90956000
- ID Length: 6
- Name: NAND 256MiB 3,3V 8-bit
- ID: 0xda
- Page size: 0x800 (2048 Byte)
- OOB size: 0x40 (64 Byte)
- Page count: 0x20000 (131072 Page)
- Size: 0x100 (256 MB)
- Erase size: 0x20000 (131072)
- Block count: 2048
- Options: 1
- Address cycle: 5
- Bits per Cell: 1
- Manufacturer: Micron
复制代码
2.4 yand
为什么要介绍这个软件,因为上文介绍的软件在windows 下写nand有点问题,半残了,这个软件是上一个软件的衍生版本,
并且没有ECC完全的RAW模式,windows下读的速度150KB/秒左右,写的速度也是150KB/秒左右,写nand很稳定
经过测试128MB的nandflash 完全写的时间约15分钟左右,马马虎虎还可以接受。
软件项目地址
https://github.com/conchyliculture/Yand
2.4.1、安装python3.7(如同安装python2.7一样,安装的目录尽量简单点,比如c:\python37)
这个软件要在python 3.7的版本下使用,我测试过python2.7 与python 3.7能共存,
但要注意因为python2.7与python3.7安装完后执行文件都是python.exe结果就是哪个版本后装的就执行那个版本。
解决办法,比如可以将c:\python27\python.exe 改名为python2.exe,
改名后 在cmd输入 python 就是执行python3.7,输入python2 就是执行python2.7
2.4.2、软件安装,在软件目录下执行
2.4.3、插件替换
安装完后的安和程序将 pyftdi 的版本自接提到最高(0.51.2),我测试过0.50.0以上的pyftdi不能在本软件中正确调用
- pip3 uninstall pyftdi #卸载pyftdi
- pip3 install pyftdi==0.48.3 #重新安装pyftdi并指定版本号
复制代码
2.4.4、安装完成后查看各插件的版本
- C:\Python37\Scripts>pip3 list
- Package Version
- --------------------- --------
- astroid 2.4.2
- colorama 0.4.3
- dumpflash-ohjeongwook 0.0.1
- isort 4.3.21
- lazy-object-proxy 1.4.3
- mccabe 0.6.1
- pip 19.2.3
- pyftdi 0.48.3
- pyserial 3.0
- pyusb 1.0.2
- setuptools 41.2.0
- six 1.15.0
- toml 0.10.1
- tqdm 4.46.1
- typed-ast 1.4.1
- wrapt 1.12.1
- yand 20190926
复制代码 在以上的列表中pyusb 1.0.2 、pyserial 4.8 、pyftdi 0.48.3、six 1.15.0、tqdm 4.46.1 都是该软件需要的插件,
yand 20190926就是本软件
2.4.5、运行,在C:\Python37\Scripts的目录下就是本软件的安装位置
这里分两种情况
第一种 软件能读出ONFI信息
- C:\Python37\Scripts>yand_cli.py
- Chip info: Chip model & Manufacturer: MT29F2G08ABAEAWP (MICRON)
- Page Size : 2112 (2048 + 64)
- Blocks number : 2048
- Device Size: 264MiB
复制代码
第二种 软件不能读出ONFI信息
- C:\Python37\Scripts>python yand_cli.py
- Traceback (most recent call last):
- File "yand_cli.py", line 4, in <module>
- __import__('pkg_resources').run_script('yand==20190926', 'yand_cli.py')
- File "C:\Python37\lib\site-packages\pkg_resources\__init__.py", line 666, in run_script
- self.require(requires)[0].run_script(script_name, ns)
- File "C:\Python37\lib\site-packages\pkg_resources\__init__.py", line 1469, in run_script
- exec(script_code, namespace, namespace)
- File "C:\Python37\lib\site-packages\yand-20190926-py3.7.egg\EGG-INFO\scripts\yand_cli.py", line 206, in <module>
- File "C:\Python37\lib\site-packages\yand-20190926-py3.7.egg\EGG-INFO\scripts\yand_cli.py", line 140, in Main
- File "C:\Python37\lib\site-packages\yand-20190926-py3.7.egg\yand\nand_interface.py", line 148, in Setup
- File "C:\Python37\lib\site-packages\yand-20190926-py3.7.egg\yand\nand_interface.py", line 97, in _SetupFlash
- yand.errors.YandException: Warning: Could not read ONFI info. Please provide geometry
- Flash returned "98d19015"
复制代码 没有问题,这个软件估计还是演进中,芯片库不是很全,它已经识别出nand芯片的ID号了“98d19015”,可以比照本文2.3.3中的“Full ID: 98D19015761410”
软件网站也提到过这个问题,直接带参数指定芯片物理特性就可以。
例如:
- python yand_cli.py -P "2048,64" -B 64 -K 1024 # -P "2048,64" 指定页的参数2048是页大小64是oob的大小,-B 64 每块有多少页 -K 1024 芯片有多少个块
- Chip info: Chip model & Manufacturer: Unknown Model (Unknown Manufacturer)
- Page Size : 2112 (2048 + 64)
- Blocks number : 1024
- Device Size: 132MiB
复制代码
2.4.6 读写nandflash
- C:\Python37\Scripts>python yand_cli.py -P "2048,64" -B 64 -K 1024 -r -f i:\temp.bin #读nand芯片到temp.bin 文件
- Chip info: Chip model & Manufacturer: Unknown Model (Unknown Manufacturer)
- Page Size : 2112 (2048 + 64)
- Blocks number : 1024
- Device Size: 132MiB
- Destination file i:\temp.bin already exists. Proceed? [y/N]y
- 0%|▏ | 214k/132M [00:01<16:39, 138kB/s]
- 0%|▏ | 229k/132M [00:01<16:40, 138kB/s]
- 0%|▏ | 245k/132M [00:01<16:20, 141kB/s]
- 0%|▏ | 260k/132M [00:02<16:40, 138kB/s]
- C:\Python37\Scripts>python yand_cli.py -P "2048,64" -B 64 -K 1024 -w -f i:\temp.bin #写temp.bin 文件到nand芯片
- Chip info: Chip model & Manufacturer: Unknown Model (Unknown Manufacturer)
- Page Size : 2112 (2048 + 64)
- Blocks number : 1024
- Device Size: 132MiB
- Reminder: You need to erase the entire flash with -e for this to work as expected
- About to write the content of "i:\temp.bin" to NAND Flash. Proceed? [y/N]y
- 0%|▏ | 214k/132M [00:01<15:08, 152kB/s]
- 0%|▏ | 233k/132M [00:01<14:31, 159kB/s]
复制代码
2.4.7 软件也不是很复杂,大家自己看吧,主要是它在windows能稳定写nand并且是Raw模式
- C:\Python37\Scripts>python yand_cli.py -h
- usage: yand_cli.py [-h] [-V] [-y] [-l LOGFILE] [-C] [-f FILE] [-r] [-w] [-e]
- [--write_value WRITE_VALUE] [--write_pgm] [--start START]
- [--end END] [-P PAGE_SIZE] [-B PAGES_PER_BLOCK]
- [-K NUMBER_OF_BLOCKS]
- optional arguments:
- -h, --help show this help message and exit
- -V, --version show version
- -y, --yes don't ask for conformation
- -l LOGFILE, --logfile LOGFILE
- log debug information to the specified file
- -C, --write_check read page after each page write operation
- -f FILE, --file FILE file to write to, or read from. "-" means stdin/stdout
- Function Options:
- Specify what operation to run.
- -r, --read read all NAND Flash
- -w, --write write NAND from a raw dump
- -e, --erase erase blocks
- --write_value WRITE_VALUE
- fill the NAND with this value.
- --write_pgm use a .pgm source image file. Will write the image
- over and over until the end.
- --start START Set a start bound for the operation. This bound is
- included: range(start, end)(for a read or write
- operation, the unit is a page, for Erase, it is a
- block
- --end END Set a end number for the operation. This bound is
- excluded: range(start, end)(for a read or write
- operation, the unit is a page, for Erase, it is a
- block
- Geometry options:
- Specify the geometry of the NAND flash if it can't be detected via ONFI.
- -P PAGE_SIZE, --page_size PAGE_SIZE
- specify page size and OOB size in bytes, with the
- format: "2048,128"
- -B PAGES_PER_BLOCK, --pages_per_block PAGES_PER_BLOCK
- number of pages per block
- -K NUMBER_OF_BLOCKS, --number_of_blocks NUMBER_OF_BLOCKS
- total number of blocks
复制代码
下载地址
http://lzdz.x3322.net:81/ftdi_2232/
特别提醒:
经过比对,以上两个工具拷贝出来的文件,需要做一个32位的翻转才能用于其它工具或设备作为源文件,
如果你用这个软件写nandflash则没有这个问题。
三、linux下有空再介绍吧
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|