跟 UMU 一塊兒玩 OpenWRT(高級篇2):不拆機刷不死 U-Boot

    在上一篇《編譯 D-Link DIR-505 的不死 U-Boot》介紹瞭如何編譯不死 U-Boot,可是不死 U-Boot 的做者只介紹了用 TTL 線刷方法,UMU 可不想拆機,畢竟拆機感受並很差……linux

    第一個思路是刷上 DD-WRT 固件,可是找了一下 DD-WRT 木有支持 DIR-505,只好繼續蛋疼地編譯 OpenWRT。編程

    第一遍在虛擬機從 12:20 編譯到 23:56,花了將近 12 小時……剛開始時,有一個下載過程,不斷失敗,想一想是由於公司的網絡太爛了,因而把下載腳本改了一下:網絡

<openwrt-svn-dir>/trunk/scripts/download.pl 中的 wget -t5 --timeout=20 --no-check-certificate 改成 wget -t5 --timeout=120 --no-check-certificatesvn

    次日來,刷上,沒問題,因而開始改代碼去掉 U-Boot 寫保護,參考這篇《Openwrt 中刷寫 uboot ART》http://see.sl088.com/wiki/Openwrt_%E4%B8%AD%E5%88%B7%E5%86%99_uboot_art,但結果很不幸,型號不一樣嘛!函數

    接下來,憑本身的編程水平了,嘗試改 <openwrt-svn-dir>/trunk/target/linux/ar71xx/files/arch/mips/ath79/mach-dir-505-a1.c,加入下面兩個結構體:測試

static struct mtd_partition dir505_partitions[] = {

 {

  .name  = "u-boot",

  .offset  = 0,

  .size  = 0x010000,

  .mask_flags = 0,

 }, {

  .name  = "art",

  .offset  = 0x010000,

  .size  = 0x010000,

 }, {

  .name  = "mac",

  .offset  = 0x020000,

  .size  = 0x010000,

 }, {

  .name  = "nvram",

  .offset  = 0x030000,

  .size  = 0x010000,

 }, {

  .name  = "language",

  .offset  = 0x040000,

  .size  = 0x040000,

 }, {

  .name  = "firmware",

  .offset  = 0x080000,

  .size  = 0x780000,

  .mask_flags = 0,

 }

};

static struct flash_platform_data dir505_flash_data = {

 .parts  = dir505_partitions,

 .nr_parts       = ARRAY_SIZE(dir505_partitions),

};

    並將 dir_505_a1_setup 函數裏的 ath79_register_m25p80(NULL); 改成 ath79_register_m25p80(&dir505_flash_data);ui

    測試仍是無效……看來必須在源頭上使 MTD_WRITEABLE 無效掉,grep -r MTD_WRITEABLE <openwrt-svn-dir>/trunk/build_dir/target-mips_34kc_uClibc-0.9.33.2/linux-ar71xx_generic/linux-3.10.36/drivers/mtd,看到幾處關鍵的地方:spa

if (!(ubi->mtd->flags & MTD_WRITEABLE)) {

.net

if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))

    主要在 mtd_erase、mtd_write 等函數,很明顯,C 語言無論在什麼平臺都是很好懂,看幾眼就搞定了,原理是使 MTD_WRITEABLE 這個標誌無用掉,您能夠設置,可是我把判斷這個標誌的代碼全乾掉了,設了也是白設!code

    最後編譯好的 openwrt-ar71xx-generic-dir-505-a1-squashfs-sysupgrade.bin,用 sysupgrade 刷一下,reboot 後再用 mtd 刷不死 U-Boot,一切順利,成功刷上不死 U-Boot!

相關文章
相關標籤/搜索