A10 Rescue System 1.1
July 26, 2012 12:58PM
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 partition 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.1.zip
unzip a10_base-1.1.zip
insert flash drive
dmesg
find drive id (sdb, in my case, using a USB SD card reader)
double check that it's the drive you're expecting to be:
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.1.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 init-*.sh and autorun-*.sh. It will also extract any files matching the pattern init-*.tgz and autorun-*.tgz and then run the extracted autorun.sh script. Init scripts are run just after the partitions have been mounted but before any network initialization. Autorun scipts run after everything has settled down. You can use this to write hooks to automate recovery or installation procedures.

The default rescue system comes with two init scripts:

init-extract-system-bin.sh - This script will attempt to extract the hardware configuration file from the android nand and patch it with the MAC address extracted from the android uboot environment.
init-modules.sh - This script will parse the system.bin file. If your device's system.bin lists an ethernet port, the module wil l be loaded. If no ethernet port is detected, the 8192cu wireless module will be loaded.

There is also one default autorun script:
autorun-deviceinfo.sh - This script will dump some helpful system debugging information to /log/deviceinfo.log on the sysconfig partition. If you're running a device that is not fully supported by the rescue system, this file can help us to add support for your system.

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 #1 PREEMPT Wed Jul 25 17:50:56 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.

Additional init/autorun scripts are available here.
Building the A10 Rescue System 1.1
July 26, 2012 01:01PM
Here's how I built the 1.1 rescue system:

build recovery image

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
cd custom
git checkout v1.1
cd ..
cp custom/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

cd ~/src
git clone https://github.com/amery/sunxi-tools
cd sunxi-tools
make
cd..

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

Prep 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 partition table and sysconfig partition
cat <<EOF | fdisk /dev/sdb
u
n
p
1
2048
63487
t
b
w
EOF

mkfs.vfat /dev/sdb1

Install files
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

wget https://raw.github.com/doozan/a10-rescue-scripts/master/init-extract-system-bin.sh -O /tmp/sysconfig/rescue/init-extract-system-bin.sh
wget https://raw.github.com/doozan/a10-rescue-scripts/master/init-modules.sh -O /tmp/sysconfig/rescue/init-modules.sh
wget https://raw.github.com/doozan/a10-rescue-scripts/master/autorun-deviceinfo.sh -O /tmp/sysconfig/rescue/autorun-deviceinfo.sh


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.conf
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/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

Extract the image

umount /tmp/sysconfig

dd if=/dev/sdb of=a10_base-1.1.img bs=1024 count=32768
zip a10_base-1.1.zip a10_base-1.1.img



Edited 1 time(s). Last edit at 07/26/2012 03:19PM by Jeff.
J. Carlos
Re: A10 Rescue System 1.1
July 26, 2012 03:00PM
When building buildroot I get:

>>> Generating root filesystem image rootfs.cpio
if [ ! -e /home/jcromero/src/buildroot-2012.05/output/target/init ]; then /usr/bin/install -m 0755 fs/cpio/init /home/jcromero/src/buildroot-2012.05/output/target/init; fi
rm -f /home/jcromero/src/buildroot-2012.05/output/build/_fakeroot.fs
echo "chown -R 0:0 /home/jcromero/src/buildroot-2012.05/output/target" >> /home/jcromero/src/buildroot-2012.05/output/build/_fakeroot.fs
cat custom/device_table.txt > /home/jcromero/src/buildroot-2012.05/output/build/_device_table.txt
cat: custom/device_table.txt: No existe el fichero o el directorio
make: *** [/home/jcromero/src/buildroot-2012.05/output/images/rootfs.cpio] Error 1
jcromero@casiopea:~/src/buildroot-2012.05$


By the way, there is no v1.1 branch in a10-rescue repository and I suppose there is a missing git command in this line:

checkout v1.1
Re: Building the A10 Rescue System 1.1
July 26, 2012 03:21PM
Oops! I've updated the repo with the correct tag plus correct .config file, which will fix the error you're seeing.
Re: Building the A10 Rescue System 1.1
July 26, 2012 03:36PM
Quote

# Create partition table and sysconfig partition
cat <<EOF | fdisk /dev/sdb
u
n
p
1
2048
63487
t
b
w
EOF
I'm fairly certain that is what's breaking kpartx. . .
Can't you use sfdisk instead so kpartx is not broken when trying to mount the image with it?

if [ $WIRED = 1 ]; then
  echo "Loading wired ethernet module"
  modprobe sun4i_wemac
