Didj U Boot Flashing Primer

This primer walks through the basics of the nand command in u-boot and shows how to use it to write a new bootloader.

Programs Needed
A serial terminal program, e.g. Hyperterminal in windows or CuteCom in Linux.

Hardware Needed
UART connection

Caution
This material can brick your Didj

While it is possible to still boot with a bad NAND, keep in mind that following the instructions in here there is a very slight, but real, possibility your Didj will never boot normally again. Follow these instructions at your own peril.

The nand command
u-boot provides a single command for interfacing with your nand part. It is important to keep in mind when using these commands that 'all values are given in hex, not decimal The general format of the nand command is:

Some of the commands whose functions are understood are listed below.

nand dump
You can dump pages (2K of data) using the nand dump command. The format of the command is

Here is an example of using nand dump:

LF1000 # nand dump 0 Page 00000000 dump: 04 d0 9f e5 01 00 00 eb 6c 0b 00 ea 00 80 22 00 34 c0 9f e5 01 30 a0 e3 00 30 8c e5 08 30 9c e5     02 0b a0 e3 04 e0 2d e5  80 30 83 e3 00 e0 a0 e3

nand read
You can read data from the nand into memory using the nand read command. The format of the command is

Example:

LF1000 # nand read 1800000 0 800 NAND read: device 0 offset 0x0, size 0x800 2048 bytes read: OK LF1000 # md 1800000 10 01800000: e59fd004 eb000001 ea000b6c 00228000   ........l.....". 01800010: e59fc034 e3a03001 e58c3000 e59c3008    4....0...0...0.. 01800020: e3a00b02 e52de004 e3833080 e3a0e000    ......-..0...... 01800030: e1a01000 e3a02b7e e58c3008 e58ce008    ....~+...0......

Comparison of this to the nand dump command above will show that these are the same data. Not that md has dumped the data in little endian format.

nand erase
Disclaimer: This will really erase one or more pages of your nand. Make sure you think this through before doing it.

The nand erase command will reset a range of your nand to its unwritten state. In flash parts, such as Didj, this means all data within an erased page will become. The format of the command is:

Example:

LF1000 # nand erase 0 4000 NAND erase: device 0 offset 0x0, size 0x4000 Erasing at 0x0 -- 800% complete. OK LF1000 # nand dump 0 Page 00000000 dump: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff     ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff

It is also important to understand that flash parts cannot erase less than one page. Either the whole page will be erased, or it will not. the size of your erasure should be a multiple of 0x800. In this case I have erased the first 16K of nand, which is where the bootstrap lives.

nand write
Disclaimer: This will write one or more pages to your nand. If those pages have not been erased first, the results will not be what you expect. See disclaimer in the erase nand section.

The nand write command will write a range of pages to your Didj's nand. In flash parts, bits can only be changed from 1 to 0. Therefore it is important to erase the block before you write it. The format of the command is

Example:

LF1000 # nand write 1800000 0 4000 NAND write: device 0 offset 0x0, size 0x4000 16384 bytes written: OK

Note that you need to have the data you wish to write already in memory. In the example this data is 16Kbytes starting at physical address 0x1800000.

Putting it all together
This section describes using u-boot to flash a new boot loader to your Didj.

Final Warning
This may prevent your Didj from ever booting normally again. It is extremely unlikely this will happen. Proceed from here at your own risk.

What you need

 * A UART connection to your Didj (required)
 * An SD cartridge (optional)
 * A NAND-compatible lightning-boot (this is not the same as the UART lightning-boot you probably just used)

Step 1: Acquire a bootloader
You will need to get the OpenDidj lightning-boot 1.4 (or later) NAND image. You can get the latest version from the OpenDidj lightning-boot hackerfoundry thread(dead link).

Run the following command on your linux box to double check which lightning-boot you have:

00000000 00 00 00 ea 55 41 52 54  04 d0 9f e5 01 00 00 eb  |....UART........| 00000010
 * 1) hexdump -C -n 16 lightning-boot.bin

If your output looks like the above STOP. You have the UART bootloader. If instead it says NAND, then you may proceed. Only lightning-boot 1.4 and later come in UART and NAND flavors and have the identification string as above. Lightning-boot 1.3 and earlier are all UART only. Do NOT flash lightning-boot 1.3 or earlier.

Step 1a: Put your bootloader on your SD card
If you have an SD-capable cartridge, copy the NAND-enabled lightning-boot.bin to the cartridge now.

Step 2: Boot to u-boot
TODO: Put a link to the boot page here

Do not load the kernel image in u-boot, we will not need it here.

Step 3a: Using SD/MMC
Initialize the MMC subsystem...

LF1000 # mmcinit SD ver 2.0 SD found : Size = 3866624 KBytes

and load lightning-boot.bin into memory.

LF1000 # fatload mmc 0 1800000 lightning-boot.bin reading lightning-boot.bin Why block_cnt == 0?? 16384 bytes read

It is not understood why the "Why block_cnt == 0??" message shows up, but all of the data will be correctly loaded into memory.

Step 3b: Using loadb
Alternatively you can use loadb to load lightning-boot.bin into memory using the kermit protocol. This process is not yet documented.

Step 4: Erase the first bootloader pages
Use  to erase the bootloader pages

LF1000 # nand erase 0 8000 NAND erase: device 0 offset 0x0, size 0x8000 Erasing at 0x0 -- 400% complete. OK

You may use  to verify that the bootloader page is now all.

Step 5: Write lightning-boot
Use  to write your new lightning-boot to flash.

LF1000 # nand write 1800000 0 8000 NAND write: device 0 offset 0x0, size 0x8000 32768 bytes written: OK

You should use  to verify that lightning-boot was written.

Step 6: Cross fingers, reboot
At this point you should be ready to boot using your new bootloader. Remove the UART-boot jumper and type  in u-boot and see what happens.