About

This is bootloader, which can boot custom boot image even milestone has locked bootloader.

It consist from:

  • small kernel module, for creating device for booting/controlling boot
  • small userspace program, which give for module boot image and flags
  • universal bootloader, which can uses many places for booting: boot image file from nand flash, boot image from SD card, USB booting, and network booting

Also u can see my analisys of similar commercial module. This is IDA disassemble of module: module.idb and of userspace program: program.idb. I use some info for maintaining 2ndboot-ng

Building 2ndboot-ng

This is small recipe how you can build 2ndboot-ng

1. Get the sources

Stay up to date by following git repository:

git clone http://github.com/XVilka/2ndboot-ng.git

2. Prepare kernel and enviroment

Download your device kernel, unpack this and create configs and headers. You can find all needed kernel sources at and-developes.com Unpack this and run:

make mapphone_defconfig
make headers_install ARCH=arm INSTALL_HDR_PATH=$HOME/build/kern_h/

We have Motorola Milestone - so processor chip is TI OMAP3430 - ARM Cortex a8 (armv7-a arch) (ARM Architectures). So you need use configs with -omap3430 suffix. Set enviroment variable for building options:

export _XXCFLAGS=" -march=armv7-a -mtune=cortex-a8 -mfpu=neon"

3. Prepare crosstool-ng

Download crosstool-ng. Unpack, build (you need for: make,install,bash,cut,sed,grep,gcc,awk,bison,flex,automake,libtool,stat,wget,cvs,patch,tar,gzip, bzip2,lzma,readlink,ncurses, mpfr-dev, gmp-dev)

hg clone http://ymorin.is-a-geek.org/hg/crosstool-ng
cd crosstool-ng
.configure
make
make install

4. Compiling toolchain

Create dir toolchain-android, cd to it and copy files:

XVilka-crosstool-<suffix>.config in .config
XVilka-uClibc-<suffix>.config in uClibc.config

and then run:

ct-ng menuconfig

you can change anything, if needed, and save to .config, then exec:

ct-ng build

5. Setting up toolchain

Done! We have toolchain in build/x-tools. All tools have this triplet: arm-android-linux-uclibsgnueabi-*; just add them in PATH:

export PATH=$HOME/build/x-tools/arm-android-linux-uclibcgnueabi/bin:$PATH
export CROSS_COMPILE=arm-android-linux-uclibcgnueabi-
export KERNEL_CROSS_COMPILE=arm-android-linux-uclibcgnueabi-
export CFLAGS=" -march=armv7-a -mtune=cortex-a8 -mfpu=neon"

So we can run this to check version of compiled gcc:

arm-android-linux-uclibcgnueabi-gcc --version

Also we have system root directory in:

$HOME/build/x-tools/arm-android-linux-uclibcgnueabi/arm-android-linux-uclibcgnueabi/sys-root

For some reasons we need not use this directory, but work with copy - $HOME/build/cross/sys-root. Also we need to change the permissions:

chmod +w sys-root
chmod +w sys-root/usr
chmod +w sys-root/usr/lib

6. Build kernel

In the kernel sources directory run:

make mapphone_defconfig
make -f kernel/kernel.mk

7. Building module

In directory hbootmod run:

make -C $HOME/build/kernel M=`pwd` modules

Also we can use automatic build script from the root of 2ndboot-ng.

Developing

At this moment 2ndboot-ng is under heavily development. So we have a lot of plans. They are:

1. Compile and test kernel module hbootmod - (we need to change memory remapping functions for OMAP3430 platform, see build_l1_table() function in hboot.c). For use processor specific features we can see cpu_v7_ functions from proc_v7.S from linux kernel. Also we need to rewrite buffer memory allocating functions to be more portable and tiny.

2. Rewrite userspace tool and test it on stock boot.img

3. Rewrite bootloader (or port u-boot) to create custom booting service:

  • boot kernel image from file;
  • boot kernel image from USB (fastboot);
  • boot kernel image from network (network boot);
  • list of avaible boot systems - like grub, or lilo bootloaders.

4. Add any of needed features to bootloader/bootmod/userspace utility

5. Add more portability and support of other platforms and kernels, use more assembler

References

Latest OMAP3430 Reference Manual

Linux Kernel Programming Book

For creating this program we need also read these resourses: