Difference between revisions of "Leapster Explorer: UART Boot"

From eLinux.org
Jump to: navigation, search
(Bootloader)
Line 49: Line 49:
 
== Bootloader ==
 
== Bootloader ==
  
Technically this isn't a UART boot, what will be happening is, once Emerald Boot is compiled, the Micromon application will be used to load the bin file onto the LX in RAM, where Micromon will then execute the code and start Emerald Boot loading. The reason for this is Emerald Boot is too big to load over UART since it can range from 40 to 80+KB in size, and the Pollux SoC will start running the code sent to it over UART at 16KB. Lightning boot on the other hand, easily meets the 16KB limit and will often times need extra padding to trigger the Pollux UART boot start up.
+
Technically this isn't a UART boot, what will be happening is, once Emerald Boot is compiled, the Micromon application will be used to load the bin file onto the LX in RAM, where Micromon will then execute the code and start Emerald Boot loading. The reason for this is Emerald Boot is too big to load over UART since it can range from 40 to 200+KB in size, and the Pollux SoC will start running the code sent to it over UART at 16KB.  
  
To get started, get yourself the Emerald Boot source linked above, the Micromon program, the Emerald Boot Fixups and the devroot environment. Devroot sets up the codesourcery build environment, if you know what you are doing with such things, you can venture out on your own, but I highly recommend devroot, as it takes all the guess work out of it, and makes life rather simple in this regard. Once devroot and Micromon are set up, you can get to working on Emerald Boot, you will need these environment variables set, I put them in a file, and run source My_Env_Vars when I need them from the devroot shell.
+
'''Compiling'''
 
export ARCH=arm
 
export TARGET_MACH=LF_TS_LF1000
 
  
export KERNELDIR=~/path/to/sources/kernel/linux-2.6
+
This works with the RidgeRun toolchain and on the LF-Linux-8291-20101026-1425.tar.gz sources, it may work with others toolchains and source version, but is as of yet untested. It also requires that you have built the LF-Linux kernel, as Emerald Boot draws a few files from it.  
  
export PROJECT_PATH=~/path/to/sources
+
Extract the emerald-boot-supplement archive. Make sure you have a clean copy of the emerald-boot/ directory in the LF-Source tree.
  
export ROOTFS_PATH=~/path/to/sources/target/didj-rootfs
+
Next apply the patch which makes the necessary modifications for UART booting, along with a few other mods to make things a bit more friendly.
export RELEASE_PATH=~/path/to/sources/target/release
 
export TFTP_PATH=~/path/to/sources/target/tftp
 
export EROOTFS_PATH=~/path/to/sources/target/erootfs.stage
 
  
if you move your emerald-boot/ you may need to change a few of these. You will also need to have compiled the LX kernel in the source tree, as Emerald Boot draws a few things from it. It doesn't have to be a working one so much as just a run through the compiling process. [[Didj_Build_Environment | Build Environments]] is a good place to get started on how to build a kernel.
+
Copy screens/ to the packages/ directory in the source tree.
  
Next take the fixup archive and extract it, screens/ should go in the source directory packages/ host_tools should be in the directory above emerald-boot, and copy dump32.py into your emerald-boot folder. If you are building the first version of Emerald Boot you can copy in the makefile into emerald-boot/, if its a newer version, do not, as some things have changed.
+
Copy host_tools/ to the root directory along side emerald-boot and packages. If you want you can make your own, just save them as png. Although they only get used when Emerald Boot is in USB boot mode.
  
First off change
+
Inside the emerald-boot/ directory apply the patch.
  CFLAGS += -I$(KERNELDIR)/arch/arm/mach-lf1000/include -I$(KERNELDIR)/include/linux
 
to this
 
  CFLAGS += -I$(KERNELDIR)/arch/arm/mach-lf1000/include -I$(KERNELDIR)/include/linux -I$(KERNELDIR)/include -I$(KERNELDIR)/arch/arm/include
 
And at the top of the file in the CFLAGS string remove -Werror and -DSELF_BOOTSTRAP
 
  
I also added in this in the file to make it easier to compile a UART version or a normal version
+
  $ patch -p1 < /path/to/emerald-boot-supplement.patch
# Boot using Micromon, turn bootstrap off
 
ifneq ($(MICRO_BOOT),)
 
CFLAGS += -DMICRO_BOOT
 
else
 
CFLAGS += -DSELF_BOOTSTRAP
 
endif
 
  
This will put the necessary SELF_BOOSTRAP flag back in, when not being booted over UART.
+
To compile the bootloader run
 +
  $ OPTION=1 ./install.sh
  
This leaves one final file to change and we are ready to compile. Open startUp.S from emerald-boot/ and you will need to include this code in two places. This code will set a register bit that tells the system where certain parts of the memory can be accessed, this changes regarding if Emerald Boot was booted from NOR or NAND/UART, for some reason this doesn't get set right, so we need to do it this way.
+
Some OPTION values include MICRO_BOOT for UART enabling, SDCARD for booting a kernel off an SD card, and DEBUG which puts out some extra info in the console which is nice for bootloader testing.
  
  #ifdef MICRO_BOOT
