Allwinner a10 SD Card Debian Install Script

Please note that you should really take a complete copy of the pre-existing OS on the device because some of the files may be needed.
#!/bin/bash
###
### V1.1 11.06.2012 HSt Fixed som option for COMPILER_VERSION and addeed some
###         logging
### V1.2 11.06.2012 HST Automated more the prosess of downloading git etc
### V1.3 11.06.2012 HST changed formating from sfdisk to fdisk
### V1.4 12.06.2012 HSt bugfixes and added possibility to just rebuild the
###         the kernel, and use a hack to have uboot work.
###         made som check to see if thing are downloaded from
###         git etc and then skip the download
### V1.5 14.06.2012 Hst Bugfixes and added a  makesdcard.conf after a
###         suggestion from someone. So with new versions of
###         script you don't need to edit since the options
###         are stored in a file makesdcard.conf in same place
###         you are running this script from.
### V1.6 15.06.2012 HSt Bugfixes, and removed autogenerating of
###         makesdcard.conf

#Set some variables
## The variables below can be placed in a file called makesdcard.conf
## The variables in makesdcard.conf will override the one below
##

# Set device the system sees your card as
MMC_DEV=/dev/mmcblk0  #change if mmc-card mounts on different dev like /dev/sdb

# Set hostname for your melebox
HOSTNAME_MELE=mele

#Set the macadress you have on the box
MACADDRESS_="00:11:22:33:44:55"


#The place you want and have space to store your build
MELE_BUILDDIR=/mnt/allwinner/mele-bygg

GIT_UBOOT=sun4i
#GIT_UBOOT=v2011.09-sun4i


#Choose compiler version
#COMPILER_VERSION=arm-linux-gnueabi-gcc-4.4
#COMPILER_VERSION=arm-linux-gnueabi-gcc-4.5
#COMPILER_VERSION=arm-linux-gnueabi-gcc-4.6
#COMPILER_VERSION=arm-linux-gnueabihf-gcc-4.4
#COMPILER_VERSION=arm-linux-gnueabihf-gcc-4.5
COMPILER_VERSION=arm-linux-gnueabihf-gcc-4.6

#CROSS_COMPILER_SYSTEM=arm-linux-gnueabi-
CROSS_COMPILER_SYSTEM=arm-linux-gnueabihf-

#Choose what linuxbranch you want to use
GIT_LINUX=allwinner-v3.0-android-v2
#GIT_LINUX=allwinner-v2.6.36-android
#GIT_LINUX=allwinner-v3.0-android
#GIT_LINUX=linux-3.3-sun4i
#GIT_LINUX=lichee-3.0.8-sun4i
#You can use your own image. Just unpack it to a catalog with the $IMAGE_NAME in $MELE_BUILDDIR/images/$IMAGE_NAME
IMAGE_NAME=mele_debian_armhf_mybuild
#IMAGE_NAME=mele_debian_armhf


IMAGE_ROOTPASSWORD="mele"
NETWORKNAME="yor_network_name"
WLANPASSWORD="Your_password_on_wireless"

### Buildoptions

# Set this to 1 if you want to rebuild a new debian wheezy armelhf rootfs
BUILD_NEW_IMAGE=1
## If BUILD_NEW_IMAGE=1 then the options below will not be used
ONLY_BUILD_IMAGE_ON_DISK=0
# If you want to put a new build and put it on sdcard with the modules from
# last kernel build
ONLY_BUILD_IMAGE_ON_SDCARD=0

# Set UBOOT_HACK to 1 since uboot spl looks broken at this point
# If using  GIT_UBOOT=v2011.09-sun4i you shouln't need this hack
# Try first with 0 to check if it still broken, and the rerun with 1
# if you got problem with the boot
UBOOT_HACK=0

# Set ONLY_BUILD_KERNEL to 1 if you just want to only rebuild the kernel
# This uImage add new modules to the rootfs on the sdcard 
ONLY_BUILD_KERNEL=0



############################################################
######## NO VARIABLES NEED TO BE EDITED BELOW ##############
############################################################
if [ -f makesdcard.conf ]; then
    source makesdcard.conf
fi

p=""
if [ `echo $MMC_DEV|grep mmc` ]; then p="p"; fi
UBOOT_PART=$MMC_DEV$p"1"
ROOTFS=$MMC_DEV$p"2"
MACADDRESS=`echo $MACADDRESS_|cut -c 1-2,4-5,7-8,10-11,13-14,16-17,19-20`
ROOTIMG=$MELE_BUILDDIR/images/$IMAGE_NAME

date >/tmp/buildlog
echo MMC_DEV=$MMC_DEV >>/tmp/buildlog
echo UBOOT_PART=$UBOOT_PART >>/tmp/buildlog
echo ROOTFS=$ROOTFS >>/tmp/buildlog
echo HOSTNAME_MELE=$HOSTNAME_MELE  >>/tmp/buildlog
echo MACADDRESS=$MACADDRESS  >>/tmp/buildlog
echo MELE_BUILDDIR=$MELE_BUILDDIR  >>/tmp/buildlog
echo GIT_UBOOT=$GIT_UBOOT  >>/tmp/buildlog
echo COMPILER_VERSION=$COMPILER_VERSION  >>/tmp/buildlog
echo CROSS_COMPILER_SYSTEM=$CROSS_COMPILER_SYSTEM  >>/tmp/buildlog 
echo GIT_LINUX=$GIT_LINUX  >>/tmp/buildlog
echo IMAGE_NAME=$IMAGE_NAME  >>/tmp/buildlog
echo ROOTIMG=$ROOTIMG  >>/tmp/buildlog
echo UBOOT_HACK=$UBOOT_HACK >>/tmp/buildlog
echo ONLY_BUILD_KERNEL=$ONLY_BUILD_KERNEL >>/tmp/buildlog
umount $ROOTFS  >>/tmp/buildlog
umount $UBOOT_PART >>/tmp/buildlog

if [ ! $ONLY_BUILD_KERNEL = 1 ];
then

if [ $BUILD_NEW_IMAGE = 1 ];
then
#Create a rootfs
mkdir -p $MELE_BUILDDIR/images
cd $MELE_BUILDDIR/images
rm -rf $MELE_BUILDDIR/images/$IMAGE_NAME
apt-get -y --force-yes install debootstrap
debootstrap --verbose --arch armhf --variant=minbase --foreign wheezy $IMAGE_NAME http://ftp.debian.org/debian
apt-get -y install -t testing qemu-user-static
apt-get -y install binfmt-support
# If building on Ubuntu, here is command
apt-get -y --force-yes install binfmt-support qemu-kvm-extras-static
modprobe binfmt_misc
cp /usr/bin/qemu-arm-static $IMAGE_NAME/usr/bin
mkdir $IMAGE_NAME/dev/pts
mount -t devpts devpts $IMAGE_NAME/dev/pts
mount -t proc proc $IMAGE_NAME/proc
chroot $IMAGE_NAME/ /bin/bash < /etc/apt/sources.list
deb http://ftp.debian.org/debian/  wheezy main contrib non-free
deb-src http://ftp.debian.org/debian/  wheezy main contrib non-free
END
apt-get update

export LANG=C
apt-get -y install apt-utils
wait
apt-get -y install dialog
wait
apt-get -y install locales
wait
LANG=en_US.UTF-8 locale-gen --purge en_US.UTF-8
wait

cat < /etc/apt/apt.conf.d/71mele
APT::Install-Recommends "0";
APT::Install-Suggests "0";
END

apt-get -y install isc-dhcp-common udev netbase ifupdown iproute openssh-server
wait
apt-get -y install iputils-ping wget net-tools ntpdate uboot-mkimage uboot-envtools vim mount
wait
apt-get -y install nano less module-init-tools wpasupplicant dhcpcd5 dbus perl-modules
wait

### Set up network
cat < /etc/network/interfaces
auto lo eth0 wlan0
iface lo inet loopback
iface eth0 inet dhcp
hwaddress ether $MACADDRESS_
iface wlan0 inet dhcp
wpa-essid $NETWORKNAME
wpa-psk $WLANPASSWORD
END

### Set hostname in image
echo $HOSTNAME_MELE > //etc/hostname

### File system mounts.
cat < //etc/fstab
# /etc/fstab: static file system information.
#
#                
/dev/root      /               ext4    noatime,errors=remount-ro 0 1
tmpfs          /tmp            tmpfs   defaults          0       0
END

##  Activate remote console and disable local consoles.
echo 'T0:2345:respawn:/sbin/getty -L ttyS0 115200 linux' >> //etc/inittab
sed -i 's/^\([1-6]:.* tty[1-6]\)/#\1/' //etc/inittab

echo root:$IMAGE_ROOTPASSWORD|chpasswd



wait
CHROOTEOF

umount $MELE_BUILDDIR/images/$IMAGE_NAME/proc
umount $MELE_BUILDDIR/images/$IMAGE_NAME/dev/pts
fi # End of creating new image

if [ $ONLY_BUILD_IMAGE_ON_DISK = 1 ];then exit;fi

if [ $ONLY_BUILD_IMAGE_ON_SDCARD = 1 ];
then
    mkdir /media/ROOTFS
    mount $ROOTFS /media/ROOTFS
    cd $MELE_BUILDDIR/linux-allwinner
    cp -a output/lib/modules/* /media/ROOTFS/lib/modules
    umount $ROOTFS
    exit
fi

### Create the uboot
cd $MELE_BUILDDIR
#Some packages in ubuntu you need to install to build
    apt-get -y install emdebian-archive-keyring
    apt-get -y install build-essential git
    apt-get -y install u-boot-tools
    apt-get -y install gcc-4.4-arm-linux-gnueabi
    apt-get -y install gcc-4.5-arm-linux-gnueabi
    apt-get -y install gcc-4.6-arm-linux-gnueabi
    apt-get -y install gcc-4.4-arm-linux-gnueabihf
    apt-get -y install gcc-4.5-arm-linux-gnueabihf
    apt-get -y install gcc-4.6-arm-linux-gnueabihf

rm /usr/bin/arm-linux-gnueabi-gcc
rm /usr/bin/arm-linux-gnueabihf-gcc
ln -s /usr/bin/$COMPILER_VERSION /usr/bin/arm-linux-gnueabi-gcc
ln -s /usr/bin/$COMPILER_VERSION /usr/bin/arm-linux-gnueabihf-gcc

# Uncomment it on first run to get a clone of git
if [ ! -d uboot-allwinner ];
then
    git clone https://github.com/hno/uboot-allwinner.git
fi
cd uboot-allwinner
# OK if you get "Already on sun4i".
git checkout $GIT_UBOOT

make clean >>/tmp/buildlog 2>&1
make sun4i CROSS_COMPILE=$CROSS_COMPILER_SYSTEM  >>/tmp/buildlog 2>&1

### This will format and prepare your mmc card
dd if=/dev/zero of=$MMC_DEV bs=512 count=2047

(echo n;echo;echo;echo;echo "+17M";echo n;echo ;echo;echo;echo;echo w) |fdisk $MMC_DEV

    dd if=spl/sun4i-spl.bin of=$MMC_DEV bs=1024 seek=8
    dd if=u-boot.bin of=$MMC_DEV bs=1024 seek=32

#spl/sun4i-spl.bin doesnt work for me so I had to make temp a hack to get uboot working


#I had to make this hack to get uboot working. I think sth is wrong with the uboot-build
#using the file from http://rhombus-tech.net/allwinner_a10/hacking_the_mele_a1000/mele_ubuntu_image/
#using this article http://rhombus-tech.net/allwinner_a10/a10_image/
#unpack the image mele-ubuntu-lucid.img on $MELE_BUILDDIR/images if UBOOT_HACK is set to 1
if [ $UBOOT_HACK = 1 ];
then
  #Check if ubuntu image is downladed and download if its not
  if [ ! -f $MELE_BUILDDIR/binfiles/uboot_mele_mmc.bin ];
  then 
   mkdir $MELE_BUILDDIR/binfiles
   mkdir -p $MELE_BUILDDIR/images
   cd $MELE_BUILDDIR/images
   wget http://www.j1nx.nl/downloads/mele-ubuntu-lucid.img.lzma
   # or wget http://hands.com/~lkcl/mele-ubuntu-lucid.img.lzma
   lzma -d mele-ubuntu-lucid.img.lzma
   mkdir ../mnt
   mount -o loop,offset=1048576 $MELE_BUILDDIR/images/mele-ubuntu-lucid.img ../mnt
   cp ../mnt/evb.bin $MELE_BUILDDIR/binfiles/
   umount ../mnt
   dd if=mele-ubuntu-lucid.img of=$MELE_BUILDDIR/binfiles/uboot_mele_mmc.bin bs=1024 skip=8 count=1008
   fi
   # Overwrite the uboot spl system on mmccard with
   dd if=../binfiles/uboot_mele_mmc.bin of=$MMC_DEV bs=1024 seek=8 #This is not the compiled version but from a ubuntu image
   dd if=u-boot.bin of=$MMC_DEV bs=1024 seek=32
fi

fi

cd $MELE_BUILDDIR
if [ ! -d linux-allwinner ];
then
    git clone git://github.com/amery/linux-allwinner.git
fi
cd linux-allwinner
git checkout $GIT_LINUX  >>/tmp/buildlog 2>&1
make clean  >>/tmp/buildlog 2>&1
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILER_SYSTEM sun4i_defconfig  >>/tmp/buildlog 2>&1
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILER_SYSTEM -j16 uImage modules  >>/tmp/buildlog 2>&1
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILER_SYSTEM INSTALL_MOD_PATH=output modules_install  >>/tmp/buildlog 2>&1

if [ ! $ONLY_BUILD_KERNEL = 1 ];
then
rm -rf $ROOTIMG/lib/modules/`ls output/lib/modules`
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILER_SYSTEM INSTALL_MOD_PATH=$ROOTIMG modules_install  >>/tmp/buildlog 2>&1
fi

cd $MELE_BUILDDIR
if [ ! $ONLY_BUILD_KERNEL = 1 ];
then
mkdir /media/UBOOT
echo $UBOOT_PART
mkfs.vfat -n 'UBOOT' $UBOOT_PART
fi
mount $UBOOT_PART /media/UBOOT
cp linux-allwinner/arch/arm/boot/uImage /media/UBOOT

if [ $ONLY_BUILD_KERNEL = 1 ];
then
    umount $ROOTFS
    mount $ROOTFS /media/ROOTFS
    cd $MELE_BUILDDIR/linux-allwinner
    rm -rf /media/ROOTFS/lib/modules/`ls output/lib/modules`
    cp -a output/lib/modules/* /media/ROOTFS/lib/modules
    exit
fi


umount $ROOTFS 
cat < boot.cmd
setenv console 'ttyS0,115200'
setenv root '/dev/mmcblk0p2'
setenv panicarg 'panic=10'
setenv extra 'rootfstype=ext4 rootwait'
setenv loglevel '8'
setenv setargs 'setenv bootargs console=${console} root=${root} loglevel=${loglevel} ${panicarg} ${extra}'
setenv kernel 'uImage'
setenv boot_mmc 'fatload mmc 0 0x43000000 script.bin; fatload mmc 0 0x48000000 ${kernel}; bootm 0x48000000'
setenv bootcmd 'run setargs boot_mmc'
END



mkimage -A arm -O u-boot -T script -C none -n "boot" -d boot.cmd boot.scr
cp boot.scr /media/UBOOT
rm *.fex
if [ ! -f script.bin ];
    then
    wget https://github.com/amery/sunxi-bin-archive/raw/master/mele-a1000/stock-nanda/script.bin
fi
if [ ! -d sunxi-tools ];
    then
    git clone https://github.com/amery/sunxi-tools
    cd sunxi-tools
    make
    cd ..
fi
sunxi-tools/bin2fex script.bin script.fex

sed s/000000000000/$MACADDRESS/ script.fex >scriptmac.fex

sunxi-tools/fex2bin scriptmac.fex scriptmac.bin

cp scriptmac.bin /media/UBOOT/script.bin
if [ $UBOOT_HACK = 1 ];
then
cp $MELE_BUILDDIR/binfiles/evb.bin /media/UBOOT/evb.bin
fi
cp /tmp/buildlog /media/UBOOT/Buildloginfo.txt
umount $UBOOT_PART

mkfs.ext4 -LROOTFS $ROOTFS

mkdir /media/ROOTFS
umount $ROOTFS
mount $ROOTFS /media/ROOTFS
cd $ROOTIMG
cp -a * /media/ROOTFS

umount $UBOOT_PART
umount $ROOTFS



No comments:

Post a Comment

Thank You , For Immediate Assistance Plz Put Email Copy to Deviceporting@gmail.com