#!/bin/bash -e # # Copyright (c) 2009-2011 Robert Nelson # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. #Notes: need to check for: parted, fdisk, wget, mkfs.*, mkimage, md5sum unset MMC unset FIRMWARE unset SERIAL_MODE unset USE_BETA_BOOTLOADER unset BETA_KERNEL unset EXPERIMENTAL_KERNEL unset PRINTK unset SPL_BOOT unset ABI_VER unset SMSC95XX_MOREMEM unset DD_UBOOT unset KERNEL_DEB unset USE_UENV SCRIPT_VERSION="2.00" IN_VALID_UBOOT=1 DI_BROKEN_USE_CROSS=1 MIRROR="http://rcn-ee.net/deb/" DIST=squeeze ARCH=armel DISTARCH="${DIST}-${ARCH}" BOOT_LABEL=boot PARTITION_PREFIX="" NATTY_NETIMAGE="current" NATTY_MD5SUM="a88f348be5c94873be0d67a9ce8e485e" ONEIRIC_NETIMAGE="current" ONEIRIC_MD5SUM="3a8978191d7a0544e229de54e4cc8e76" PRECISE_ARMEL_NETIMAGE="current" PRECISE_ARMEL_MD5SUM="d1de888066922a7619e66af331531837" PRECISE_ARMHF_NETIMAGE="current" PRECISE_ARMHF_MD5SUM="6088fc08c04e98ac98998c62787be32a" #SQUEEZE_NETIMAGE="current" SQUEEZE_NETIMAGE="20110106+squeeze3+b1" SQUEEZE_MD5SUM="c6f477cf9dbb2573a31618238dbde468" DIR=$PWD TEMPDIR=$(mktemp -d) function check_root { if [[ $UID -ne 0 ]]; then echo "$0 must be run as sudo user or root" exit fi } function find_issue { check_root #Software Qwerks #Check for gnu-fdisk #FIXME: GNU Fdisk seems to halt at "Using /dev/xx" when trying to script it.. if fdisk -v | grep "GNU Fdisk" >/dev/null ; then echo "Sorry, this script currently doesn't work with GNU Fdisk" exit fi unset PARTED_ALIGN if parted -v | grep parted | grep 2.[1-3] >/dev/null ; then PARTED_ALIGN="--align cylinder" fi } function detect_software { echo "This script needs:" echo "Ubuntu/Debian: sudo apt-get install uboot-mkimage wget dosfstools parted" echo "Fedora: as root: yum install uboot-tools wget dosfstools parted dpkg patch" echo "Gentoo: emerge u-boot-tools wget dosfstools parted dpkg" echo "" unset NEEDS_PACKAGE if [ ! $(which mkimage) ];then echo "Missing uboot-mkimage" NEEDS_PACKAGE=1 fi if [ ! $(which wget) ];then echo "Missing wget" NEEDS_PACKAGE=1 fi if [ ! $(which mkfs.vfat) ];then echo "Missing mkfs.vfat" NEEDS_PACKAGE=1 fi if [ ! $(which parted) ];then echo "Missing parted" NEEDS_PACKAGE=1 fi if [ ! $(which dpkg) ];then echo "Missing dpkg" NEEDS_PACKAGE=1 fi if [ ! $(which patch) ];then echo "Missing patch" NEEDS_PACKAGE=1 fi if [ "${NEEDS_PACKAGE}" ];then echo "" echo "Your System is Missing some dependencies" echo "" exit fi } function dl_bootloader { echo "" echo "Downloading Device's Bootloader" echo "-----------------------------" mkdir -p ${TEMPDIR}/dl/${DISTARCH} mkdir -p ${DIR}/dl/${DISTARCH} wget --no-verbose --directory-prefix=${TEMPDIR}/dl/ ${MIRROR}tools/latest/bootloader if [ "$USE_BETA_BOOTLOADER" ];then ABI="ABX" else ABI="ABI" fi if [ "${SPL_BOOT}" ] ; then MLO=$(cat ${TEMPDIR}/dl/bootloader | grep "${ABI}:${ABI_VER}:MLO" | awk '{print $2}') wget --no-verbose --directory-prefix=${TEMPDIR}/dl/ ${MLO} MLO=${MLO##*/} echo "SPL Bootloader: ${MLO}" fi UBOOT=$(cat ${TEMPDIR}/dl/bootloader | grep "${ABI}:${ABI_VER}:UBOOT" | awk '{print $2}') wget --no-verbose --directory-prefix=${TEMPDIR}/dl/ ${UBOOT} UBOOT=${UBOOT##*/} echo "UBOOT Bootloader: ${UBOOT}" } function dl_kernel_image { echo "" echo "Downloading Device's Kernel Image" echo "-----------------------------" KERNEL_SEL="STABLE" if [ "$BETA_KERNEL" ];then KERNEL_SEL="TESTING" fi if [ "$EXPERIMENTAL_KERNEL" ];then KERNEL_SEL="EXPERIMENTAL" fi if [ ! "${KERNEL_DEB}" ] ; then wget --no-verbose --directory-prefix=${TEMPDIR}/dl/ http://rcn-ee.net/deb/${DIST}-${ARCH}/LATEST-${SUBARCH} FTP_DIR=$(cat ${TEMPDIR}/dl/LATEST-${SUBARCH} | grep "ABI:1 ${KERNEL_SEL}" | awk '{print $3}') FTP_DIR=$(echo ${FTP_DIR} | awk -F'/' '{print $6}') KERNEL=$(echo ${FTP_DIR} | sed 's/v//') wget --no-verbose --directory-prefix=${TEMPDIR}/dl/ http://rcn-ee.net/deb/${DIST}-${ARCH}/${FTP_DIR}/ ACTUAL_DEB_FILE=$(cat ${TEMPDIR}/dl/index.html | grep linux-image | awk -F "\"" '{print $2}') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} ${MIRROR}${DIST}-${ARCH}/v${KERNEL}/${ACTUAL_DEB_FILE} if [ "${DI_BROKEN_USE_CROSS}" ] ; then CROSS_DEB_FILE=$(echo ${ACTUAL_DEB_FILE} | sed 's:'${DIST}':cross:g') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} ${MIRROR}cross/v${KERNEL}/${CROSS_DEB_FILE} fi else unset DI_BROKEN_USE_CROSS KERNEL=${DEB_FILE} #Remove all "\" from file name. ACTUAL_DEB_FILE=$(echo ${DEB_FILE} | sed 's!.*/!!' | grep linux-image) cp -v ${DEB_FILE} ${DIR}/dl/${DISTARCH}/ fi echo "Using: ${ACTUAL_DEB_FILE}" } function remove_uboot_wrapper { echo "Note: NetInstall has u-boot header, removing..." echo "-----------------------------" dd if=${DIR}/dl/${DISTARCH}/${NETINSTALL} bs=64 skip=1 of=${DIR}/dl/${DISTARCH}/initrd.gz echo "-----------------------------" NETINSTALL="initrd.gz" unset UBOOTWRAPPER } function actually_dl_netinstall { wget --directory-prefix=${DIR}/dl/${DISTARCH} ${HTTP_IMAGE}/${DIST}/main/installer-${ARCH}/${NETIMAGE}/images/${BASE_IMAGE}/netboot/${NETINSTALL} MD5SUM=$(md5sum ${DIR}/dl/${DISTARCH}/${NETINSTALL} | awk '{print $1}') if [ "${UBOOTWRAPPER}" ]; then remove_uboot_wrapper fi } function check_dl_netinstall { MD5SUM=$(md5sum ${DIR}/dl/${DISTARCH}/${NETINSTALL} | awk '{print $1}') if [ "=$TEST_MD5SUM=" != "=$MD5SUM=" ]; then echo "Note: NetInstall md5sum has changed: $MD5SUM" echo "-----------------------------" rm -f ${DIR}/dl/${DISTARCH}/${NETINSTALL} || true actually_dl_netinstall else if [ "${UBOOTWRAPPER}" ]; then remove_uboot_wrapper fi fi } function dl_netinstall_image { echo "" echo "Downloading NetInstall Image" echo "-----------------------------" unset UBOOTWRAPPER case "$DISTARCH" in natty-armel) TEST_MD5SUM=$NATTY_MD5SUM NETIMAGE=$NATTY_NETIMAGE HTTP_IMAGE="http://ports.ubuntu.com/ubuntu-ports/dists" BASE_IMAGE="versatile" NETINSTALL="initrd.gz" ;; oneiric-armel) TEST_MD5SUM=$ONEIRIC_MD5SUM NETIMAGE=$ONEIRIC_NETIMAGE HTTP_IMAGE="http://ports.ubuntu.com/ubuntu-ports/dists" BASE_IMAGE="linaro-vexpress" NETINSTALL="initrd.gz" ;; precise-armel) TEST_MD5SUM=$PRECISE_ARMEL_MD5SUM NETIMAGE=$PRECISE_ARMEL_NETIMAGE HTTP_IMAGE="http://ports.ubuntu.com/ubuntu-ports/dists" BASE_IMAGE="linaro-vexpress" NETINSTALL="initrd.gz" ;; precise-armhf) TEST_MD5SUM=$PRECISE_ARMHF_MD5SUM NETIMAGE=$PRECISE_ARMHF_NETIMAGE HTTP_IMAGE="http://ports.ubuntu.com/ubuntu-ports/dists" BASE_IMAGE="omap" UBOOTWRAPPER=1 NETINSTALL="uInitrd" ;; squeeze-armel) TEST_MD5SUM=$SQUEEZE_MD5SUM NETIMAGE=$SQUEEZE_NETIMAGE HTTP_IMAGE="http://ftp.debian.org/debian/dists" BASE_IMAGE="versatile" NETINSTALL="initrd.gz" ;; esac if [ -f ${DIR}/dl/${DISTARCH}/${NETINSTALL} ]; then check_dl_netinstall else actually_dl_netinstall fi echo "md5sum of NetInstall: ${MD5SUM}" } function dl_firmware { echo "" echo "Downloading Firmware" echo "-----------------------------" #TODO: We should just use the git tree blobs over distro versions if [ ! -f ${DIR}/dl/linux-firmware/.git/config ]; then cd ${DIR}/dl/ git clone git://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/linux-firmware.git cd ${DIR}/ else cd ${DIR}/dl/linux-firmware git pull cd ${DIR}/ fi #from: http://ports.ubuntu.com/pool/main/l/linux-firmware/ ULF="1.62" #from: http://ports.ubuntu.com/pool/multiverse/l/linux-firmware-nonfree/ ULFN="1.11" case "$DIST" in natty) rm -f ${TEMPDIR}/dl/index.html || true wget --directory-prefix=${TEMPDIR}/dl/ http://ports.ubuntu.com/pool/main/l/linux-firmware/ NATTY_FW=$(cat ${TEMPDIR}/dl/index.html | grep ${ULF} | grep linux-firmware | grep _all.deb | head -1 | awk -F"\"" '{print $8}') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://ports.ubuntu.com/pool/main/l/linux-firmware/${NATTY_FW} NATTY_FW=${NATTY_FW##*/} rm -f ${TEMPDIR}/dl/index.html || true wget --directory-prefix=${TEMPDIR}/dl/ http://ports.ubuntu.com/pool/multiverse/l/linux-firmware-nonfree/ NATTY_NONF_FW=$(cat ${TEMPDIR}/dl/index.html | grep ${ULFN} | grep linux-firmware-nonfree | grep _all.deb | head -1 | awk -F"\"" '{print $8}') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://ports.ubuntu.com/pool/multiverse/l/linux-firmware-nonfree/${NATTY_NONF_FW} NATTY_NONF_FW=${NATTY_NONF_FW##*/} #V3.1 needs 1.9.4 for ar9170 #wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://www.kernel.org/pub/linux/kernel/people/chr/carl9170/fw/1.9.4/carl9170-1.fw wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://rcn-ee.net/firmware/carl9170/1.9.4/carl9170-1.fw AR9170_FW="carl9170-1.fw" ;; oneiric) rm -f ${TEMPDIR}/dl/index.html || true wget --directory-prefix=${TEMPDIR}/dl/ http://ports.ubuntu.com/pool/main/l/linux-firmware/ ONEIRIC_FW=$(cat ${TEMPDIR}/dl/index.html | grep ${ULF} | grep linux-firmware | grep _all.deb | head -1 | awk -F"\"" '{print $8}') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://ports.ubuntu.com/pool/main/l/linux-firmware/${ONEIRIC_FW} ONEIRIC_FW=${ONEIRIC_FW##*/} rm -f ${TEMPDIR}/dl/index.html || true wget --directory-prefix=${TEMPDIR}/dl/ http://ports.ubuntu.com/pool/multiverse/l/linux-firmware-nonfree/ ONEIRIC_NONF_FW=$(cat ${TEMPDIR}/dl/index.html | grep ${ULFN} | grep linux-firmware-nonfree | grep _all.deb | head -1 | awk -F"\"" '{print $8}') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://ports.ubuntu.com/pool/multiverse/l/linux-firmware-nonfree/${ONEIRIC_NONF_FW} ONEIRIC_NONF_FW=${ONEIRIC_NONF_FW##*/} #V3.1 needs 1.9.4 for ar9170 #wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://www.kernel.org/pub/linux/kernel/people/chr/carl9170/fw/1.9.4/carl9170-1.fw wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://rcn-ee.net/firmware/carl9170/1.9.4/carl9170-1.fw AR9170_FW="carl9170-1.fw" ;; precise) rm -f ${TEMPDIR}/dl/index.html || true wget --directory-prefix=${TEMPDIR}/dl/ http://ports.ubuntu.com/pool/main/l/linux-firmware/ PRECISE_FW=$(cat ${TEMPDIR}/dl/index.html | grep ${ULF} | grep linux-firmware | grep _all.deb | head -1 | awk -F"\"" '{print $8}') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://ports.ubuntu.com/pool/main/l/linux-firmware/${PRECISE_FW} PRECISE_FW=${PRECISE_FW##*/} rm -f ${TEMPDIR}/dl/index.html || true wget --directory-prefix=${TEMPDIR}/dl/ http://ports.ubuntu.com/pool/multiverse/l/linux-firmware-nonfree/ PRECISE_NONF_FW=$(cat ${TEMPDIR}/dl/index.html | grep ${ULFN} | grep linux-firmware-nonfree | grep _all.deb | head -1 | awk -F"\"" '{print $8}') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://ports.ubuntu.com/pool/multiverse/l/linux-firmware-nonfree/${PRECISE_NONF_FW} PRECISE_NONF_FW=${PRECISE_NONF_FW##*/} #V3.1 needs 1.9.4 for ar9170 #wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://www.kernel.org/pub/linux/kernel/people/chr/carl9170/fw/1.9.4/carl9170-1.fw wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://rcn-ee.net/firmware/carl9170/1.9.4/carl9170-1.fw AR9170_FW="carl9170-1.fw" ;; squeeze) #from: http://packages.debian.org/source/squeeze/firmware-nonfree #Atmel rm -f ${TEMPDIR}/dl/index.html || true wget --directory-prefix=${TEMPDIR}/dl/ ftp://ftp.us.debian.org/debian/pool/non-free/a/atmel-firmware/ ATMEL_FW=$(cat ${TEMPDIR}/dl/index.html | grep atmel | grep -v diff.gz | grep -v .dsc | grep -v orig.tar.gz | tail -1 | awk -F"\"" '{print $2}') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} ${ATMEL_FW} ATMEL_FW=${ATMEL_FW##*/} #Ralink rm -f ${TEMPDIR}/dl/index.html || true wget --directory-prefix=${TEMPDIR}/dl/ ftp://ftp.us.debian.org/debian/pool/non-free/f/firmware-nonfree/ RALINK_FW=$(cat ${TEMPDIR}/dl/index.html | grep ralink | grep -v lenny | tail -1 | awk -F"\"" '{print $2}') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} ${RALINK_FW} RALINK_FW=${RALINK_FW##*/} #libertas rm -f ${TEMPDIR}/dl/index.html || true wget --directory-prefix=${TEMPDIR}/dl/ ftp://ftp.us.debian.org/debian/pool/non-free/libe/libertas-firmware/ LIBERTAS_FW=$(cat ${TEMPDIR}/dl/index.html | grep libertas | grep -v diff.gz | grep -v .dsc | grep -v orig.tar.gz | tail -1 | awk -F"\"" '{print $2}') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} ${LIBERTAS_FW} LIBERTAS_FW=${LIBERTAS_FW##*/} #zd1211 rm -f ${TEMPDIR}/dl/index.html || true wget --directory-prefix=${TEMPDIR}/dl/ ftp://ftp.us.debian.org/debian/pool/non-free/z/zd1211-firmware/ ZD1211_FW=$(cat ${TEMPDIR}/dl/index.html | grep zd1211 | grep -v diff.gz | grep -v tar.gz | grep -v .dsc | tail -1 | awk -F"\"" '{print $2}') wget -c --directory-prefix=${DIR}/dl/${DISTARCH} ${ZD1211_FW} ZD1211_FW=${ZD1211_FW##*/} #V3.1 needs 1.9.4 for ar9170 #wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://www.kernel.org/pub/linux/kernel/people/chr/carl9170/fw/1.9.4/carl9170-1.fw wget -c --directory-prefix=${DIR}/dl/${DISTARCH} http://rcn-ee.net/firmware/carl9170/1.9.4/carl9170-1.fw AR9170_FW="carl9170-1.fw" ;; esac } function boot_files_template { cat > ${TEMPDIR}/bootscripts/netinstall.cmd < ${TEMPDIR}/bootscripts/normal.cmd < ${TEMPDIR}/bootscripts/uEnv.cmd < ${TEMPDIR}/bootscripts/netinstall.cmd < ${TEMPDIR}/bootscripts/normal.cmd <> ${TEMPDIR}/bootscripts/netinstall.cmd <> ${TEMPDIR}/bootscripts/normal.cmd <> ${TEMPDIR}/bootscripts/netinstall.cmd <> ${TEMPDIR}/bootscripts/normal.cmd <> ${TEMPDIR}/bootscripts/netinstall.cmd <> ${TEMPDIR}/bootscripts/normal.cmd <> ${TEMPDIR}/bootscripts/netinstall.cmd <> ${TEMPDIR}/bootscripts/normal.cmd <> ${TEMPDIR}/initrd-tree/etc/sysctl.conf else echo "vm.min_free_kbytes = 8192" >> ${TEMPDIR}/initrd-tree/etc/sysctl.conf fi if [ "${SERIAL_MODE}" ] ; then if [ ! "${DD_UBOOT}" ] ; then #this needs more thought, need to disable the check for mx53loco, but maybe we don't need it for omap.. touch ${TEMPDIR}/initrd-tree/etc/rcn-serial.conf fi fi } function recompress_initrd { echo "NetInstall: Compressing initrd image" cd ${TEMPDIR}/initrd-tree/ find . | cpio -o -H newc | gzip -9 > ${TEMPDIR}/initrd.mod.gz cd ${DIR}/ } function extract_zimage { echo "NetInstall: Extracting Kernel Boot Image" if [ ! "${DI_BROKEN_USE_CROSS}" ] ; then dpkg -x ${DIR}/dl/${DISTARCH}/${ACTUAL_DEB_FILE} ${TEMPDIR}/kernel else dpkg -x ${DIR}/dl/${DISTARCH}/${CROSS_DEB_FILE} ${TEMPDIR}/kernel fi } function create_custom_netinstall_image { echo "" echo "NetInstall: Creating Custom Image" echo "-----------------------------" mkdir -p ${TEMPDIR}/kernel mkdir -p ${TEMPDIR}/initrd-tree extract_base_initrd if [ "${FIRMWARE}" ] ; then mkdir -p ${TEMPDIR}/initrd-tree/lib/firmware/ initrd_add_firmware fi initrd_cleanup initrd_preseed_settings initrd_fixes recompress_initrd extract_zimage } function unmount_all_drive_partitions { echo "" echo "Unmounting Partitions" echo "-----------------------------" NUM_MOUNTS=$(mount | grep -v none | grep "$MMC" | wc -l) for (( c=1; c<=$NUM_MOUNTS; c++ )) do DRIVE=$(mount | grep -v none | grep "$MMC" | tail -1 | awk '{print $1}') umount ${DRIVE} &> /dev/null || true done parted --script ${MMC} mklabel msdos } function uboot_in_boot_partition { echo "" echo "Using fdisk to create BOOT Partition" echo "-----------------------------" #With util-linux, 2.18.x/2.19.x, fdisk no longer has dos/cylinders mode on by default unset FDISK_DOS if test $(fdisk -v | grep -o -E '2\.[0-9]+' | cut -d'.' -f2) -ge 18 ; then FDISK_DOS="-c=dos -u=cylinders" fi fdisk ${FDISK_DOS} ${MMC} << END n p 1 1 +64M t e p w END sync echo "Setting Boot Partition's Boot Flag" echo "-----------------------------" parted --script ${MMC} set 1 boot on if [ "$FDISK_DEBUG" ];then echo "Debug: Partition 1 layout:" echo "-----------------------------" fdisk -l ${MMC} echo "-----------------------------" fi } function dd_uboot_before_boot_partition { echo "" echo "Using dd to place bootloader before BOOT Partition" echo "-----------------------------" dd if=${TEMPDIR}/dl/${UBOOT} of=${MMC} seek=1 bs=1024 #For now, lets default to fat16, but this could be ext2/3/4 echo "Using parted to create BOOT Partition" echo "-----------------------------" parted --script ${PARTED_ALIGN} ${MMC} mkpart primary fat16 10 100 #parted --script ${PARTED_ALIGN} ${MMC} mkpart primary ext3 10 100 } function format_boot_partition { echo "Formating Boot Partition" echo "-----------------------------" mkfs.vfat -F 16 ${MMC}${PARTITION_PREFIX}1 -n ${BOOT_LABEL} } function create_partitions { if [ "${DD_UBOOT}" ] ; then dd_uboot_before_boot_partition else uboot_in_boot_partition fi format_boot_partition } function populate_boot { echo "Populating Boot Partition" echo "-----------------------------" mkdir -p ${TEMPDIR}/disk if mount -t vfat ${MMC}${PARTITION_PREFIX}1 ${TEMPDIR}/disk; then if [ "${SPL_BOOT}" ] ; then if [ -f ${TEMPDIR}/dl/${MLO} ]; then cp -v ${TEMPDIR}/dl/${MLO} ${TEMPDIR}/disk/MLO fi fi if [ ! "${DD_UBOOT}" ] ; then if [ -f ${TEMPDIR}/dl/${UBOOT} ]; then if echo ${UBOOT} | grep img > /dev/null 2>&1;then cp -v ${TEMPDIR}/dl/${UBOOT} ${TEMPDIR}/disk/u-boot.img else cp -v ${TEMPDIR}/dl/${UBOOT} ${TEMPDIR}/disk/u-boot.bin fi fi fi VMLINUZ="vmlinuz-*" UIMAGE="uImage.net" if [ -f ${TEMPDIR}/kernel/boot/${VMLINUZ} ]; then LINUX_VER=$(ls ${TEMPDIR}/kernel/boot/${VMLINUZ} | awk -F'vmlinuz-' '{print $2}') echo "Using mkimage to create uImage" echo "-----------------------------" mkimage -A arm -O linux -T kernel -C none -a ${ZRELADD} -e ${ZRELADD} -n ${LINUX_VER} -d ${TEMPDIR}/kernel/boot/${VMLINUZ} ${TEMPDIR}/disk/${UIMAGE} fi INITRD="initrd.mod.gz" UINITRD="uInitrd.net" if [ -f ${TEMPDIR}/${INITRD} ]; then echo "Using mkimage to create uInitrd" echo "-----------------------------" mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n initramfs -d ${TEMPDIR}/${INITRD} ${TEMPDIR}/disk/${UINITRD} fi if [ "${USE_UENV}" ] ; then echo "Copying uEnv.txt based boot scripts to Boot Partition" echo "-----------------------------" echo "Net Install Boot Script:" cp -v ${TEMPDIR}/bootscripts/netinstall.cmd ${TEMPDIR}/disk/uEnv.txt echo "-----------------------------" cat ${TEMPDIR}/bootscripts/netinstall.cmd echo "-----------------------------" echo "Normal Boot Script:" cp -v ${TEMPDIR}/bootscripts/normal.cmd ${TEMPDIR}/disk/normal.txt echo "-----------------------------" cat ${TEMPDIR}/bootscripts/normal.cmd echo "-----------------------------" touch ${TEMPDIR}/disk/use_uenv else echo "Copying boot.scr based boot scripts to Boot Partition" echo "-----------------------------" echo "Net Install Boot Script:" cp -v ${TEMPDIR}/bootscripts/uEnv.cmd ${TEMPDIR}/disk/uEnv.txt cat ${TEMPDIR}/disk/uEnv.txt echo "-----------------------------" mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Debian Installer" -d ${TEMPDIR}/bootscripts/netinstall.cmd ${TEMPDIR}/disk/boot.scr cat ${TEMPDIR}/bootscripts/netinstall.cmd echo "-----------------------------" echo "Normal Boot Script:" cp -v ${TEMPDIR}/bootscripts/normal.cmd ${TEMPDIR}/disk/boot.cmd cat ${TEMPDIR}/bootscripts/normal.cmd echo "-----------------------------" fi cp -v ${DIR}/dl/${DISTARCH}/${ACTUAL_DEB_FILE} ${TEMPDIR}/disk/ cat > ${TEMPDIR}/readme.txt < ${TEMPDIR}/update_boot_files.sh </dev/null 2>&1;then sudo update-initramfs -c -k \$(uname -r) else sudo update-initramfs -u -k \$(uname -r) fi if ls /boot/initrd.img-\$(uname -r) >/dev/null 2>&1;then sudo mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n initramfs -d /boot/initrd.img-\$(uname -r) /boot/uboot/uInitrd fi if ls /boot/uboot/boot.cmd >/dev/null 2>&1;then sudo mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Boot Script" -d /boot/uboot/boot.cmd /boot/uboot/boot.scr fi if ls /boot/uboot/serial.cmd >/dev/null 2>&1;then sudo mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Boot Script" -d /boot/uboot/serial.cmd /boot/uboot/boot.scr fi sudo cp /boot/uboot/boot.scr /boot/uboot/boot.ini if ls /boot/uboot/user.cmd >/dev/null 2>&1;then sudo mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Reset Nand" -d /boot/uboot/user.cmd /boot/uboot/user.scr fi update_boot_files cat > ${TEMPDIR}/minimal_xfce.sh < ${TEMPDIR}/get_chrome.sh < /dev/null fi if [ -f /tmp/chrome-linux.zip ] ; then rm -f /tmp/chrome-linux.zip &> /dev/null fi wget --no-verbose --directory-prefix=/tmp/ http://build.chromium.org/buildbot/snapshots/chromium-rel-arm/LATEST CHROME_VER=\$(cat /tmp/LATEST) wget --directory-prefix=/tmp/ http://build.chromium.org/buildbot/snapshots/chromium-rel-arm/\${CHROME_VER}/chrome-linux.zip sudo mkdir -p /opt/chrome-linux/ sudo chown -R \$USER:\$USER /opt/chrome-linux/ if [ -f /tmp/chrome-linux.zip ] ; then unzip -o /tmp/chrome-linux.zip -d /opt/ fi cat > /tmp/chrome.desktop </dev/null | grep "[Disk] ${MMC}" | awk '{print $2}') if test "-$FDISK-" = "-$MMC:-" then echo "" echo "I see..." echo "fdisk -l:" LC_ALL=C fdisk -l 2>/dev/null | grep "[Disk] /dev/" --color=never echo "" echo "mount:" mount | grep -v none | grep "/dev/" --color=never echo "" read -p "Are you 100% sure, on selecting [${MMC}] (y/n)? " [ "$REPLY" == "y" ] || exit echo "" else echo "" echo "Are you sure? I Don't see [${MMC}], here is what I do see..." echo "" echo "fdisk -l:" LC_ALL=C fdisk -l 2>/dev/null | grep "[Disk] /dev/" --color=never echo "" echo "mount:" mount | grep -v none | grep "/dev/" --color=never echo "" exit fi } function is_omap { SPL_BOOT=1 UIMAGE_ADDR="0x80300000" UINITRD_ADDR="0x81600000" SERIAL_CONSOLE="${SERIAL},115200n8" ZRELADD="0x80008000" SUBARCH="omap" VIDEO_CONSOLE="console=tty0" VIDEO_DRV="omapfb.mode=dvi" VIDEO_OMAPFB_MODE="dvi" VIDEO_TIMING="1280x720MR-16@60" } function is_imx53 { UIMAGE_ADDR="0x70800000" UINITRD_ADDR="0x72100000" SERIAL_CONSOLE="${SERIAL},115200" ZRELADD="0x70008000" SUBARCH="imx" VIDEO_CONSOLE="console=tty0" VIDEO_DRV="mxcdi1fb" VIDEO_TIMING="RGB24,1280x720M@60" } function check_uboot_type { unset DO_UBOOT case "$UBOOT_TYPE" in beagle_bx) SYSTEM=beagle_bx unset IN_VALID_UBOOT DO_UBOOT=1 ABI_VER=1 SERIAL="ttyO2" USE_UENV=1 is_omap ;; beagle_cx) SYSTEM=beagle_cx unset IN_VALID_UBOOT DO_UBOOT=1 ABI_VER=1 SERIAL="ttyO2" USE_UENV=1 is_omap ;; beagle) SYSTEM=beagle unset IN_VALID_UBOOT DO_UBOOT=1 ABI_VER=7 SERIAL="ttyO2" USE_UENV=1 is_omap ;; bone) SYSTEM=bone unset IN_VALID_UBOOT DO_UBOOT=1 ABI_VER=10 SERIAL="ttyO0" USE_UENV=1 is_omap # mmc driver fails to load with this setting # UIMAGE_ADDR="0x80200000" # UINITRD_ADDR="0x80A00000" SERIAL_MODE=1 SUBARCH="omap-psp" ;; igepv2) SYSTEM=igepv2 unset IN_VALID_UBOOT DO_UBOOT=1 ABI_VER=3 SERIAL="ttyO2" is_omap BETA_KERNEL=1 ;; panda) SYSTEM=panda unset IN_VALID_UBOOT DO_UBOOT=1 ABI_VER=2 SMSC95XX_MOREMEM=1 SERIAL="ttyO2" is_omap ;; panda_es) SYSTEM=panda unset IN_VALID_UBOOT DO_UBOOT=1 ABI_VER=2 SMSC95XX_MOREMEM=1 SERIAL="ttyO2" is_omap BETA_KERNEL=1 ;; touchbook) SYSTEM=touchbook unset IN_VALID_UBOOT DO_UBOOT=1 ABI_VER=5 SERIAL="ttyO2" is_omap VIDEO_TIMING="1024x600MR-16@60" BETA_KERNEL=1 SERIAL_MODE=1 ;; crane) SYSTEM=crane unset IN_VALID_UBOOT DO_UBOOT=1 ABI_VER=6 SERIAL="ttyO2" is_omap #with the crane, we need the beta kernel and serial-more BETA_KERNEL=1 SERIAL_MODE=1 ;; mx53loco) SYSTEM=mx53loco unset IN_VALID_UBOOT DO_UBOOT=1 DD_UBOOT=1 ABI_VER=8 SERIAL="ttymxc0" is_imx53 ;; esac if [ "$IN_VALID_UBOOT" ] ; then usage fi } function check_addon_type { IN_VALID_ADDON=1 case "$ADDON_TYPE" in pico) ADDON=pico unset IN_VALID_ADDON ;; ulcd) ADDON=ulcd unset IN_VALID_ADDON ;; esac if [ "$IN_VALID_ADDON" ] ; then usage fi } function check_distro { IN_VALID_DISTRO=1 if test "-$DISTRO_TYPE-" = "-squeeze-" then DIST=squeeze ARCH=armel DISTARCH="${DIST}-${ARCH}" unset IN_VALID_DISTRO fi if test "-$DISTRO_TYPE-" = "-oneiric-" then DIST=oneiric ARCH=armel DISTARCH="${DIST}-${ARCH}" unset DI_BROKEN_USE_CROSS unset IN_VALID_DISTRO fi if test "-$DISTRO_TYPE-" = "-natty-" then DIST=natty ARCH=armel DISTARCH="${DIST}-${ARCH}" unset DI_BROKEN_USE_CROSS unset IN_VALID_DISTRO fi if test "-$DISTRO_TYPE-" = "-precise-armel-" then DIST=precise ARCH=armel DISTARCH="${DIST}-${ARCH}" unset DI_BROKEN_USE_CROSS unset IN_VALID_DISTRO fi if test "-$DISTRO_TYPE-" = "-precise-armhf-" then DIST=precise ARCH=armhf DISTARCH="${DIST}-${ARCH}" unset DI_BROKEN_USE_CROSS unset IN_VALID_DISTRO fi if [ "$IN_VALID_DISTRO" ] ; then usage fi } function usage { echo "usage: sudo $(basename $0) --mmc /dev/sdX --uboot " cat < --uboot (omap) beagle_bx - beagle_cx - beagle - bone - igepv2 - panda - panda_es - (freescale) mx53loco Optional: --distro Debian: squeeze Ubuntu natty oneiric precise-armel (alpha) precise-armhf (alpha) --addon pico ulcd --firmware Add distro firmware --serial-mode --svideo-ntsc force ntsc mode for svideo --svideo-pal force pal mode for svideo Additional Options: -h --help this help --probe-mmc List all partitions: sudo ./mk_mmc.sh --probe-mmc Debug: --earlyprintk EOF exit } function checkparm { if [ "$(echo $1|grep ^'\-')" ];then echo "E: Need an argument" usage fi } IN_VALID_UBOOT=1 # parse commandline options while [ ! -z "$1" ]; do case $1 in -h|--help) usage MMC=1 ;; --probe-mmc) MMC="/dev/idontknow" check_root check_mmc ;; --mmc) checkparm $2 MMC="$2" if [[ "${MMC}" =~ "mmcblk" ]] then PARTITION_PREFIX="p" fi find_issue check_mmc ;; --uboot) checkparm $2 UBOOT_TYPE="$2" check_uboot_type ;; --distro) checkparm $2 DISTRO_TYPE="$2" check_distro ;; --firmware) FIRMWARE=1 ;; --serial-mode) SERIAL_MODE=1 ;; --addon) checkparm $2 ADDON_TYPE="$2" check_addon_type ;; --svideo-ntsc) SVIDEO_NTSC=1 ;; --svideo-pal) SVIDEO_PAL=1 ;; --deb-file) checkparm $2 DEB_FILE="$2" KERNEL_DEB=1 ;; --beta-kernel) BETA_KERNEL=1 ;; --experimental-kernel) EXPERIMENTAL_KERNEL=1 ;; --use-beta-bootloader) USE_BETA_BOOTLOADER=1 ;; --earlyprintk) PRINTK=1 ;; esac shift done if [ ! "${MMC}" ];then echo "ERROR: --mmc undefined" usage fi if [ "$IN_VALID_UBOOT" ] ; then echo "ERROR: --uboot undefined" usage fi find_issue detect_software dl_bootloader dl_kernel_image dl_netinstall_image if [ "${FIRMWARE}" ] ; then dl_firmware fi setup_bootscripts create_custom_netinstall_image unmount_all_drive_partitions create_partitions populate_boot reset_scripts