Welcome! Log In Create A New Profile

Advanced

A10 Rescue System

Posted by Jeff 
A10 Rescue System
July 24, 2012 12:34PM
I've created a bootable rescue system for the A10. When this image is written to an empty flash card, it will use the first 32MB of the card for uBoot and a 31MB FAT32 partition (I'll refer to this as the sysconfig partition). The sysconfig parititon contains the uboot environment and a /rescue directory containing a basic system.bin file, boot images, autorun scripts, and network configuration files for the rescue system. The included uBoot is configured to boot both the rescue system and any other systems that can be found on the SD card. This way, you can use the remaining space on the SD card for a linux installation.


Installing the rescue system
wget http://download.doozan.com/a10/a10_base-1.0.zip
unzip a10_base-1.0.zip
insert flash drive
dmesg
find drive id (sdb, in my case, using a USB SD card reader)
double check:
fdisk -l /dev/sdb

Disk /dev/sdb: 7948 MB, 7948206080 bytes
245 heads, 62 sectors/track, 1021 cylinders
Units = cylinders of 15190 * 512 = 7777280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5d02e879

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1021     7754464    b  W95 FAT32

Yup, that's my 8GB SD card. I've copied everything I need off of it, which is good because the following dd command is going to wipe out the partition table:

dd if=a10_base-1.0.img of=/dev/sdb bs=4096

fdisk -lu /dev/sdb

Disk /dev/sdb: 7948 MB, 7948206080 bytes
245 heads, 62 sectors/track, 1021 cylinders
Units = cylinders of 15190 * 512 = 7777280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5d02e879

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048       65536       31744+   b  W95 FAT32


alternatively, you can write the image using Windows with this program, making sure that you unzip the file first:
https://launchpad.net/win32-image-writer

Configuring the rescue system

If you're using a device with a wired network port, make sure it's attached to your network. No other configuration is needed.

If you're using a device without a wired network port, you'll need to configure the rescue system so it can connect to your wireless network. On the sysconfig partition, inside /rescue, you'll find two files named 'interfaces' and 'wpa_supplicant.conf' Depending on the type of security used on your wireless network, you will need to edit one or both of these files.

No matter what security you're using, you need to edit 'interfaces' so open that in your favorite editor (Windows users, make sure you're using an editor that respects UNIX line endings, such as Notepad2). Uncomment the two lines starting with "auto wlan0" and "iface wlan0" and then uncomment the section that corresponds with your security. If you're using Open or WEP encryption, you're done. If you're using WPA or WPA2, you'll also need to edit 'wpa_supplicant.conf'


Using the rescue system

On boot, the rescue system will search for and run any files matching the pattern autorun-*.sh. It will also extract any files matching the pattern autorun-*.tgz and then run the extracted autorun.sh script. You can use this to write hooks to automate any recovery or installation procedures.

The default rescue system comes with just one autorun script named autorun-extract-system-bin.sh that will extract the system.bin file from the android partition, find and set the appropriate MAC address using the android uboot environment, and save the updated system.bin file to the sysconfig partition. This only runs if there is no /system.bin on the sysconfig partition, and it will reboot after copying the system.bin file so that uBoot can re-load the system using the new configuration file.

At this time, the rescue system does not display anything on the HDMI output nor on the LCD display on tablet computers. You must use SSH to connect to the rescue system.

Let's try it out: Turn off your system, insert the SD card and boot it up. If it boots into android, you may need to power-cycle again. I find that my mele a2000 alternates between booting from NAND and MMC with each power cycle.


Now that the device has booted, you'll need to find its IP address (check your router's DHCP log). Once you've got the ip, go ahead and connect with SSH:

ssh root@192.168.0.2 (use the ip address that you found here)

the root password is 'root'

[root@rescue ~]# uname -a
Linux rescue 3.0.36 #2 PREEMPT Mon Jul 23 11:55:49 EDT 2012 armv7l GNU/Linux

It works! You're in! This is a simple linux environment with just enough tools to help you restore or recover a broken system. It can also be used as a sane environment for installing your favorite linux distribution. See the Debian install post for more details on that.
Building the A10 Rescue System
July 24, 2012 12:37PM
Here's how I built the rescue system:

Compile buildroot images
cd ~/src
wget http://buildroot.uclibc.org/downloads/buildroot-2012.05.tar.gz
cd buildroot-2012.05
git clone https://github.com/doozan/a10-rescue.git custom
cp buildroot-config .config
make

mkimage -A arm -O linux -T ramdisk -C bzip2 -a 0 -e 0 -n RescueSystem -d output/images/rootfs.cpio.bz2 output/images/uInitrd

Compile the fexc so it will run on the build machine
cd ~/src
git clone https://github.com/amery/sunxi-tools
cd sunxi-tools
make
cd..

Build uBoot
git clone https://github.com/hno/uboot-allwinner.git
cd uboot-allwinner
checkout sun4i
make CROSS_COMPILE=arm-linux-gnueabi- sun4i
cd..

Prepare the SD card
# Zero the first 32M of the card
dd if=/dev/zero of=/dev/sdb bs=1024 count=32768

# Install the boot images
dd if=uboot-allwinner/spl/sun4i-spl.bin of=/dev/sdb bs=1024 seek=8
dd if=uboot-allwinner/u-boot.bin of=/dev/sdb bs=1024 seek=32

# Create u-boot partition on sdb

fdisk /dev/sdb
u
n
p
1
2048
+31M
t
b
w

mkfs.vfat /dev/sdb1

mkdir /tmp/sysconfig
mount /dev/sdb1 /tmp/sysconfig

mkdir /tmp/sysconfig/rescue
cp buildroot-2012.05/output/images/uInitrd  buildroot-2012.05/output/images/uImage /tmp/sysconfig/rescue

cat<<EOF>/tmp/sysconfig/boot.cmd
setenv system.bin 'fatload mmc 0:1 0x43000000 system.bin || fatload mmc 0:1 0x43000000 /rescue/system.bin'
setenv force_rescue 0
setenv force_rescue_bootcmd 'if test \$force_rescue -eq 1 || fatload mmc 0 0x45000000 /rescue/force_rescue.txt; then run rescue_bootcmd; fi'
setenv mmc_root '/dev/mmcblk0p2'
setenv mmc_rootfstype 'ext2'
setenv mmc_bootargs 'setenv bootargs console=\$console root=\$mmc_root rootfstype=\$mmc_rootfstype rootwait'
setenv mmc_boot 'mw 0x44000000 0 1; if ext2load mmc 0:2 0x44000000 /boot/uImage; then if ext2load mmc 0:2 0x45000000 /boot/uInitrd; then bootm 0x44000000 0x45000000; else bootm 0x44000000; fi; else if fatload mmc 0:1 0x44000000 uImage; then if fatload mmc 0:1 0x45000000 uInitrd; then bootm 0x44000000 0x45000000; else bootm 0x44000000; fi; fi; fi;'
setenv mmc_bootcmd 'run mmc_bootargs ; run mmc_boot'
setenv rescue_set_bootargs 'setenv bootargs console=\$console'
setenv rescue_boot 'mw 0x44000000 0 1; fatload mmc 0 0x44000000 /rescue/uImage; if fatload mmc 0 0x45000000 /rescue/uInitrd; then bootm 0x44000000 0x45000000; else bootm 0x44000000; fi'
setenv rescue_bootcmd 'run rescue_set_bootargs; run rescue_boot'
setenv bootcmd 'run system.bin ; run force_rescue_bootcmd; run mmc_bootcmd; run rescue_bootcmd; reset'
setenv boot_mmc 'run bootcmd'
EOF

./uboot-allwinner/tools/mkimage -A arm -O u-boot -T script -C none -n "boot" -d /tmp/sysconfig/boot.cmd /tmp/sysconfig/boot.scr
  
wget https://github.com/amery/sunxi-bin-archive/raw/master/mele-a1000/stock-nanda/script.bin -O system.bin.orig
./sunxi-tools/fexc -I bin -O fex system.bin.orig system.fex
sed -i -e's/^MAC = "000000000000"/MAC = "d0b3d0b3d000"/' system.fex
./sunxi-tools/fexc -I fex -O bin system.fex system.bin
cp system.bin /tmp/sysconfig/rescue


cat<<EOF>/tmp/sysconfig/rescue/interfaces
# Configure Loopback
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