else
  echo "Loading wireless module"
  modprobe 8192cu
fi
Why not load both modules on the mele. Wemac is crap. I never use Eth0 on the mele. Have not even tried it. . .

One last thing. AFAIK there is not a coded in MAC for the script.bin on my tablet.


BTW: Thank you very much for this rescue disk and your excellent instructions on creating it. Awesome work!



Edited 3 time(s). Last edit at 07/26/2012 04:02PM by gnexus.
Re: Building the A10 Rescue System 1.1
July 26, 2012 04:14PM
Quote
gnexus
Why not load both modules on the mele.

Because until you pointed it out, I didn't realize that the mele HAD built in wifi. You are absolutely correct, however. Thank you for making my device even better, I'll make sure that gets fixed in the next version.

I'm not seeing the kpartx issue on my system, so I'm not in a position to test that. If you can get it working with sfdisk, I will be more than happy to accept patches.

The MAC is coded into the environment (the first 128k of nandh), not the script.bin. You can verify that with the following commands:

dd if=/dev/nandh of=/tmp/env bs=1024 count=128
strings /tmp/env

That should print out the environment of the android uboot.
J. Carlos
Re: Building the A10 Rescue System 1.1
July 26, 2012 04:14PM
jcromero@casiopea:~/src/buildroot-2012.05/custom$ git checkout v1.1
error: pathspec 'v1.1' did not match any file(s) known to git.
Re: Building the A10 Rescue System 1.1
July 26, 2012 04:32PM
I forgot to push --tags the first time around. Now it really should work, sorry for all the trouble!
Re: Building the A10 Rescue System 1.1
July 26, 2012 05:13PM
Quote

I'm not seeing the kpartx issue on my system, so I'm not in a position to test that. If you can get it working with sfdisk, I will be more than happy to accept patches.
I figured it out. Your FAT partition is one block too big. For some reason writing the u-boot changes it slightly:

/dev/sdb is your rescue disk
sfdisk -d /dev/sdb > > a10_base-partitions.txt
qemu-img create a10_base-1.11.img 32M
kpartx -a a10_base-1.11.img
sfdisk -d /dev/loop0 < a10_base-partitions.txt
sfdisk: ERROR: sector 0 does not have an msdos signature
sfdisk:  /dev/loop0: unrecognized partition table type
fdisk /dev/sdb
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048       65536       31744+   b  W95 FAT32
fdisk /dev/loop0
[root@lp01 z]# fdisk /dev/loop0
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-65535, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-65535, default 65535): 
Using default value 65535
Partition 1 of type Linux and of size 31 MiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))

Command (m for help): w
The partition table has been altered!
 dd if=/dev/sdb of=/dev/loop0 bs=1024 count=2048
kpartx -d a10_base-1.11.img
loop deleted : /dev/loop0
kpartx -a a10_base-1.11.img
device-mapper: resume ioctl on loop0p1 failed: Invalid argument
create/reload failed on loop0p1
fdisk /dev/loop0
      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1            2048       65536       31744+   b  W95 FAT32

Command (m for help): d
Command (m for help): n
Select (default p): p
      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1            2048       65535       31744   83  Linux
Command (m for help): t
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))
Command (m for help): w
kpartx -d a10_base-1.11.img
kpartx -a a10_base-1.11.img

Now it mounts with no issues:
mount /dev/mapper/loop0p1 /mnt/misc

and I can copy the data over:
mount /dev/sdb1 /mnt/ns01
tar -c --one-file-system -f - -C /mnt/ns01 . | tar xvf  - -C /mnt/misc

Now I have a kpartx mountable disk identical to yours, which I will upload.

Here is the corrected a10_base-partitions.txt , which you can use in your script like this:
# Create partition table and sysconfig partition
sfdisk -d /dev/sdb < a10_base-partitions.txt
. . . or you can use the text itself from a10_base-partitions.txt.

Edit: removed u/l link due to later post - see below.



Edited 1 time(s). Last edit at 07/28/2012 11:12AM by gnexus.
Re: Building the A10 Rescue System 1.1
July 26, 2012 05:14PM
Jeff Wrote:

> The MAC is coded into the environment (the first
> 128k of nandh), not the script.bin. You can
> verify that with the following commands:
>
>
> dd if=/dev/nandh of=/tmp/env bs=1024 count=128
> strings /tmp/env
>
>
> That should print out the environment of the
> android uboot.

I had upgraded to the ICS that is on Lundmans site. I found the environment on nandb.
Re: Building the A10 Rescue System 1.1
July 27, 2012 06:21AM
Quote

I had upgraded to the ICS that is on Lundmans site. I found the environment on nandb.
root@mele:/# dd if=/dev/nandb of=/tmp/env bs=1024 count=128
root@mele:/# strings /tmp/env
bootdelay=1
bootcmd=run setargs boot_normal
console=ttyS0,115200
nand_root=/dev/nandd
mmc_root=/dev/mmcblk0p7  (but how did this get there?)
init=/init
loglevel=8
setargs=setenv bootargs console=${console} root=${nand_root} init=${init} loglevel=${loglevel} mac_addr=${mac}
boot_normal=nand read 40007800 boot;boota 40007800
boot_recovery=nand read 40007800 recovery;boota 40007800
boot_fastboot=fastboot
mac=xx:xx:xx:xx:xx:xx

I can verify that. I doubt many people will be using Android 2.3 on the Mele much longer. ICS is too much of an improvement to pass up! I can also verify that the MAC in the environment doesn't correspond to either the Eth0 or Wlan0 address on my Mele.
Re: Building the A10 Rescue System 1.1
July 27, 2012 06:35AM
gnexus Wrote:
-------------------------------------------------------

> I can also
> verify that the MAC in the environment doesn't
> correspond to either the Eth0 or Wlan0 address on
> my Mele.

On mine at least, the MAC in the environment corresponds to eth0 as labeled on the rj45 connector inside the case.
Re: Building the A10 Rescue System 1.1
July 27, 2012 06:54AM
Quote

On mine at least, the MAC in the environment corresponds to eth0 as labeled on the rj45 connector inside the case.

Yes. That does match on mine also. I was referring to the MAC that is currently shown on the Eth0 and wlan0 devices in Linux.
So it seems that is a reliable way to get the MAC for Eth0. But what about wlan0? That one is more important for most people.
Re: A10 Rescue System 1.1
July 27, 2012 11:48PM
Big thanks tried this out on my 'Hackberry A10' board to get to the boot partition and it worked out of the box :). Useful tool!
Re: A10 Rescue System 1.1
July 28, 2012 11:06AM
I finally got an SD card free so I could try to boot Jeff's rescue system. Sorry about the delay on that. But I do not currently have enough SD cards laying about. I can verify that Jeff's rescue system works very well as intended. You can use it to login to the system and check the disk, repair the system, and fix and create partitions. It is an excellent utility!

I can also now verify that my kpartx mountable copy of his disk boots fine and has no issues (I never tested it before ;).

I'm uploading a bzipped tarred copy of it with a sha256sum so paranoid people like me can verify the integrity of the image.
I would kindly ask Jeff to incorporate the partition fix into the next version so we can easily mount and edit the image without needing an SD card.

I am very impressed with Jeff's creation and only have one suggestion I can think of for Jeff. Would it not be possible to have the interfaces file contain the wpa supplicant data? That would make it simpler. Usually that is done like this:
auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet dhcp
        pre-up ifconfig wlan0 hw ether [your wireless MAC address]  up || true
#       wireless-essid [your wireless SSID ] (use for WEP only)
#       wireless-key [your wireless password ] (use for WEP only)
        wpa-ssid [your wireless SSID ]
        wpa-psk [your wireless password ]

Here is the shasum verified kpartx mountable image : http://download.doozan.com/a10/a10_base-1.11.tar.bz2
sha256sum: 3726248789c2c6e5982a39ae83b288b1f4e1663012a1758017ba353c2fb62d78

Thanks again Jeff for your excellent creation to better assist everyone using the A10 platform!
J. Carlos
Re: A10 Rescue System 1.1
August 01, 2012 12:00PM
Only one question relative to buildroot and uboot. Why uboot (by Allwiner) is not built from within buildroot (the same way the kernel (by Allwiner) is? I'm a complete newbie with buildroot, so I expect the question not to be a silly one.
Re: A10 Rescue System 1.1
August 01, 2012 06:51PM
AFAIK, buildroot doesn't support cloning uBoot from a custom git repo and the sun4i support is not part of mainline uboot.
J. Carlos
Re: A10 Rescue System 1.1
August 02, 2012 03:36AM
Are you sure of that?

screenshot
Re: A10 Rescue System 1.1
August 02, 2012 07:18AM
I guess I missed that, thanks for pointing it out.
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: