20160809_jeffrey - silenceuncrio/diary GitHub Wiki

Index

  • 0925 - 準備 winston 協助 NAND Flash 開機 image 的板子
  • 1130 - nand read.raw 讀出 再寫回 nand flash
  • 1310 - 盤 將 kernelrootfs 燒錄到 NAND 所需 tool
  • 1330 - mtd-utils recipe
  • 1410 - U-Boot 把 NAND Flash image dump 出來
  • 1435 - 修改 mx6ul_14x14_evk.h - image 2MB
  • 1450 - U-Boot - image dump - tftpput
  • 1500 - 萬事起頭難
  • 1520 - 7 個 page dump - 64, 128, 192, 256, 320, 384, 448
  • 1605 - 第 320 個 page - DBBT - 不是我想像的規則 - 放棄

0925

先準備一塊可以讓 winston 協助 NAND Flash 開機 image 的板子

1130

-------------- Start to write the [ FCB ] -----
mtd: erasing @0:0x0-0x20000
mtd: Writing FCB0 [ @0:0x0 ] (840) *
mtd: erasing @0:0x20000-0x40000
mtd: Writing FCB1 [ @0:0x20000 ] (840) *
mtd: erasing @0:0x40000-0x60000
mtd: Writing FCB2 [ @0:0x40000 ] (840) *
mtd: erasing @0:0x60000-0x80000
mtd: Writing FCB3 [ @0:0x60000 ] (840) *
mtd_commit_bcb(FCB): status 0

-------------- Start to write the [ DBBT ] -----
mtd: erasing @0:0x80000-0xa0000
mtd: Writing DBBT0 [ @0:0x80000 ] (800) *
mtd: erasing @0:0xa0000-0xc0000
mtd: Writing DBBT1 [ @0:0xa0000 ] (800) *
mtd: erasing @0:0xc0000-0xe0000
mtd: Writing DBBT2 [ @0:0xc0000 ] (800) *
mtd: erasing @0:0xe0000-0x100000
mtd: Writing DBBT3 [ @0:0xe0000 ] (800) *
mtd_commit_bcb(DBBT): status 0

---------- Start to write the [ .tmp_kobs_ng ]----
mtd: Writting .tmp_kobs_ng: #0 @0: 0x00100000 - 0x00165000
mtd: erasing @0:0x100000-0x120000
mtd: erasing @0:0x120000-0x140000
mtd: erasing @0:0x140000-0x160000
mtd: erasing @0:0x160000-0x180000
mtd: We write one page for save guard. *
mtd: Writting .tmp_kobs_ng: #1 @0: 0x00200000 - 0x00265000
mtd: erasing @0:0x200000-0x220000
mtd: erasing @0:0x220000-0x240000
mtd: erasing @0:0x240000-0x260000
mtd: erasing @0:0x260000-0x280000
mtd: We write one page for save guard. *

雖然前面的 1MB - 0x00000000 ~ 0x00100000

MfgTool 的 kobs-ng 分八次寫入到八個地方

winston 表示可以把這 1MB 利用 nand read.raw 直接讀出來再寫回 nand flash 就可以了

  • nand read.raw 81000000 0 200
    • 從 NAND Flash address 0x00000000 讀 512(0x200) 個 page(連同 OOB) 到 RAM address 0x81000000 去
  • nand erease.chip
  • nand write.raw 81000000 0 200
    • 從 RAM address 0x81000000 讀 512(0x200) 個 page(連同 OOB) 到 NAND Flash address 0x00000000 去

實際上看到的確可行

理論上直接用 read.raw 把 3MB 的 image 直接讀出來是最單純的

不過要把這 3MB 的 OOB 再抽出來才行

目前堪用的 tftpput 連一次 put 一個 page 都辦不到

先來克服這件事好了

不過也許 linux 有更多工具可以用

1310

參考 bitbake linux-mfgtool - 包含我們需要的 tool

盤一下我們之後需要將 kernelrootfs 燒錄到 NAND 去所需要的 tool

  • flash_erase
  • nandwrite
  • ubiformat
  • ubiattach
  • ubimkvol
  • mkdir
  • mount
  • umount
  • tar

flash_erase

目前 M300 沒有

參考 ubuntu_16 上的 linux-mfgtool 設定

感覺不是從 make menuconfig 下手

1330

發現關鍵是 mtd-utils 這個 recipe

加到 local.conf

...
DISTRO_FEATURES_append = " iptables ... mtd-utils prosrc"
IMAGE_INSTALL_append +=  " iptables ... mtd-utils prosrc"
...

build image

jeffrey@jeffrey-VirtualBox:~/M300/fsl-release-bsp/build_small$ source bimage.sh
...

copy the full SD card image

jeffrey@jeffrey-VirtualBox:~/M300/fsl-release-bsp/build_small/images$ sudo dd if=core-image-minimal-imx6ulevk.sdcard of=/dev/sdb bs=1M && sync
52+0 records in
52+0 records out
54525952 bytes (55 MB) copied, 0.0328726 s, 1.7 GB/s

SD card 放回 M300 CPU 板

開機

root@M300:/# ls /usr/sbin/ | grep flash
flash_erase
flash_eraseall
flash_lock
flash_otp_dump
flash_otp_info
flash_otp_lock
flash_otp_write
flash_unlock
flashcp
root@M300:/# ls /usr/sbin/ | grep nand
nanddump
nandtest
nandwrite
root@M300:/# ls /usr/sbin/ | grep mtd
mtd_debug
mtdinfo
root@M300:/#

目前還需要的 tool 剩

  • ubiformat
  • ubiattach
  • ubimkvol

不過這些應該都包含在 mtd-utils 之中才對

1410

可能先試著用更單純的方式把可以開機的 NAND Flash 裡的 image dump 出來

1435

修改 <UBOOT_SRC_NAND>/include/configs/mx6ul_14x14_evk.h

#define CONFIG_MFG_NAND_PARTITION "mtdparts=gpmi-nand:2m(boot),16m(kernel),16m(dtb),-(rootfs) "
...
#define CONFIG_EXTRA_ENV_SETTINGS \
...
		"mtdparts=gpmi-nand:2m(boot),16m(kernel),16m(dtb),-(rootfs)\0"\
...
#if 0
#define CONFIG_FSL_USDHC
#endif
...
#if 0
#define CONFIG_VIDEO
#endif
...

MfgTool 的 log - 2016-08-09-MfgTool.log

-------------- Start to write the [ FCB ] -----
mtd: erasing @0:0x0-0x20000
mtd: Writing FCB0 [ @0:0x0 ] (840) *
mtd: erasing @0:0x20000-0x40000
mtd: Writing FCB1 [ @0:0x20000 ] (840) *
mtd: erasing @0:0x40000-0x60000
mtd: Writing FCB2 [ @0:0x40000 ] (840) *
mtd: erasing @0:0x60000-0x80000
mtd: Writing FCB3 [ @0:0x60000 ] (840) *
mtd_commit_bcb(FCB): status 0

-------------- Start to write the [ DBBT ] -----
mtd: erasing @0:0x80000-0xa0000
mtd: Writing DBBT0 [ @0:0x80000 ] (800) *
mtd: erasing @0:0xa0000-0xc0000
mtd: Writing DBBT1 [ @0:0xa0000 ] (800) *
mtd: erasing @0:0xc0000-0xe0000
mtd: Writing DBBT2 [ @0:0xc0000 ] (800) *
mtd: erasing @0:0xe0000-0x100000
mtd: Writing DBBT3 [ @0:0xe0000 ] (800) *
mtd_commit_bcb(DBBT): status 0

---------- Start to write the [ .tmp_kobs_ng ]----
mtd: Writting .tmp_kobs_ng: #0 @0: 0x00100000 - 0x0014c000
mtd: erasing @0:0x100000-0x120000
mtd: erasing @0:0x120000-0x140000
mtd: erasing @0:0x140000-0x160000
mtd: We write one page for save guard. *
mtd: Writting .tmp_kobs_ng: #1 @0: 0x00180000 - 0x001cc000
mtd: erasing @0:0x180000-0x1a0000
mtd: erasing @0:0x1a0000-0x1c0000
mtd: erasing @0:0x1c0000-0x1e0000
mtd: We write one page for save guard. *

目前已經整個 image 鎖死在 0x00000000 ~ 0x00200000 - 2,097,152 bytes 的範圍

