#!/bin/bash -e # # Copyright (c) 2009-2010 Robert Nelson # Copyright (c) 2010 Mario Di Francesco # Copyright (c) 2010 Till Harbaum # # 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. # # Latest can be found at: # http://github.com/RobertCNelson/omap-image-builder/blob/master/tools/setup_sdcard.sh #Notes: need to check for: parted, fdisk, wget, mkfs.*, mkimage, md5sum #Debug Tips #oem-config username/password #add: "debug-oem-config" to bootargs unset MMC unset SWAP_BOOT_USER unset DEFAULT_USER unset DEBUG #Defaults RFS=ext3 BOOT_LABEL=BOOT RFS_LABEL=ROOT PARTITION_PREFIX="" UBOOT_TYPE=beagle SWAPSIZE=512 if [ "$TYPE" == "" ]; then TYPE=handset fi RELEASE=latest ARCH=armv7l DIR=$PWD function detect_software { #Currently only Ubuntu and Debian.. #Working on Fedora... unset PACKAGE unset APT if [ ! $(which mkimage) ];then echo "Missing uboot-mkimage" PACKAGE="uboot-mkimage " APT=1 fi if [ ! $(which wget) ];then echo "Missing wget" PACKAGE+="wget " APT=1 fi if [ ! $(which pv) ];then echo "Missing pv" PACKAGE+="pv " APT=1 fi if [ "${APT}" ];then echo "Installing Dependencies" sudo aptitude install $PACKAGE fi } function beagle_boot_scripts { cat > /tmp/boot.cmd < /tmp/boot.cmd < /tmp/boot.cmd < /dev/null || true done sudo parted -s ${MMC} mklabel msdos } function create_partitions { sudo fdisk -H 255 -S 63 ${MMC} << END n p 1 1 +64M a 1 t e p w END echo "" echo "3 / 7: Formatting Boot Partition" echo "" sudo mkfs.vfat -F 16 ${MMC}${PARTITION_PREFIX}1 -n ${BOOT_LABEL} sudo rm -rfd ${DIR}/disk || true mkdir ${DIR}/disk sudo mount ${MMC}${PARTITION_PREFIX}1 ${DIR}/disk if [ "$DO_UBOOT" ];then if ls ${DIR}/downloads/${MLO} >/dev/null 2>&1;then sudo cp -v ${DIR}/downloads/${MLO} ${DIR}/disk/MLO fi if ls ${DIR}/downloads/${UBOOT} >/dev/null 2>&1;then sudo cp -v ${DIR}/downloads/${UBOOT} ${DIR}/disk/u-boot.bin fi fi cd ${DIR}/disk sync cd ${DIR}/ sudo umount ${DIR}/disk || true echo "done" SIZE=`sudo fdisk -s ${MMC}` SIZE=$(( (SIZE/1024)-64-SWAPSIZE )) echo "rootfs size = ${SIZE}" sudo fdisk ${MMC} << ROOTFS n p 2 +${SIZE}M p w ROOTFS echo "" echo "4 / 7: Formating ${RFS} Partition" echo "" sudo mkfs.${RFS} ${MMC}${PARTITION_PREFIX}2 -L ${RFS_LABEL} sudo fdisk ${MMC} << SWAP n p 3 t 3 82 p w SWAP echo "" echo "4a / 7: Creating Swap Partition" echo "" sudo mkswap ${MMC}${PARTITION_PREFIX}3 echo "done" } function populate_boot { echo "" echo "5 / 7: Populating Boot Partition" echo "" sudo mount ${MMC}${PARTITION_PREFIX}1 ${DIR}/disk sudo cp ${LATEST_UIMAGE} ${DIR}/disk/uImage if [ "$DO_UBOOT" ];then if ls /tmp/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 /tmp/boot.cmd ${DIR}/disk/boot.scr sudo cp /tmp/boot.cmd ${DIR}/disk/boot.cmd rm -f /tmp/boot.cmd || true fi #for igepv2 users # if ls ${DIR}/disk/boot.scr >/dev/null 2>&1;then # sudo cp -v ${DIR}/disk/boot.scr ${DIR}/disk/boot.ini # fi fi cd ${DIR}/disk/ sync sync cd ${DIR}/ sudo umount ${DIR}/disk || true } function populate_rootfs { echo "" echo "6 / 7: Populating rootfs Partition" echo "Be patient, this may take a few minutes" echo "" sudo mount ${MMC}${PARTITION_PREFIX}2 ${DIR}/disk mkdir image sudo mount -o loop ./${RELEASE}/images/meego-${TYPE}-${ARCH}-beagle/meego-${TYPE}-${ARCH}-beagle-${RELEASE}.img ./image sudo rsync -aHx --delete ./image/* ${DIR}/disk/ # add SGX and kernel modules INSTALL_ROOT=${DIR}/disk/ # check if module tarball exists and install modules if [ -d ./$KERNEL_VERSION-devel/deploy ]; then echo "Installing kernel modules for $KERNEL_VERSION" # find latest module package LATEST_MODULES=`ls -t1 ./$KERNEL_VERSION-devel/deploy/$KERNEL_VERSION-*-modules.tar.gz | head -n1` sudo tar xfz $LATEST_MODULES -C $INSTALL_ROOT else echo "WARNING: kernel module path ./$KERNEL_VERSION-devel/deploy not found!" fi sudo umount ./image rmdir ./image cd ${DIR}/disk/ sync sync cd ${DIR}/ sudo umount ${DIR}/disk || true echo "" echo "7 / 7: setup_sdcard.sh script complete" echo "" } function check_mmc { FDISK=$(sudo LC_ALL=C sfdisk -l 2>/dev/null | grep "[Disk] ${MMC}" | awk '{print $2}') if test "-$FDISK-" = "-$MMC:-" then echo "" echo "I see..." echo "sudo sfdisk -l:" sudo LC_ALL=C sfdisk -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 "sudo sfdisk -l:" sudo LC_ALL=C sfdisk -l 2>/dev/null | grep "[Disk] /dev/" --color=never echo "" echo "mount:" mount | grep -v none | grep "/dev/" --color=never echo "" exit fi } function check_uboot_type { IN_VALID_UBOOT=1 unset DO_UBOOT case "$UBOOT_TYPE" in beagle) SYSTEM=beagle unset IN_VALID_UBOOT DO_UBOOT=1 ;; beagle-proto) #hidden: proto button bug SYSTEM=beagle SWAP_BOOT_USER=1 unset IN_VALID_UBOOT DO_UBOOT=1 ;; igepv2) SYSTEM=igepv2 unset IN_VALID_UBOOT DO_UBOOT=1 ;; touchbook) SYSTEM=touchbook unset IN_VALID_UBOOT DO_UBOOT=1 ;; panda) SYSTEM=panda unset IN_VALID_UBOOT DO_UBOOT=1 ;; esac if [ "$IN_VALID_UBOOT" ] ; then usage fi } function check_addon_type { IN_VALID_ADDON=1 if test "-$ADDON_TYPE-" = "-pico-" then ADDON=pico unset IN_VALID_ADDON fi if [ "$IN_VALID_ADDON" ] ; then usage fi } function check_fs_type { IN_VALID_FS=1 case "$FS_TYPE" in ext2) RFS=ext2 unset IN_VALID_FS ;; ext3) RFS=ext3 unset IN_VALID_FS ;; ext4) RFS=ext4 unset IN_VALID_FS ;; btrfs) if [ ! $(which mkfs.btrfs) ];then echo "Missing btrfs tools" sudo aptitude install btrfs-tools fi RFS=btrfs unset IN_VALID_FS ;; esac if [ "$IN_VALID_FS" ] ; then usage fi } function check_contents { # determine name of latest kernel built KERNEL_VERSION=2.6.38 if [ -d ./$KERNEL_VERSION-devel/deploy ]; then echo "Installing kernel modules for $KERNEL_VERSION" # find latest module package LATEST_UIMAGE=`ls -t1 ./$KERNEL_VERSION-devel/deploy/$KERNEL_VERSION-*.uImage | head -n1` else echo "No kernel image found in ./$KERNEL_VERSION-devel/deploy!" exit -1 fi if [ ! -f ./${RELEASE}/images/meego-${TYPE}-${ARCH}-beagle/meego-${TYPE}-${ARCH}-beagle-${RELEASE}.img ]; then echo "No meego image found at ./${RELEASE}/images/meego-${TYPE}-${ARCH}-beagle/meego-${TYPE}-${ARCH}-beagle-${RELEASE}.img" echo "Please run ./build_image.sh first" exit -1 fi } function usage { echo "usage: $(basename $0) --mmc /dev/sdX" cat < Unformated MMC Card Additional/Optional options: -h --help this help --uboot beagle - igepv2 - panda - --use-default-user (useful for serial only modes and when oem-config is broken) --rootfs ext3 ext4 - btrfs --boot_label boot partition label --rfs_label rootfs partition label --debug enable all debug options for troubleshooting EOF exit } function checkparm { if [ "$(echo $1|grep ^'\-')" ];then echo "E: Need an argument" usage fi } # parse commandline options while [ ! -z "$1" ]; do case $1 in -h|--help) usage MMC=1 ;; --mmc) checkparm $2 MMC="$2" if [[ "${MMC}" =~ "mmcblk" ]] then PARTITION_PREFIX="p" fi check_mmc ;; --uboot) checkparm $2 UBOOT_TYPE="$2" check_uboot_type ;; --addon) checkparm $2 ADDON_TYPE="$2" check_addon_type ;; --rootfs) checkparm $2 FS_TYPE="$2" check_fs_type ;; --use-default-user) DEFAULT_USER=1 ;; --boot_label) checkparm $2 BOOT_LABEL="$2" ;; --rfs_label) checkparm $2 RFS_LABEL="$2" ;; --debug) DEBUG=1 ;; esac shift done if [ ! "${MMC}" ];then usage fi check_contents check_uboot_type detect_software if [ "$DO_UBOOT" ];then dl_xload_uboot fi cleanup_sd create_partitions populate_boot populate_rootfs