# Uncomment and adjust for your own wifi settings
#auto wlan0
#iface wlan0 inet dhcp
#
#  WPA/WPA2 security, uncomment the next two lines and then edit wpa_supplicant.conf
#pre-up wpa_supplicant -B -Dwext -i wlan0 -c/etc/wpa_supplicant.conf
#post-down killall -q wpa_supplicant
#
#  WEP security, uncomment and edit the next three lines
#wireless-mode managed
#wireless-essid mynetworkname
#wireless-key mywepkey
#
#  Open or no security, uncomment and edit the next two lines
#wireless-mode managed
#wireless-essid mynetworkname
#   
EOF

cat<<EOF>/tmp/sysconfig/rescue/wpa_supplicant
ctrl_interface=/var/run/wpa_supplicant
# Uncomment the following lines if you're using WPA supplicant
#network={
#  ssid="MyNetwork"
#  psk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#}
EOF

cat<<EOF>/tmp/sysconfig/rescue/autorun-extract-system-bin.sh
#!/bin/sh

if [ ! -f /mnt/sysconfig/system.bin ]; then
  echo "Could not find /system.bin on sysconfig partition"
  echo "Searching NAND for usable system.bin files..."

  mkdir /tmp/nand
  mount /dev/nanda /tmp/nand

  if [ -f /tmp/nand/script.bin ]; then
    # Decompile script.bin
    /sbin/fexc -I bin -O fex /tmp/nand/script.bin /tmp/system.fex

    # Extract the MAC address from the uboot environment on nandh
    dd if=/dev/nandh of=/tmp/env bs=1024 count=128
    mac=\`strings /tmp/env | grep "^mac=" | cut -d "=" -f 2 | sed -e 's/://g'\`

    # Set the new MAC address and save system.bin on sysconfig
    sed -i -e"s/^MAC = \\"000000000000\\"/MAC = \\"\$mac\\"/" /tmp/system.fex
    mount -o remount,rw /mnt/sysconfig
    /sbin/fexc -I fex -O bin /tmp/system.fex /mnt/sysconfig/system.bin
    mount -o remount,ro /mnt/sysconfig

    umount /tmp/nand
    echo "Created system.bin from nanda/script.bin, MAC Address = \$mac"
    echo "Rebooting system to use new system.bin"
    sleep 5
    reboot
  else
    echo "Could not find /script.bin on nanda"
  fi
else
  echo "/mnt/sysconfig/system.bin already installed, exiting"
fi
EOF

cat<<EOF>/tmp/sysconfig/README.txt
This partition is reserved for system/boot configs plus a rescue system.

/system.bin - device-specific hardware configuration, extracted from Android partition
boot.scr = compiled uboot environment
boot.cmd = source code for uboot environment, this file can be compiled
with the following command:
mkimage -A arm -O u-boot -T script -C none -n "boot" -d boot.cmd boot.scr


/rescue
======
The images in /rescue will be loaded if no system is found on the mmc0p2 partition.
The rescue system should have just enough tools to allow you to ssh to your device
and repair or install an operating system.

You can force booting to the rescue system by creating a file named 'force_rescue.txt'
in the /rescue directory.

You can also configure the wireless network settings for the rescue system by editing
the network_interfaces file.  If you're editing this file on Windows, be sure to use
an editor that will preserve the UNIX line endings (Notepad2 is a safe choice)

The rescue system includes a precompiled fexc binary.  Full source is available
at http://github.com/amery/sunxi-tools
EOF

echo "1.0" > /tmp/sysconfig/etc/version

Extract the image
umount /tmp/sysconfig

dd if=/dev/sdb of=a10_base-1.0.img bs=1024 count=32768
zip a10_base-1.0.zip a10_base-1.0.img
Re: A10 Rescue System
July 24, 2012 12:45PM
I guess you got your Mele :)

Way to go Jeff!

Can't wait to play with your rescue system!
Re: A10 Rescue System
July 24, 2012 01:49PM
The included autorun-extract-system-bin.sh script works on my Mele A2000 with the stock Android 2.3. On this system, the hardware configuration file is located in /script.bin on /dev/nanda and the uBoot environment containing the MAC address is saved in the first 128k of /dev/nandh

As I don't have any other devices to test, I'd be interested in hearing from anyone with knowledge of other A10 devices. Specifically, I'd like to know what partition your configuration file is located on, what it is named, and where the uBoot environment is saved.
Re: A10 Rescue System
July 24, 2012 02:20PM
Quote

Specifically, I'd like to know what partition your configuration file is located on

It's always in partition 1 (nanda) AFAIK.

The script.bin is called evb.bin on some Mele's, on some tablets it is script_??.bin or something like that. There are a LOT of A10 tablet models out there, and the mfr. can name script.bin whatever they want. Often there are several different script.bins on the same device for whatever reason. Fortunately most tablets are based on just a few PCB's and the file is identical on most of them. Minor variations should not matter too much anyway. But it still opens a difficult can of worms. . .
Re: A10 Rescue System
July 24, 2012 09:54PM
I've created an autorun-deviceinfo script to assist with gathering system information about yet unsupported A10 devices.

If you've got a device that doesn't respond to the rescue system, you can help with troubleshooting.
Download the script from here, save it in the /rescue folder on your rescue SD card (make sure it's still named autorun-deviceinfo.sh) and then boot your device with that SD card.

The script only takes a moment to run, so if you're running "headless" or if the rescue system isn't working with your network or display devices, you can just turn the system on, let it run for two minutes, and then turn the device off. If the rescue system is booting, you should now have some diagnostic info in /log/deviceinfo.log on your rescue SD card.

This file may contain your MAC address, so if you're overly paranoid you can edit that out before posting your log. You can attach the log file to a post here or email it to me directly.

-- Jeff
Re: A10 Rescue System
July 24, 2012 11:53PM
You know the Debian OS install script makes a lot of sense. Combined with the SD image here on your "rescue system" it would likely make for a good "Debian OS install disk (SD card)." But, after thinking about it a while, an A10 "Rescue System" makes little to no sense to me for the A10. It makes perfect sense on the Dockstar or other embedded-only devices. But I can not really see much of a use for it on the A10. I would hope people would have a backup SD card if it means anything to them.
So if it breaks you just pop another SD card in or boot off the NAND. . .

If it is a "rescue disk" in the normal sense then it should be bootable to an accessible command line where you could do OS repairs such as e2fsck, fix inits, replace bad files, etc. But even with a boot disk it is usually difficult to impossible to fix Android issues, and most people will want to keep their Android install at least for now until the Mali works. It is better to have a good backup and reflash for Android. Fixing a messed up SD install would be easier done on a PC or a chroot from Android.

Maybe you could outline the purpose a bit better for us. I don't quite get it.
Re: A10 Rescue System
July 25, 2012 09:29AM
It's primary purpose is meant to be a small, easy to install base platform with enough tools to install or repair a full OS. It should also be helpful doing diagnostics or gathering system information about new devices.

The current A10 linux boot process involves having an extra partition for the uboot script and hardware config, it certainly doesn't hurt to have a tiny bootable platform on there to get started.

It's not made for fixing Android, although now that you mention it, it should be trivial to develop an autorun script that could dump/flash the android partitions.
Diolu
Re: A10 Rescue System
November 24, 2012 05:51AM
I have tried your rescue system on a Sanei N10 but it does not work. I cannot ssh. No log file is created on the sdcard (I have tried to create a file from autorun-extract-system-bin.sh just to see, but nothing). When I try to power it on nothing seems to happen. This means that the system nevertheless tries to do something because it I boot without sdcard, then android boot, but here nothing, the system seems dead. Moreover to reboot into android I have to force the system off (holding the power button and volume down for a few seconds) otherwise the system remains "dead".
Trime
Re: A10 Rescue System
May 23, 2013 05:27AM
I just get a black screen, it seems to be booting from this but it never gets into the shell nor is it connecting to the wifi after I set it. Even the deviceinfo.sh doesn't seem to run.
louigi600
Re: A10 Rescue System
June 27, 2013 03:07AM
Is there any chance that this rescue system would also work on a A13b SOC ?
Is there support for a usb ethernet dongle (rtl8150) ? as the fbcon will most likely not work on the A13b.

Regards
David
stephane ancelot
Re: A10 Rescue System
July 09, 2013 05:02PM
I compiled a brand new kernel with some modules...but how can I upgrade the sdcard to use it ?

Regards.
steph
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: