HLK-7688AのNANDフラッシュをJTAGから書き換える
U-Bootが起動しない状態でU-Bootを焼き直すにはJTAGからできそうな気配がある これつかったらできそう
ChatGPTにREADMEを日本語訳してもらったものを置いておいた
J-LINKに対応させてる人がいた
VoCoreで使ってる例
READMEの英訳
9 EPHY_LED4 JTAG_RST_N GPIO39
10 EPHY_LED3 JTAG_CLK GPIO40
11 EPHY_LED2 JTAG_TMS GPIO41
12 EPHY_LED1 JTAG_TDI GPIO42
13 EPHY_LED0 JTAG_TDO GPIO43
他のSoCだが、JTAGでNANDフラッシュを焼いている例
Atherosのチップが載ってるルータをJTAGで復旧させる例
U-BootのドキュメントにあるJTAG経由でgdbを使う例
RaspberryPiをJTAGインターフェースとして使うこともできるっぽい
JTAGの使い方がよくわかってないので調べる
JTAGデバッガを入手する
ARM JTAG が6000円くらいと結構高い
FTDIのチップがかわりに使えるっぽい
FT232Hを使っている例
FT2232を使っている例
JTAG + OpenOCDの練習
練習としてRaspberryPiをJTAGで接続してみる
これらの記事を参考にやってみる
sysfsgpioドライバを使ってRaspberryPi4をJTAGデバッガに仕立て上げる
/usr/share/openocd/scripts/interface/sysfsgpio-raspberrypi.cfg が使えそうだったので使ってみる
GPIO番号は以下のコマンドで確認する
code:sh
cat /sys/kernel/debug/gpio
こんな感じにしてみた
code:sysfsgpio-raspberrypi.cfg
adapter driver sysfsgpio
sysfsgpio jtag_nums 523 537 522 521
sysfsgpio trst_num 519
reset_config trst_only
結線はこんな感じ
https://scrapbox.io/files/66eded7b76ffb8001c9945b2.png
table:pins
pinname color target openocd(gpio)
TRST brown 15 26(7)
RTCK red 16 -
TDO orange 18 21(9)
TCK yellow 22 23(11)
TDI green 37 19(10)
TMS blue 13 22(25)
VTref purple 1 -
GND black 6 6
RTCKはオープンでもいいらしい
raspi4.cfgはhikaliumさんの記事のものそのまま
code:sh
openocd -c 'bindto 0.0.0.0' -f sysfsgpio-raspberrypi.cfg -f raspi4.cfg
作業用マシンからRaspberryPiで起動しているOpenOCDにtelnet接続する
code:telnet.txt
$ telnet 192.168.39.11 4444
Trying 192.168.39.11...
Connected to 192.168.39.11.
Escape character is '^]'.
Open On-Chip Debugger
作業用マシンからRaspberryPiで起動しているOpenOCDにgdbで接続する
code:gdb.txt
$ gdb-multiarch
GNU gdb (Debian 13.1-3) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
Find the GDB manual and other documentation resources online at:
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) set architecture aarch64
The target architecture is set to "aarch64".
(gdb) target remote 192.168.39.11:3333
Remote debugging using 192.168.39.11:3333
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0xffffffddc50fb9e8 in ?? ()
(gdb)
HLK-7688AでJTAGできた
結線
https://scrapbox.io/files/66f422d03b0248001df361e1.png
Linuxカーネル起動後だと、Watchdog Timerを有効化になっているようで、JTAGからhaltしても勝手に再起動してしまう
電源投入してすぐ、Linuxの起動がはじまる前にいちどhaltしておくとWatchdog Timerを有効化されずに済む
いちどでもWatchdog Timerが有効化されると、電源が切れるまでWatchdog Timerが有効化されたままになる
これはWatchdog Timerの趣旨からして当たり前の挙動
code:openocd
reset
halt
ddrinit
load_image ramboot.bin 0x80200000
resume 0x80200000
一度だけ成功した?
code:txt
RamBoot 1.0.0 (U-Boot 1.1.3) (Jun 26 2017 - 13:12:03)
Board: Ralink APSoC DRAM: 128 MB
relocate_code Pointer at: 87f68000
flash manufacture id: ef, device id 40 19
find flash: W25Q256FV
============================================
RamBoot UBoot for Ralink-SoC
Version: 4.3.0.0
--------------------------------------------
ASIC 7628_MP (Port5<->None)
DRAM_CONF_FROM: From SPI/NAND
DRAM_TYPE: SDRAM
DRAM component: 256 Mbits
DRAM bus: 32 bit
Total memory: 32 MBytes
Flash component: SPI Flash
Date:Jun 26 2017 Time:13:12:03
============================================
icache: sets:512, ways:4, linesz:32 ,total:65536
dcache: sets:256, ways:4, linesz:32 ,total:32768
##### The CPU freq = 580 MHZ ####
estimate memory size =128 Mbytes
RESET MT7628 PHY!!!!!!
GPIOMODE --> 50054400
GPIOMODE2 --> 5540551
Please choose the operation:
1: Load system code to SDRAM via TFTP.
2: Load system code then write to Flash via TFTP.
3: Boot system code via Flash (default).
4: Entr boot command line interface.
7: Load Boot Loader code then write to Flash via Serial.
9: Load Boot Loader code then write to Flash via TFTP.
0
3: System Boot system code via Flash.
## Booting image at bc050000 ...
Image Name: MIPS OpenWrt Linux-4.14.95
Image Type: MIPS Linux Kernel Image (lzma compressed)
Data Size: 1508613 Bytes = 1.4 MB
Load Address: 80000000
Entry Point: 80000000
Verifying Checksum ... OK
Uncompressing Kernel Image ... OK
No initrd
## Transferring control to Linux (at address 80000000) ...
## Giving linux memsize in MB, 128
Starting kernel ...
0.000000 Linux version 4.14.95 (techware@ubuntu) (gcc version 7.39 resume の前に verify_image を行うようにしたら Ramboot が起動するようになった
code:openocd
reset
halt
ddrinit
load_image ramboot.bin 0x80200000
verify_image ramboot.bin 0x80200000
resume 0x80200000
code:txt
RamBoot 1.0.0 (U-Boot 1.1.3) (Jun 26 2017 - 13:12:03)
Board: Ralink APSoC DRAM: 128 MB
relocate_code Pointer at: 87f68000
flash manufacture id: ef, device id 40 19
find flash: W25Q256FV
============================================
RamBoot UBoot for Ralink-SoC
Version: 4.3.0.0
--------------------------------------------
ASIC 7628_MP (Port5<->None)
DRAM_CONF_FROM: From SPI/NAND
DRAM_TYPE: SDRAM
DRAM component: 256 Mbits
DRAM bus: 32 bit
Total memory: 32 MBytes
Flash component: SPI Flash
Date:Jun 26 2017 Time:13:12:03
============================================
icache: sets:512, ways:4, linesz:32 ,total:65536
dcache: sets:256, ways:4, linesz:32 ,total:32768
##### The CPU freq = 580 MHZ ####
estimate memory size =128 Mbytes
RESET MT7628 PHY!!!!!!
GPIOMODE --> 50054400
GPIOMODE2 --> 5540551
Please choose the operation:
1: Load system code to SDRAM via TFTP.
2: Load system code then write to Flash via TFTP.
3: Boot system code via Flash (default).
4: Entr boot command line interface.
7: Load Boot Loader code then write to Flash via Serial.
9: Load Boot Loader code then write to Flash via TFTP.
You choosed 4
0
4: System Enter Boot Command Line Interface.
RamBoot 1.0.0 (U-Boot 1.1.3) (Jun 26 2017 - 13:12:03)
RamBoot #
なんでこうなるのかはよくわからない