+
example for UART booting and Debugging
    // Sets NFCONTROL bit NFBOOTENB, Doesn't seem to get set
 
    //  when put into UART/NAND boot mode, so must manually do it
 
    ldr r3, =0xC0015874  // Loads NFCONTROL's address into R3
 
    ldr r2, [r3]          // Fetch NFCONTROL's value
 
    orr r2, r2, #0x020  // Set Bit5
 
    str r2, [r3]          // Store the value back to NFCONTROL
 
  #endif
 
  
Include this snippet right after the IRQHandler: label and after the #endif directly following the line iputc   #'^' around line 355 or so. You should be all set to compile now.
+
   $ MICRO_BOOT=1 DEBUG=1 ./install.sh
  
Open up a terminal, then run ./devroot-dir/devroot/usr/bin/shell and then put in your environment variables, navigate to the emerald-bin folder and run
+
'''UART Booting'''
   DEBUG=1 MICRO_BOOT=1 ./install.sh -c
+
 
that will give some debug info on the terminal, make it UART bootable, and do a clean build. Open up another terminal and go to your micromon directory. Make sure you've got your UART cartridge in the LX and hooked up to a USB port and hold the power button down. Then run
+
Once you have compiled a UART enabled Emerald Boot, copy the resulting emerald-boot_UART.bin file to the micromon directory in the emerald-boot-supplement directory. Set the jumpers or switches to enable UART boot on the Explorer and hook up a serial cable or usb adapter, then run this command while holding down the power button.
   bootloader.py /path/to/emerald-boot.bin 115200 0x00000000 0x00000000
+
 
if all is correct you should see it send itself over, a number counting up to 31, then start sending another bit of data with a higher number, this is emerald-boot.bin once loaded it will execute and you should see it start uncompressing a kernel, and on your LX screen it should start booting as normal.
+
   $ ./bootloader emerald-boot_UART.bin 115200
 +
 
 +
This uploads a small program, micromon to the Explorer, which allows uploading a file much larger than the 16k bytes the Pollux SoC accepts for UART booting. Which is necessary because Emerald Boot is a lot bigger than that. If all goes well the Explorer should boot up as normal.
 +
 
 +
Flashing Emerald Boot
 +
Once you've tested out your UART booting Emerald Boot, or have found a precompiled NOR version you want to permanently install on your Explorer, you need to flash it to the NOR memory.
 +
 
 +
Caution: This is a potentially harmful modification. Some precautions, make sure you have a known working copy of Emerald Boot for NOR and UART. If you compile you're own, make sure to test a UART version first. Before attempting this, make sure you have fresh batteries or AC adapter, and in worst case, will be able to make the hardware modifications necessary to UART boot if you have not already.
 +
 
 +
Copy emerald-boot_NOR.bin to /LF/Bulk then run these commands on the Explorers command line.
 +
 
 +
   mfgmode.sh 9 > /dev/null
 +
  flashcp -v /LF/Bulk/emerald-boot_NOR.bin /dev/mtd5
 +
  mfgmode.sh 0 > /dev/null
 +
 
 +
Then reboot your device, if all went well it should boot up fine. If there is an issue and it will not boot, make the necessary hardware modifications for UART boot if you have not. UART boot the device, and redo this process with a known working version of Emerald Boot.
  
 
== Flash to NOR ==
 
== Flash to NOR ==

Revision as of 18:53, 17 June 2011

Getting Started

This how-to will show you how to gain UART Boot access to your Explorer. This involves a hardware hack not for the faint of smd soldering skills, or eye sight. There is two connections that need to be made to some pads that are very very tiny, takes some soldering skills, so be prepared. Also being a hardware hack, there is there is a chance of breaking something important, be careful and be warned. In the second part it will take you through compiling Emerald Boot and sending it over UART to the LX for testing.

How tiny are the pads? Here is a comparison of a normal resistor vs the pads you will be soldering to.

Leapster Explorer-D6 comparison.jpg

Notice that the width of the pad is the same size as the stripe on the resistor. If you don't feel comfortable soldering something this small, this mod might not be good for you to attempt.

Software Needed

RidgeRun Toolchain

Linux, this tutorial will use it exclusive for building the boot loader

emerald-boot-supplement Includes binaries, source patch, and micromon

LF Linux Source Tested on LF-Linux-8291-20101026-1425.tar.gz

Hardware

DJHI or similar cartridge for access to UART console

Soldering Iron (with very tiny tip)

Wire (very fine gauge)

2x 10K Ohm Resistor

2x Switch or jumper pins

On Explorer

