破解kindle--第二部分:啓動加載和固件的更新

 http://blog.sina.com.cn/s/blog_6441e0640100fxgf.html

 

按:本文譯自<Hacking the Kindle part 2bootloader and firmware updates >,可惜原站點已經無法登錄,只能從Google的網頁快照來翻譯。

啓動加載(Bootloader)

Kindle使用的是Das U-Boot加載器,只要在reset後按任意鍵,就可以進入交互式shell。鍵入help命令就可以得到下面的命令列表:

KINDLE> help
      - alias for 'help'
badblocks - print OneNAND bad block info
base    - print or set address offset
bbm     - BBM sub-system
bdinfo  - print Board Info structure
boot    - boot default, i.e., run 'bootcmd'
bootd   - boot default, i.e., run 'bootcmd'
bootf   - boot from various options
bootm - boot application image from memory
cmp     - memory compare
coninfo - print console devices and information
cp      - memory copy
crc32   - checksum calculation
dcache  - enable or disable data cache
diags   - execute the User Diagnostics from OneNAND
dsleep  - sleep USB device controller
dwake   - wake USB device controller
echo    - echo args to console
erase   - erase FLASH memory
exit    - exit script
factory - string [lock] [LLL_RR_PP]
fatinfo - print information about filesystem
fatload - load binary file from a dos filesystem
fatls   - list files in a directory (default /)
fb      - framebuffer subsystem
flinfo  - print FLASH memory information
gain    - displays/sets the gain value
go      - start application at address 'addr'
help    - print online help
hsuspend - suspend the 1761 USB host controller
hwake   - wake USB host controller
icache  - enable or disable instruction cache
iminfo  - print header information for application image
itest  - return true/false on integer compare
keys    - prints out hex values from device keyboard until console key is pressed
kindle  - print info about Kindle's revision
load    - load OneNAND page into DataRAM
loadb   - load binary file over serial line (kermit mode)
loads   - load S-Record file over serial line
loop    - infinite loop on address range
loopw   - infinite write loop on address range
mbboot  - boot bootloader from MMC/SC card
md      - memory display
mdc     - memory display cyclic
mkboot  - boot kernel & initrd from MMC/SD card
mm      - memory modify (auto-incrementing)
mmcinit - init mmc card
mtest   - simple RAM test
mw      - memory write (fill)
mwc     - memory write cyclic
nand    - NAND sub-system
nboot   - boot from NAND device
nm      - memory modify (constant address)
ohms    - calculates board resistance
onenand - print OneNAND register info
opamp   - displays/sets the op-amp offset value
otp     - dump/read/write OneNAND OTP
printenv- print environment variables
protect - enable or disable FLASH write protection
reboot  - alias of reset to match kernel
reset   - perform RESET of the CPU
run     - run commands in an environment variable
rve     - displays/sets the rve (reference voltage error) value
saveenv - save environment variables to persistent storage
serial  - set/display board serial number in OTP
setenv  - set environment variables
sleep   - delay execution for some time
snuz    - put PXA to sleep
test    - minimal test like /bin/sh
update  - update sub-system (updates images from MMC/SD card to flash)
usb_init  - init USB host controller
version - print monitor version
write   - write DataRAM buffer to OneNAND page

 

看一下bbm命令的作用:

KINDLE> ? bbm
bbm format
    - format device
bbm open
    - open device
bbm eraseall
    - erase all blocks
bbm erase 'start' 'end'
    - erase blocks from 'start' to 'end'
bbm load image 'id' ['start']
    - load image from partition 'id' into RAM;
      image is loaded into RAM at location 0xA2000000
or into 'start' if 'start' is specified (in hex)
bbm save image 'id' ['start'] 'size'
    - save image of 'size' to partition 'id';
      image should be loaded into RAM at 0xA2000000
      or into 'start' if 'start' is specified (in hex)

- Partition Info -
bbm show partition
    - show partition information
bbm save partition
    - save partition information
bbm del partition
    - delete last partition
bbm add partition 'id 'attr' 'blocks'
   - add partition 'id' of type 'attr' and of size 'blocks'
KINDLE> bbm show partition
<< PARTITION INFORMATION >>
id        : Bootloaders, Diagnostics (3)
attr      : RW (1)
first_blk : 0 (0x00000000)
no_blks   : 12 (1.5 MB)
  ---------------------
id        : Standard Kernel (17)
attr      : RW (1)
first_blk : 12 (0x00180000)
no_blks   : 12 (1.5 MB)
  ---------------------
id        : Recovery Kernel (16)
attr      : RW (1)
first_blk : 24 (0x00300000)
no_blks   : 12 (1.5 MB)
  ---------------------
id        : Standard Initrd (15)
attr      : RW (1)
first_blk : 36 (0x00480000)
no_blks   : 10 (1.3 MB)
  ---------------------
id        : Recovery Initrd (14)
attr      : RW (1)
first_blk : 46 (0x005C0000)
no_blks   : 10 (1.3 MB)
  ---------------------
id        : Read-only Root Filesystem (8)
attr      : RW (1)
first_blk : 56 (0x00700000)
no_blks   : 96 (12 MB)
  ---------------------
id        : Default Content (9)
attr      : RW (1)
first_blk : 152 (0x01300000)
no_blks   : 120 (15 MB)
  ---------------------
id        : Read/Write Root Filesystem (10)
attr      : RW (1)
first_blk : 272 (0x02200000)
no_blks   : 144 (18 MB)
  ---------------------
id        : Userstore (11)
attr      : RW (1)
first_blk : 416 (0x03400000)
no_blks   : 1584 (198 MB)
  ---------------------
id        : Environment Variables (4)
attr      : RW (1)
first_blk : 2000 (0x0FA00000)
no_blks   : 2 (256 KB)
  ---------------------

 

U-Boot的診斷鏡像的內容保存在第一分區。

有兩個內核,一個標準內核,一個還原內核,對應着相應的虛盤。還原內核用於固件的更新。

它有一個只讀的根文件系統,和一個讀寫的部分。默認的分區內容用於恢復出產設置。

還有一個用戶存貯分區,對應着用戶可以見到的U盤。

沒有從閃存拷貝內容到SD/MMC的命令,但是我可以把閃存的內容拷貝到內存,再把它導出。

 

KINDLE> bbm load image 3
Loading partition "Bootloaders, Diagnostics" into 0xA2000000... Success
KINDLE> base a2000000
KINDLE> md.b 0 100
a2000000: 4e 69 63 6b ff ff ff ff ff ff ff ff ff ff ff ff    Nick............
a2000010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
a2000020: 0e 00 00 ea 18 f0 9f e5 2c f0 9f e5 18 f0 9f e5    ........,.......
a2000030: 18 f0 9f e5 18 f0 9f e5 18 f0 9f e5 18 f0 9f e5    ................
a2000040: 60 00 00 a2 20 01 00 a2 80 01 00 a2 e0 01 00 a2    `... ...........
a2000050: 40 02 00 a2 a0 02 00 a2 00 03 00 a2 40 03 00 a2    @...........@...
a2000060: 00 00 0f e1 80 00 c0 e3 00 f0 29 e1 7c 00 9f e5    ..........).|...
a2000070: 21 0a 40 e2 02 0c 40 e2 02 0a 40 e2 0c d0 40 e2    !.@...@...@...@.
a2000080: 70 00 9f e5 70 10 9f e5 00 20 a0 e3 00 20 80 e5    p...p.... ... ..
a2000090: 04 00 80 e2 01 00 50 e1 fb ff ff 1a e6 80 00 ea    ......P.........
a20000a0: 00 00 a0 40 00 00 00 00 00 00 00 00 00 00 00 00    ...@............
a20000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
a20000c0: 28 00 1f e5 18 10 90 e5 01 10 81 e3 18 10 80 e5    (...............
a20000d0: 10 10 90 e5 02 1b 81 e2 02 1b 81 e2 0c 10 80 e5    ................
a20000e0: fe ff ff ea ef be ad de ef be ad de ef be ad de    ................
a20000f0: 00 00 00 a2 20 00 00 a2 1c 56 06 a2 98 52 4a a3    .... ....V...RJ.

(Nick參考見Nick Vaccaro的Lab126文, 他顯然是Kindle 軟件的主要開發者, 你好, Nick!)

由於我的線纜和不穩定的終端,我導出的數據超過256字節時,要麼返回開始的,要麼返回最後的。所以我不得不借助一個小的Python腳本,把數據分成256字節的塊導出,再寫入到一個文件。每個分區都要寫上幾個小時,不過最後我終於導出了我想要的東西。在還原內核的initrd鏡像部分我發現了執行固件更新的腳本,我轉成了刷新的文件(update)格式。

固件更新(fireware updates)

固件更新可以通過手機下載或者通過SD卡和用戶的U盤存貯分區來實現。

固件更新文件名必需符合"update*.bin" ,放在用戶存貯分區的根目錄(Kindle的USB盤)或者放在SD/MMC卡上,只能放成這樣。更新文件有一個文件頭,而且必需是.tar.gz的更新文件。

破解kindle--第二部分:啓動加載和固件的更新

版式本的數值是由Kindle的版式本字串組成。在我的機器上是292-Kindle-012138 版本數值爲121380292 (12138*10000 + 292).
手動更新除了檢查簽名和MD5值外,不檢查其它任何的域。

干擾(scrambled)算法爲:

byte = rol(byte,4)^0x7A;

解擾(descrambled)算法爲:

byte = rol(byte^0x7A,4);

tgz文件還要包含名爲"update*.dat"的文件.它的每行格式如下:

 id md5 filename block_count display_name

id爲要寫入的分區的ID。我知道的數值如下:

基本的只讀文件系統(RO fs) (squashfs 鏡像)
默認內容 (squashfs)

塊計數(block_count )爲閃存中128k塊的序數。(見上面bbm命令顯示的分區輸出內容)

id爲129,被認爲是shell的腳步本,是可以執行的.
id爲128, 除了做md5校驗沒有別的用處。

我編了一個Python腳步本來編譯我的update文件, 並自動的加上校驗值。下一次將會公佈。

要進行更新,首先必需把更新文件放在Kindle的USB盤的根目錄或者SD/MMC卡上。然後按HOME鍵,重啓Kindle,這樣你就會看到下面的菜單:

破解kindle--第二部分:啓動加載和固件的更新

2、"Firmware Reset" 命令會清除所有的用戶定義和設置數據,恢復Kindle的出廠狀態。我不肯定如果沒有Kndle技術人員另外的初始化是不是能用。

3、"Exit"會開始正常的啓動進程。

0(不顯示)開始啓動加載診斷。交互式的在控制檯上,Kindle屏上看不到這些 。

1"Firmware update"開始一個手動的更新進程。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章