因為 NAND Flash 可以開機

索性就把 整個 2,097,152 bytes 的範圍 read 到 RAM 去

  • nand read.raw 81000000 0 400
    • 從 NAND Flash address 0x00000000 用 read.raw 讀 0x400(1,024) 個 page(2048+64) 到 RAM address 0x81000000 去
=> nand read.raw 81000000 0 400

NAND read:  2162688 bytes read: OK

把 NAND Flash 整個 erase

  • nand erase.chip
=> nand erase.chip

NAND erase.chip: device 0 whole chip
Erasing at 0x7fe0000 -- 100% complete.
OK

再把 整個 2,097,152 bytes 的範圍 從 RAM write 到 NAND Flash 去

  • nand write.raw 81000000 0 400
    • 從 RAM address 0x81000000 用 write.raw 寫 0x400(1,024) 個 page(2048+64) 到 NAND Flash address 0x00000000 去
=> nand write.raw 81000000 0 400

NAND write:  2162688 bytes written: OK

開機

成功

1450

再來的事就簡單了

把 RAM 裡頭 0x81000000 到 0x81210000 總共 0x210000(2,162,688 bytes) 的 image dump 出來

tftpput 分兩次 put 一個 page 的話 - 要 0x400(1,024) 個 page

不過好好觀察可以發現有很多 page 可以製造出來

加油吧

1500

萬事起頭難

第 0 個 page - p000 - 0x81000000 - 0x840 bytes

  • tftpput 81000000 400 p000_0
  • tftpput 81000400 440 p000_1

使用 cat p000_0 p000_1 > p000 便可還原第 0 個 raw page

第 1 個 page - p001 - 0x81000840 - 0x840 bytes

  • tftpput 81000840 400 p001_0
  • tftpput 81000C40 440 p001_1

使用 cat p001_0 p001_1 > p001 便可還原第 1 個 raw page

內容全部為 0xff

理論上一直到第 63 個 page 都還是 0xff 才對

第 63 個 page - p063 - 0x810330C0 - 0x840 bytes - 0x81000000 + (0x840 * 63) = 0x810330C0

  • tftpput 810330C0 400 p063_0
  • tftpput 810334C0 440 p063_1

使用 cat p063_0 p063_1 > p063 便可還原第 63 個 raw page

1520

那重點只剩把下面 7 個 page dump 出來

  • 第 64 個 page - p064 - 0x81021000 - 0x840 bytes - 0x81000000 + (0x840 * 0x40) = 0x81021000
    • tftpput 81021000 400 p064_0
    • tftpput 81021400 440 p064_1
  • 第 128 個 page - p128 - 0x81042000 - 0x840 bytes - 0x81000000 + (0x840 * 0x80) = 0x81042000
    • tftpput 81042000 400 p128_0
    • tftpput 81042400 440 p128_1
  • 第 192 個 page - p192 - 0x81063000 - 0x840 bytes - 0x81000000 + (0x840 * 0xc0) = 0x81063000
    • tftpput 81063000 400 p192_0
    • tftpput 81063400 440 p192_1
  • 第 256 個 page - p256 - 0x81084000 - 0x840 bytes - 0x81000000 + (0x840 * 0x100) = 0x81084000
    • tftpput 81084000 400 p256_0
    • tftpput 81084400 440 p256_1
  • 第 320 個 page - p320 - 0x810A5000 - 0x840 bytes - 0x81000000 + (0x840 * 0x140) = 0x810A5000
    • tftpput 810A5000 400 p320_0
    • tftpput 810A5400 440 p320_1
  • 第 384 個 page - p384 - 0x810C6000 - 0x840 bytes - 0x81000000 + (0x840 * 0x180) = 0x810C6000
    • tftpput 810C6000 400 p384_0
    • tftpput 810C6400 440 p384_1
  • 第 448 個 page - p448 - 0x810E7000 - 0x840 bytes - 0x81000000 + (0x840 * 0x1c0) = 0x810E7000
    • tftpput 810E7000 400 p448_0
    • tftpput 810E7400 440 p448_1

1605

第 320 個 page 開始就是 DBBT 了

就已經不是我想像的規則了...

看來還是要從 Linux 著手