blob: c8799c6ab1a25689a921d2b6e57aa05e05295df9 [file] [log] [blame]
Mike Dunn0dc0e842013-06-18 11:08:50 -07001
2README for the Palm Treo 680.
3
4Copyright (C) 2013 Mike Dunn <mikedunn@newsguy.com>
5
6You may reproduce the contents of this file entirely or in part, but please
7credit me by name if you do. Thanks.
8
9
10Intro
11=====
12
13Yes, you can program u-boot onto the flash of your Palm Treo 680 so that u-boot
14(then Linux, Android, ...) runs at power-up. This document describes how, and
15gives some implementation details on this port of u-boot and describes how the
16Treo 680 boots from reset.
17
18But first, I probably don't need to tell you that after doing this, your phone
19will no longer run PalmOS. You *may* be able to later restore your phone to its
20original state by creating a backup image of the flash before writing u-boot
21(details below), but this is not heavily tested and should not be relied upon.
22There is also the possibility that something may go wrong during the process of
23programming u-boot, leaving you with a bricked phone. If you follow these
24instructions carefully this chance will be minimized, but I do not recommend
25that you program u-boot onto a phone that you can not afford to lose, and
26certainly not one that contains important data that is not backed up elsewhere.
27I AM NOT RESPONSIBLE FOR THE LOSS OF YOUR PHONE. DO THIS AT YOUR OWN RISK.
28Having said that, feel free to send me a note cursing me out if something does
29go wrong, but please tell me what happened exactly. For that matter, I'd love
30to hear from you if you succeed.
31
32
Mike Dunn0dc0e842013-06-18 11:08:50 -070033Details on the SPL
34==================
35
36The docg4 features a 2k region at the start of its address space that interfaces
37to the system bus like a NOR flash. This allows the docg4 to function as a boot
38ROM. The Treo 680 uses this feature. The contents of this 2k region are
39write-protected and can not be reprogrammed. Fortunately, the code it contains
40does what we need to do, at least partially. After some essential hardware
41initialization (like the SDRAM controller), it runs an IPL (initial program
42loader) that copies 128K (no more, no less) from flash to a fixed address in
43SDRAM (0xa1700000) and jumps to it. 128K is too small for u-boot, so we use it
44to load a u-boot secondary program loader (SPL). But since our SPL only
45occupies a little over 1k, we can economize on flash usage by having the IPL
46load a portion of u-boot proper as well. We let the IPL load the first 128k of
47a concatenated spl + u-boot image, and because the SPL is placed before u-boot
48proper, the IPL jumps to the SPL, which copies the portion of u-boot that the
49IPL has already loaded to its correct SDRAM address, and then loads the
50remainder of u-boot and jumps to it.
51
52
Mike Dunn0dc0e842013-06-18 11:08:50 -070053The docg4's "reliable mode"
54===========================
55
56This is a special mode of operation of the docg4's integrated controller whereby
57consecutive pairs of 2k regions are used in parallel (in some fashion) to store
582k of data. In other words, the normal capacity is halved, but the data
59integrity is improved. In this mode, the data is read or written from pages in
60even-numbered 2k regions (regions starting at 0x000, 0x1000, 0x2000, ...). The
61odd-numbered 2k regions (regions starting at 0x800, 0x1800, 0x2800, ...) are
62transparently used in parallel. In reliable mode, the odd-numbered 2k regions
63are not meant to be read or written directly.
64
65Reliable mode is used by the IPL because there is not enough space in its 2k
66footprint to implement the BCH ecc algorithm. Data that is read while reliable
67mode is enabled must have been written in reliable mode, or the read fails.
68However, data written in reliable mode can also be read in normal mode (just not
69as reliably), but only from the even-numbered 2k regions; the odd-numbered 2k
70regions appear to contain junk, and will generate ecc errors. When the IPL and
71SPL read from flash, the odd-numbered 2k regions are explicitly skipped. The
72same is true for the flash_u-boot utility when it writes the u-boot image in
73reliable mode.
74
75The docg4 Linux driver supports writing in reliable mode (it is enabled by the
76module parameter), but not reading. However, the u-boot docg4_spl driver does
77read in reliable mode, in the same fashion as the IPL.
78
79
Mike Dunn0dc0e842013-06-18 11:08:50 -070080Details on the IPL and its data format
81======================================
82
83Starting from block 5 and counting upward, the IPL will search for and load the
84first two blocks it finds that contain a magic number in the oob of the first
85page of the block. The contents are loaded to SDRAM starting at address
860xa1700000. After two blocks have been loaded, it jumps to 0xa1700000. The
87number of blocks loaded and the load address in SDRAM are hard-coded; only the
88flash offset of the blocks can vary at run-time (based on the presence of the
89magic number).
90
91In addition to using the docg4's reliable mode, the IPL expects each 512 byte
92page to be written redundantly in the subsequent page. The hardware is capable
93of detecting bit errors (but not correcting them), and if a bit error is
94detected when a page is read, the page contents are discarded and the subsequent
95page is read.
96
97Reliable mode reduces the capacity of a block by half, and the redundant pages
98reduce it by half again. As a result, the normal 256k capacity of a block is
99reduced to 64k for the purposes of the IPL/SPL.
100
101For the sake of simplicity and uniformity, the u-boot SPL mimics the operation
102of the IPL, and expects the image to be stored in the same format.
103
104
Mike Dunn0dc0e842013-06-18 11:08:50 -0700105Instructions on Programming u-boot to flash
106===========================================
107
108To program u-boot to your flash, you will need to boot the Linux kernel on your
109phone using a PalmOS bootloader such as cocoboot. The details of building and
110running Linux on your Treo (cross-compiling, creating a root filesystem,
111configuring the kernel, etc) are beyond the scope of this document. The
112remainder of this document describes in detail how to program u-boot to the
113flash using Linux running on the Treo.
114
115
Mike Dunn0dc0e842013-06-18 11:08:50 -0700116Hardware Prerequisites
117======================
118
119A Palm Treo 680:
120 (dugh)
121
122A Palm usb cable:
123 You'll need this to establish a usbtty console connection to u-boot from a
124 desktop PC. Currently there is no support in u-boot for the pxa27x keypad
125 (coming soon), so a serial link must be used for the console.
126 These cables are still widely available if you don't already have one.
127
128A Linux desktop PC.
129 You may be able to use Windows for the u-boot console if you have a usb driver
130 that is compatible with the Linux usbserial driver, but for programming u-boot
131 to flash, you'll really want to use a Linux PC.
132
133
Mike Dunn0dc0e842013-06-18 11:08:50 -0700134Treo-side Software Prerequisites
135================================
136
137Linux bootloader for PalmOS:
138
139 Cocoboot is the only one I'm aware of. If you don't already have this, you
140 can download it from
141 https://download.enlightenment.org/misc/Illume/Treo-650/2008-11-13/sdcard-base.tar.gz
142 which is a compressed tar archive of the contents of an sd card containing
143 cocoboot. Use mkdosfs to create a fat16 filesystem on the first primary
144 partition of the card, mount the partition, and extract the tar file to it.
145 You will probably need to edit the cocoboot.conf file to customize the
146 parameters passed to the kernel.
147
148
Mike Dunn0dc0e842013-06-18 11:08:50 -0700149Linux kernel:
150
151 The kernel on the Treo 680 is still a little rough around the edges, and the
152 official kernel frequently breaks on the Treo :( A development kernel
153 specifically for the Treo 680 can be found on github:
154 http://github.com/mike-dunn/linux-treo680
155 The master branch of this tree has been tested on the Treo, and I recommend
156 using this kernel for programming u-boot. As of this writing, there may be a
157 bug in the docg4 nand flash driver that sometimes causes block erasures to
158 fail. This has been fixed in the above tree.
159
160 If you choose to use the official kernel, it must contain the docg4 driver that
161 includes the reliable_mode module parameter. This was a later enhancement to
162 the driver, and was merged to the kernel as of v3.8. Do not try to use an
163 earlier kernel that contains the docg4 driver without support for writing in
164 reliable mode. If you try to program u-boot to flash with the docg4 driver
165 loaded without the reliable_mode parameter enabled, you *will* brick your
166 phone!
167
168 For the purpose of programming u-boot to flash, the following options must be
169 enabled in the Treo kernel's .config:
170
171 CONFIG_MTD=y
172 CONFIG_MTD_CMDLINE_PARTS=y
173 CONFIG_MTD_CHAR=y
174 CONFIG_MTD_NAND_DOCG4=m
175
176 Note that the docg4 nand driver is configured as a module, because we will
177 want to load and unload it with reliable_mode enabled or disabled as needed.
178
179 You will also need to specify mtd partitions on the kernel command line. In
180 the instructions that follow, we will assume that the flash blocks to which
181 u-boot will be programmed are defined by the second partition on the device.
182 The u-boot config file (include/configs/palmtreo680.h) places the u-boot image
183 at the start of block 6 (offset 0x180000), which is the first writable
184 (non-protected) block on the flash (this is also where the PalmOS SPL starts).
185 The u-boot image occupies four blocks, so to create the u-boot partition, pass
186 this command line to the kernel:
187 mtdparts=Msys_Diskonchip_G4:1536k(protected_part)ro,1024k(bootloader_part),-(filesys_part)
188 This will create three partitions:
189 protected_part: the first six blocks, which are read-only
190 bootloader_part: the next four blocks, for the u-boot image
191 filesys_part: the remainder of the device
192 The mtdchar kernel device driver will use device nodes /dev/mtd0, /dev/mtd1,
193 and /dev/mtd2 for these partitions, respectively. Ensure that your root file
194 system at least has /dev/mtd1 if you are not running udev or mdev.
195
Mike Dunn0dc0e842013-06-18 11:08:50 -0700196Userspace Utilities:
197
198 In addition to everything necessary to provide a useful userspace environment
199 (busybox is indispensable, of course), you will need the mtd-utils package on
200 your root filesystem. I use version 1.5.0 of mtd-utils, and I suggest you use
201 this version as well, or at leat a version very close to this one, as
202 mtd-utils has tended to be fluid.
203
204 Note that busybox includes a version of mtd-utils. These are deficient and
205 should not be used. When you run one of these utilities (nanddump, etc),
206 ensure you are invoking the separate executable from mtd-utils, and not the
207 one built into busybox. I recommend that you configure busybox with its
208 mtd-utils disabled to avoid any possibility of confusion.
209
210 You will also need to cross-compile the userspace Linux utility in
211 tools/palmtreo680/flash_u-boot.c, which we will run on the Treo to perform the
212 actual write of the u-boot image to flash. This utility links against libmtd
213 from the mtd-utils package.
214
215
Mike Dunn0dc0e842013-06-18 11:08:50 -0700216Desktop PC-side Software Prerequisites
217======================================
218
219Terminal emulator application:
220 minicom, kermit, etc.
221
Mike Dunn0dc0e842013-06-18 11:08:50 -0700222Linux kernel:
223 Compiled with CONFIG_USB_SERIAL enabled. Build this as a module.
224
225
Mike Dunn0dc0e842013-06-18 11:08:50 -0700226Recommended (Not directly related to u-boot)
227============================================
228
229Working directly on the Treo's tiny screen and keypad is difficult and
230error-prone. I recommend that you log into the Linux kernel running on your
231Treo from your desktop PC using ethernet over usb. The desktop's kernel must be
232configured with CONFIG_USB_USBNET, CONFIG_USB_NET_CDCETHER, and
233CONFIG_USB_NET_CDC_SUBSET. The Treo's kernel will need CONFIG_USB_ETH, and its
234init script will need to start an ssh daemon like dropbear. Note that the usb0
235network interface will not appear on the desktop PC until the Treo kernel's usb
236ethernet gadget driver has initialized. You must wait for this to occur (watch
237the PC's kernel log) before you can assign usb0 an ip address and log in to the
238Treo. If you also build the Treo's kernel with CONFIG_IP_PNP enabled, you can
239pass its ip address on the kernel command line, and obviate the need to
240initialize the network interface in your init script.
241
242Having the Palm usb cable connected to the host has the added benefit of keeping
243power supplied to your Treo, reducing the drain on the battery. If something
244goes wrong while you're programming u-boot to the flash, you will have lots of
245time to correct it before the battery dies.
246
247I have encountered a situation where the kernel is sometimes unable to mount a
248root filesystem on the mmc card due to the mmc controller not initializing in
249time, (and CONFIG_MMC_UNSAFE_RESUME doesn't seem to help) so I recommend that
250you build a minimal root filesystem into the kernel using the kernel's initramfs
251feature (CONFIG_BLK_DEV_INITRD). If you want your root filesystem on the mmc
252card, your init script can mount and switch_root to the mmc card after a short
253sleep. But keep in mind that in this case you won't be able to use an mmc card
254to transfer files between your desktop and the Treo once Linux is running.
255Another option for transfering files is to mount an nfs filesystem exported by
256the desktop PC. For greatest convenience, you can export the root filesystem
257itself from your desktop PC and switch_root to it in your init script. This
258will work if your initramfs init script contains a loop that waits for you to
259initialize the usb0 network interface on the desktop PC; e.g., loop while a ping
260to the desktop PC returns an error. After the loop exits, do the nfs mount and
261call switch_root. (You can not use the kernel nfsroot feature because the
262network will not be up when the kernel expects it to be; i.e., not until you
263configure the usb0 interface on the desktop.) Use the nfs 'nolock' option when
264mounting to avoid the need to run a portmapper like rpcbind.
265
266
Mike Dunn0dc0e842013-06-18 11:08:50 -0700267Preliminaries
268=============
269
270Once Linux is running on your Treo, you may want to perform a few sanity checks
271before programming u-boot. These checks will verify my assumptions regarding
272all the Treo 680s out there, and also ensure that the flash and mtd-utils are
273working correctly. If you are impatient and reckless, you may skip this
274section, but see disclaimer at the top of this file!
275
276Load the docg4 driver:
277
278 $ modprobe docg4 ignore_badblocks=1 reliable_mode=1
279
280We tell the driver to use the docg4's "reliable mode" when writing because this
281is the format required by the IPL, which runs from power-up and loads the first
282portion of u-boot. We must ignore bad blocks because linux mtd uses out-of-band
283(oob) bytes to mark bad blocks, which will cause the blocks written by PalmOS to
284be misidentified as "bad" by libmtd.
285
286Check the kernel log to ensure that all's well:
287
288 $ dmesg | tail
289 <... snip ...>
290 docg4 docg4: NAND device: 128MiB Diskonchip G4 detected
291 3 cmdlinepart partitions found on MTD device Msys_Diskonchip_G4
292 Creating 3 MTD partitions on "Msys_Diskonchip_G4":
293 0x000000000000-0x000000180000 : "protected_part"
294 0x000000180000-0x000000280000 : "bootloader_part"
295 0x000000280000-0x000008000000 : "filesys_part"
296
297Ensure that the partition boundaries are as shown. (If no partitions are shown,
298did you remember to pass them to the kernel on the command line?) We will write
299u-boot to bootloader_part, which starts at offset 0x180000 (block 6) and spans 4
300256k blocks. This partition is accessed through the device node /dev/mtd1.
301
302The docg4 contains a read-only table that identifies blocks that were marked as
303bad at the factory. This table is in the page at offset 0x2000, which is within
304the partition protected_part (/dev/mtd0). There is a slight chance that one or
305more of the four blocks that we will use for u-boot is listed in the table, so
306use nanddump to inspect the table to see if this is the case:
307
308 $ nanddump -p -l 512 -s 0x2000 -o /dev/mtd0
309 ECC failed: 0
310 ECC corrected: 0
311 Number of bad blocks: 0
312 Number of bbt blocks: 0
313 Block size 262144, page size 512, OOB size 16
314 Dumping data starting at 0x00002000 and ending at 0x00002200...
315 0x00002000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
316 <... snip ...>
317
318The format of the table is simple: one bit per block, with block numbers
319increasing from left to right, starting with block 0 as the most significant bit
320of the first byte. A bit will be clear if the corresponding block is bad. We
321want to use blocks 6 throgh 9, so both of the two least significant bits of the
322first byte must be set, as must the two most significant bits of the second
323byte. If this is not true in your case (you are very unlucky), you should use
324the first contiguous set of four good blocks after block 6, and adjust the
325partition boundaries accordingly. You will also have to change the value of
326CONFIG_SYS_NAND_U_BOOT_OFFS in include/configs/palmtreo680.h and recompile
327u-boot. Because the two blocks loaded by the IPL do not have to be contiguous,
328but our SPL expects them to be, you will need to erase any good blocks that are
329at an offset prior to CONFIG_SYS_NAND_U_BOOT_OFFS, so that the IPL does not find
330the magic number in oob and load it. Once you have done all this, the
331instructions in this file still apply, except that the instructions below for
332restoring the original PalmOS block contents may need to be modified.
333
334Next, use nanddump to verify that the PalmOS SPL is where we expect it to be.
335The SPL can be identified by a magic number in the oob bytes of the first page
336of each of the two blocks containing the SPL image. Pages are 512 bytes in
337size, so to dump the first page, plus the oob:
338
339 $ nanddump -p -l 512 -s 0 -o /dev/mtd1
340 ECC failed: 0
341 ECC corrected: 0
342 Number of bad blocks: 0
343 Number of bbt blocks: 0
344 Block size 262144, page size 512, OOB size 16
345 Dumping data starting at 0x00000000 and ending at 0x00000200...
346 0x00000000: 0a 00 00 ea 00 00 00 00 00 00 00 00 00 00 00 00
347 <... snip ...>
348 0x000001f0: 13 4c 21 60 13 4d 2a 69 13 4b 29 69 89 1a 99 42
349 OOB Data: 42 49 50 4f 30 30 30 10 3a e2 00 92 be a0 11 ff
350
351Verify that the first seven bytes of oob data match those in the above line.
352(This is ASCII "BIPO000".)
353
354Do the same for the next block:
355 $ nanddump -p -l 512 -s 0x40000 -o /dev/mtd1
356
357The first seven oob bytes in last line should read:
358
359 OOB Data: 42 49 50 4f 30 30 31 81 db 8e 8f 46 07 9b 59 ff
360
361(This is ASCII "BIPO001".)
362
363For additional assurance, verify that the next block does *not* contain SPL
364data.
365
366 $ nanddump -p -l 512 -s 0x80000 -o /dev/mtd1
367
368It doesn't matter what the oob contains, as long as the first four bytes are
369*not* ASCII "BIPO". PalmOS should only be using two blocks for the SPL
370(although we will need four for u-boot).
371
372If you want, you can back up the contents of bootloader_part to a file. You may
373be able to restore it later, if desired (see "Restoring PalmOS" below).
374
375 $ nanddump -l 0x100000 -s 0 -o -f bootloader_part.orig /dev/mtd1
376
377nanddump will spew voluminous warnings about uncorrectable ecc errors. This is
378a consequence of reading pages that were written in reliable mode, and is
379expected (these should all occur on pages in odd-numbered 2k regions; i.e.,
3800x800, 0xa00, 0xc00, 0xe00, 0x1800, 0x1a00, ...). The size of the file
381bootloader_part.orig should be 1081344, which is 2048 pages, each of size 512
382plus 16 oob bytes. If you are using initramfs for the root filesystem, don't
383forget to copy the file to permanent storage, such as an mmc card.
384
385If all of the above went well, you can now program u-boot.
386
387
Mike Dunn0dc0e842013-06-18 11:08:50 -0700388Programming u-boot
389==================
390
391Our u-boot includes a small SPL that must be prepended to u-boot proper. From
392the base u-boot source directory on your desktop PC:
393
394 $ cat spl/u-boot-spl.bin u-boot.bin > u-boot-concat.bin
395
396cd to the tools/palmtreo680/ directory, and cross-compile flash_u-boot.c for the
397Treo:
398
399 $(CC) -o flash_u-boot $(CFLAGS) $(INCLUDEPATH) $(LIBPATH) flash_u-boot.c -lmtd
400
401Substitute variable values from your cross-compilation environment as
402appropriate. Note that it links to libmtd from mtd-utils, and this must be
403included in $(LIBPATH) and $(INCLUDEPATH).
404
405Transfer u-boot-concat.bin and the compiled flash_u-boot utility to the Treo's
406root filesystem. On the Treo, cd to the directory where these files were
407placed.
408
409Load the docg4 driver if you have not already done so.
410
411 $ modprobe docg4 ignore_badblocks=1 reliable_mode=1
412
413Erase the blocks to which we will write u-boot:
414
415 $ flash_erase /dev/mtd1 0x00 4
416
417If no errors are reported, write u-boot to the flash:
418
419 $ ./flash_u-boot u-boot-concat.bin /dev/mtd1
420
421You can use nanddump (see above) to verify that the data was written. This
422time, "BIPO" should be seen in the first four oob bytes of the first page of all
423four blocks in /dev/mtd1; i.e., at offsets 0x00000, 0x40000, 0x80000, 0xc0000.
424
425Shutdown linux, remove and re-insert the battery, hold your breath...
426
427
Mike Dunn0dc0e842013-06-18 11:08:50 -0700428Enjoying u-boot
429===============
430
431After you insert the battery, the u-boot splash screen should appear on the lcd
432after a few seconds. With the usb cable connecting the Treo to your PC, in the
433kernel log of your PC you should see
434
435 <6>usb 3-1: New USB device found, idVendor=0525, idProduct=a4a6
436 <6>usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
437 <6>usb 3-1: Product: U-Boot 2013.01-00167-gd62ef56-dirty
438 <6>usb 3-1: Manufacturer: Das U-Boot
439
440Load the usbserial module on your desktop PC:
441
442 $ modprobe usbserial vendor=0x0525 product=0xa4a6
443
444and run your favorite terminal emulation utility (minicom, kermit, etc) with the
445serial device set to /dev/ttyUSB0 (assuming this is your only usb serial
446device). You should be at the u-boot console (type 'help').
447
448There is not much that is unique about using u-boot on the palm treo 680.
449Kernels can be loaded from mmc, flash, and from the desktop PC via kermit. You
450can expand the size of the second partition on the flash to contain a kernel, or
451else put the kernel(s) in their own partition.
452
453Nand commands work as expected, with the excepton that blocks not written by the
454linux mtd subsystem may be misidentified by the u-boot docg4 driver as "bad" if
455they contain data in the oob bytes. This will be the case for the blocks
456containing the u-boot image, for example. To work around this, use 'nand scrub'
457instead of 'nand erase' to erase these blocks, and 'nand read.raw' to read them
458to memory. (It would be useful if u-boot's nand commands provided a way to
459explicitly ignore "bad" blocks, because read.raw does not perform ecc.) The
460'nand dump' command will read these "bad" blocks, however.
461
462Currently u-boot itself can only be programmed to flash from Linux; there is no
463support for reliable mode in u-boot's docg4 flash driver. This should be
464corrected soon.
465
466
Mike Dunn0dc0e842013-06-18 11:08:50 -0700467Customizing
468===========
469
470If you change u-boot's configuration significantly (adding or removing
471features), you may have to adjust the value of CONFIG_SYS_NAND_U_BOOT_SIZE.
472This is the size of the concatenated spl + u-boot image, and tells the SPL how
473many flash blocks it needs to load. It will be rounded up to the next 64k
474boundary (the spl flash block capacity), so it does not have to be exact, but
475you must ensure that it is not less than the actual image size. If it is larger
476than the image, blocks may be needlessly loaded, but if too small, u-boot may
477only be partially loaded, resulting in a boot failure (bricked phone), so better
478to be too large. The flash_u-boot utility will work with any size image and
479write the required number of blocks, provided that the partition is large
480enough.
481
482As the first writable block on the device, block 6 seems to make the most sense
483as the flash offset for writing u-boot (and this is where PalmOS places its
484SPL). But you can place it elsewhere if you like. If you do, you need to
485adjust CONFIG_SYS_NAND_U_BOOT_OFFS accordingly, and you must ensure that blocks
486preceeding the ones containing u-boot do *not* have the magic number in oob (the
487IPL looks for this). In other words, make sure that any blocks that previously
488contained the u-boot image or PalmOS SPL are erased (and optionally written with
489something else) so that the IPL does not load it. Also make sure that the new
490u-boot starting offset is at the start of a flash partition (check the kernel
491log after loading the docg4 driver), and pass the corresponding mtd device file
492to the flash_u-boot utility.
493
494The u-boot built-in default environment is used because a writable environment
495in flash did not seem worth the cost of a 256k flash block. But adding this
496should be straightforward.
497
498
Mike Dunn0dc0e842013-06-18 11:08:50 -0700499Restoring PalmOS
500================
501
502If you backed up the contents of bootloader_part flash partition earlier, you
503should be able to restore it with the shell script shown below. The first two
504blocks of data contain the PalmOS SPL and were written in reliable mode, whereas
505the next two blocks were written in normal mode, so the script has to load and
506unload the docg4 driver. Make sure that the mtd-utils nandwrite and flash_erase
507are in your path (and are not those from busybox). Also double-check that the
508backup image file bootloader_part.orig is exactly 1081344 bytes in length. If
509not, it was not backed up correctly. Run the script as:
510
511 ./restore_bootpart bootloader_part.orig /dev/mtd1
512
513The script will take a minute or so to run. When it finishes, you may want to
514verify with nanddump that the data looks correct before you cycle power, because
515if the backup or restore failed, your phone will be bricked. Note that as a
516consequence of reliable mode, the odd-numbered 2k regions in the first two
517blocks will not exactly match the contents of the backup file, (so unfortunately
518we can't simply dump the flash contents to a file and do a binary diff with the
519original back-up image to verify that it was restored correctly). Also,
520nanddump will report uncorrectable ecc errors when it reads those regions.
521
522#!/bin/sh
523
524if [ $# -ne 2 ]; then
525 echo "usage: $0: <image file> <mtd device node>"
526 exit 1
527fi
528
529# reliable mode used for the first two blocks
530modprobe -r docg4
531modprobe docg4 ignore_badblocks=1 reliable_mode=1 || exit 1
532
533# erase all four blocks
534flash_erase $2 0 4
535
536# Program the first two blocks in reliable mode.
537# 2k (4 pages) is written at a time, skipping alternate 2k regions
538# Note that "2k" is 2112 bytes, including 64 oob bytes
539file_ofs=0
540flash_ofs=0
541page=0
542while [ $page -ne 1024 ]; do
543 dd if=$1 bs=2112 skip=$file_ofs count=1 | nandwrite -o -n -s $flash_ofs $2 - || exit 1
544 file_ofs=$((file_ofs+2))
545 flash_ofs=$((flash_ofs+0x1000))
546 page=$((page+8))
547done;
548
549# normal mode used for the next two blocks
550modprobe -r docg4
551modprobe docg4 ignore_badblocks=1 || exit 1
552dd if=$1 bs=1 skip=$file_ofs count=540672 | nandwrite -o -n -s 0x80000 $2 - || exit 1
553modprobe -r docg4
554
Mike Dunn0dc0e842013-06-18 11:08:50 -0700555TODO
556====
557
558 - Keypad support.
559 - Interactive boot menu using keypad and lcd.
560 - Add reliable mode support to the u-boot docg4 driver.
561 - U-boot command that will write a new image to the bootloader partition in
562 flash.
563 - Linux FTD support.