Pictures SD[13] and SD[6] show the pads you will be working with. Take your 4 pieces of wire and strip a small amount of insulation off one end of each, and solder one to each pad shown, watch your heat and where the tip is, so as not to destroy the pad or unsolder the component next to it. A magnifier would be a good idea here. Then on one of the wires, of the two to be connected together, attach the resistor and on the other the switch, then solder the resistor to the switch. Add a dab of hot glue or some other means of strain relief, put back together and you are done. To test, hold down both buttons, while you turn on your Explorer, nothing should happen. Try it with out holding down the buttons, to verify your Explorer still works.


SD[13] LX SD13 UART Enable.jpg

SD[6] Leapster Explorer-D6 Pull Down.png


Example:

D6hack.jpg

Bootloader

Technically this isn't a UART boot, what will be happening is, once Emerald Boot is compiled, the Micromon application will be used to load the bin file onto the LX in RAM, where Micromon will then execute the code and start Emerald Boot loading. The reason for this is Emerald Boot is too big to load over UART since it can range from 40 to 200+KB in size, and the Pollux SoC will start running the code sent to it over UART at 16KB.

Compiling

This works with the RidgeRun toolchain and on the LF-Linux-8291-20101026-1425.tar.gz sources, it may work with others toolchains and source version, but is as of yet untested. It also requires that you have built the LF-Linux kernel, as Emerald Boot draws a few files from it.

Extract the emerald-boot-supplement archive. Make sure you have a clean copy of the emerald-boot/ directory in the LF-Source tree.

Next apply the patch which makes the necessary modifications for UART booting, along with a few other mods to make things a bit more friendly.

Copy screens/ to the packages/ directory in the source tree.

Copy host_tools/ to the root directory along side emerald-boot and packages. If you want you can make your own, just save them as png. Although they only get used when Emerald Boot is in USB boot mode.

Inside the emerald-boot/ directory apply the patch.

 $ patch -p1 < /path/to/emerald-boot-supplement.patch

To compile the bootloader run

 $ OPTION=1 ./install.sh

Some OPTION values include MICRO_BOOT for UART enabling, SDCARD for booting a kernel off an SD card, and DEBUG which puts out some extra info in the console which is nice for bootloader testing.

example for UART booting and Debugging

 $ MICRO_BOOT=1 DEBUG=1 ./install.sh

UART Booting

Once you have compiled a UART enabled Emerald Boot, copy the resulting emerald-boot_UART.bin file to the micromon directory in the emerald-boot-supplement directory. Set the jumpers or switches to enable UART boot on the Explorer and hook up a serial cable or usb adapter, then run this command while holding down the power button.

 $ ./bootloader emerald-boot_UART.bin 115200

This uploads a small program, micromon to the Explorer, which allows uploading a file much larger than the 16k bytes the Pollux SoC accepts for UART booting. Which is necessary because Emerald Boot is a lot bigger than that. If all goes well the Explorer should boot up as normal.

Flashing Emerald Boot Once you've tested out your UART booting Emerald Boot, or have found a precompiled NOR version you want to permanently install on your Explorer, you need to flash it to the NOR memory.

Caution: This is a potentially harmful modification. Some precautions, make sure you have a known working copy of Emerald Boot for NOR and UART. If you compile you're own, make sure to test a UART version first. Before attempting this, make sure you have fresh batteries or AC adapter, and in worst case, will be able to make the hardware modifications necessary to UART boot if you have not already.

Copy emerald-boot_NOR.bin to /LF/Bulk then run these commands on the Explorers command line.

 mfgmode.sh 9 > /dev/null
 flashcp -v /LF/Bulk/emerald-boot_NOR.bin /dev/mtd5
 mfgmode.sh 0 > /dev/null

Then reboot your device, if all went well it should boot up fine. If there is an issue and it will not boot, make the necessary hardware modifications for UART boot if you have not. UART boot the device, and redo this process with a known working version of Emerald Boot.

Flash to NOR

First off, this is a dangerous operation, things can go wrong. I would make sure you understanding fully the process here, and that you are using AC power instead of batteries, or at the very least a good fresh set of batteries, if the power goes out before its done, it won't boot back up. Also make sure you tested your Emerald Boot the best you can prior to doing this. Bricking is possible, so know what you are doing first.

To flash your compiled binary of Emerald Boot to your LX, you need to make sure and recompile it with out the MICRO_BOOT option, and then place your bin file on your LX. Run cat /proc/mtd on your LX and double check that NOR is mtd5 this will be needed for the next step. On the LX there is a script /usr/bin/norget that is for flashing to the NOR. It contains the key commands you will need to flash your new Emerald Boot to your LX.

mfgmode.sh 9 > /dev/null
flashcp -v path/to/your/emerald-boot.bin /dev/mtd5
mfgmode.sh 0 > /dev/null

It should say its erasing then writing, then finish, now cross your fingers and reboot. If all is successful it should boot like normal. Remember, things can go wrong, so make sure you understand the process first.