Last active
August 31, 2015 21:24
-
-
Save RobertCNelson/716a0c616e600259e6f3 to your computer and use it in GitHub Desktop.
am57xx-evm-meta-ti
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #MACHINE=am57xx-evm bitbake-layers show-recipes "*-image-*" | |
| git clone git://arago-project.org/git/projects/oe-layersetup.git tisdk | |
| cd tisdk/ | |
| ./oe-layertool-setup.sh -f configs/arago-fido-config.txt | |
| cd build/ | |
| wget --no-check-certificate https://launchpad.net/linaro-toolchain-binaries/trunk/2013.03/+download/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux.tar.bz2 | |
| tar -jxvf gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux.tar.bz2 -C $HOME | |
| export PATH=$HOME/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/bin:$PATH | |
| . conf/setenv | |
| MACHINE=am57xx-evm bitbake core-image-weston |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -e | |
| # | |
| # Copyright (c) 2015 Robert Nelson <[email protected]> | |
| # | |
| # 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. | |
| # | |
| #REQUIREMENTS: | |
| #uEnv.txt bootscript support | |
| BOOT_LABEL="BOOT" | |
| unset USE_BETA_BOOTLOADER | |
| unset USE_LOCAL_BOOT | |
| unset LOCAL_BOOTLOADER | |
| #Defaults | |
| ROOTFS_TYPE=ext4 | |
| ROOTFS_LABEL=rootfs | |
| DIR="$PWD" | |
| TEMPDIR=$(mktemp -d) | |
| is_element_of () { | |
| testelt=$1 | |
| for validelt in $2 ; do | |
| [ $testelt = $validelt ] && return 0 | |
| done | |
| return 1 | |
| } | |
| ######################################################################### | |
| # | |
| # Define valid "--rootfs" root filesystem types. | |
| # | |
| ######################################################################### | |
| VALID_ROOTFS_TYPES="ext2 ext3 ext4" | |
| is_valid_rootfs_type () { | |
| if is_element_of $1 "${VALID_ROOTFS_TYPES}" ] ; then | |
| return 0 | |
| else | |
| return 1 | |
| fi | |
| } | |
| check_root () { | |
| if ! [ $(id -u) = 0 ] ; then | |
| echo "$0 must be run as sudo user or root" | |
| exit 1 | |
| fi | |
| } | |
| find_issue () { | |
| check_root | |
| ROOTFS=$(ls "${DIR}/" | grep -v md5 | grep -v gz | grep rootfs.tar) | |
| if [ "x${ROOTFS}" != "x" ] ; then | |
| echo "Debug: ARM rootfs: ${ROOTFS}" | |
| else | |
| echo "Make sure your in the right dir..." | |
| exit | |
| fi | |
| } | |
| check_for_command () { | |
| if ! which "$1" > /dev/null ; then | |
| echo -n "You're missing command $1" | |
| NEEDS_COMMAND=1 | |
| if [ -n "$2" ] ; then | |
| echo -n " (consider installing package $2)" | |
| fi | |
| echo | |
| fi | |
| } | |
| detect_software () { | |
| unset NEEDS_COMMAND | |
| check_for_command mkfs.vfat dosfstools | |
| check_for_command wget wget | |
| check_for_command git git | |
| check_for_command partprobe parted | |
| if [ "x${build_img_file}" = "xenable" ] ; then | |
| check_for_command kpartx kpartx | |
| fi | |
| if [ "${NEEDS_COMMAND}" ] ; then | |
| echo "" | |
| echo "Your system is missing some dependencies" | |
| echo "Debian/Ubuntu: sudo apt-get install dosfstools git-core kpartx wget parted" | |
| echo "Fedora: yum install dosfstools dosfstools git-core wget" | |
| echo "Gentoo: emerge dosfstools git wget" | |
| echo "" | |
| exit | |
| fi | |
| unset test_sfdisk | |
| test_sfdisk=$(LC_ALL=C sfdisk -v 2>/dev/null | grep 2.17.2 | awk '{print $1}') | |
| if [ "x${test_sdfdisk}" = "xsfdisk" ] ; then | |
| echo "" | |
| echo "Detected known broken sfdisk:" | |
| echo "See: https://github.com/RobertCNelson/netinstall/issues/20" | |
| echo "" | |
| exit | |
| fi | |
| unset wget_version | |
| wget_version=$(LC_ALL=C wget --version | grep "GNU Wget" | awk '{print $3}' | awk -F '.' '{print $2}' || true) | |
| case "${wget_version}" in | |
| 12|13) | |
| #wget before 1.14 in debian does not support sni | |
| echo "wget: [`LC_ALL=C wget --version | grep \"GNU Wget\" | awk '{print $3}' || true`]" | |
| echo "wget: [this version of wget does not support sni, using --no-check-certificate]" | |
| echo "wget: [http://en.wikipedia.org/wiki/Server_Name_Indication]" | |
| dl="wget --no-check-certificate" | |
| ;; | |
| *) | |
| dl="wget" | |
| ;; | |
| esac | |
| dl_continue="${dl} -c" | |
| dl_quiet="${dl} --no-verbose" | |
| } | |
| local_bootloader () { | |
| echo "" | |
| echo "Using Locally Stored Device Bootloader" | |
| echo "-----------------------------" | |
| mkdir -p ${TEMPDIR}/dl/ | |
| if [ "${spl_name}" ] ; then | |
| cp ${LOCAL_SPL} ${TEMPDIR}/dl/ | |
| SPL=${LOCAL_SPL##*/} | |
| echo "SPL Bootloader: ${SPL}" | |
| fi | |
| if [ "${boot_name}" ] ; then | |
| cp ${LOCAL_BOOTLOADER} ${TEMPDIR}/dl/ | |
| UBOOT=${LOCAL_BOOTLOADER##*/} | |
| echo "UBOOT Bootloader: ${UBOOT}" | |
| fi | |
| } | |
| drive_error_ro () { | |
| echo "-----------------------------" | |
| echo "Error: for some reason your SD card is not writable..." | |
| echo "Check: is the write protect lever set the locked position?" | |
| echo "Check: do you have another SD card reader?" | |
| echo "-----------------------------" | |
| echo "Script gave up..." | |
| exit | |
| } | |
| unmount_all_drive_partitions () { | |
| echo "" | |
| echo "Unmounting Partitions" | |
| echo "-----------------------------" | |
| NUM_MOUNTS=$(mount | grep -v none | grep "${media}" | wc -l) | |
| ## for (i=1;i<=${NUM_MOUNTS};i++) | |
| for ((i=1;i<=${NUM_MOUNTS};i++)) | |
| do | |
| DRIVE=$(mount | grep -v none | grep "${media}" | tail -1 | awk '{print $1}') | |
| umount ${DRIVE} >/dev/null 2>&1 || true | |
| done | |
| echo "Zeroing out Drive" | |
| echo "-----------------------------" | |
| dd if=/dev/zero of=${media} bs=1M count=100 || drive_error_ro | |
| sync | |
| dd if=${media} of=/dev/null bs=1M count=100 | |
| sync | |
| } | |
| sfdisk_partition_layout () { | |
| sfdisk_options="--force --in-order --Linux --unit M" | |
| sfdisk_boot_startmb="${conf_boot_startmb:-"1"}" | |
| sfdisk_boot_endmb="${conf_boot_endmb}" | |
| sfdisk_var_startmb="${conf_var_startmb}" | |
| test_sfdisk=$(LC_ALL=C sfdisk --help | grep -m 1 -e "--in-order" || true) | |
| if [ "x${test_sfdisk}" = "x" ] ; then | |
| echo "log: sfdisk: 2.26.x or greater detected" | |
| sfdisk_options="--force" | |
| sfdisk_boot_startmb="${sfdisk_boot_startmb}M" | |
| sfdisk_boot_endmb="${sfdisk_boot_endmb}M" | |
| sfdisk_var_startmb="${sfdisk_var_startmb}M" | |
| fi | |
| if [ "x${option_ro_root}" = "xenable" ] ; then | |
| LC_ALL=C sfdisk ${sfdisk_options} "${media}" <<-__EOF__ | |
| ${sfdisk_boot_startmb},${sfdisk_boot_endmb},${sfdisk_fstype},* | |
| ,${sfdisk_var_startmb},,- | |
| ,,,- | |
| __EOF__ | |
| media_rootfs_var_partition=3 | |
| else | |
| LC_ALL=C sfdisk ${sfdisk_options} "${media}" <<-__EOF__ | |
| ${sfdisk_boot_startmb},${sfdisk_boot_endmb},${sfdisk_fstype},* | |
| ,,,- | |
| __EOF__ | |
| fi | |
| sync | |
| } | |
| sfdisk_single_partition_layout () { | |
| sfdisk_options="--force --in-order --Linux --unit M" | |
| sfdisk_boot_startmb="${conf_boot_startmb:-"1"}" | |
| sfdisk_var_startmb="${conf_var_startmb}" | |
| test_sfdisk=$(LC_ALL=C sfdisk --help | grep -m 1 -e "--in-order" || true) | |
| if [ "x${test_sfdisk}" = "x" ] ; then | |
| echo "log: sfdisk: 2.26.x or greater detected" | |
| sfdisk_options="--force" | |
| sfdisk_boot_startmb="${sfdisk_boot_startmb}M" | |
| sfdisk_var_startmb="${sfdisk_var_startmb}M" | |
| fi | |
| if [ "x${option_ro_root}" = "xenable" ] ; then | |
| LC_ALL=C sfdisk ${sfdisk_options} "${media}" <<-__EOF__ | |
| ${sfdisk_boot_startmb},${sfdisk_var_startmb},${sfdisk_fstype},* | |
| ,,,- | |
| __EOF__ | |
| media_rootfs_var_partition=2 | |
| else | |
| LC_ALL=C sfdisk ${sfdisk_options} "${media}" <<-__EOF__ | |
| ${sfdisk_boot_startmb},,${sfdisk_fstype},* | |
| __EOF__ | |
| fi | |
| sync | |
| } | |
| dd_uboot_boot () { | |
| unset dd_uboot | |
| if [ ! "x${dd_uboot_count}" = "x" ] ; then | |
| dd_uboot="${dd_uboot}count=${dd_uboot_count} " | |
| fi | |
| if [ ! "x${dd_uboot_seek}" = "x" ] ; then | |
| dd_uboot="${dd_uboot}seek=${dd_uboot_seek} " | |
| fi | |
| if [ "x${build_img_file}" = "xenable" ] ; then | |
| dd_uboot="${dd_uboot}conv=notrunc " | |
| else | |
| if [ ! "x${dd_uboot_conf}" = "x" ] ; then | |
| dd_uboot="${dd_uboot}conv=${dd_uboot_conf} " | |
| fi | |
| fi | |
| if [ ! "x${dd_uboot_bs}" = "x" ] ; then | |
| dd_uboot="${dd_uboot}bs=${dd_uboot_bs}" | |
| fi | |
| echo "${uboot_name}: dd if=${uboot_name} of=${media} ${dd_uboot}" | |
| echo "-----------------------------" | |
| dd if=${TEMPDIR}/dl/${UBOOT} of=${media} ${dd_uboot} | |
| echo "-----------------------------" | |
| } | |
| dd_spl_uboot_boot () { | |
| unset dd_spl_uboot | |
| if [ ! "x${dd_spl_uboot_count}" = "x" ] ; then | |
| dd_spl_uboot="${dd_spl_uboot}count=${dd_spl_uboot_count} " | |
| fi | |
| if [ ! "x${dd_spl_uboot_seek}" = "x" ] ; then | |
| dd_spl_uboot="${dd_spl_uboot}seek=${dd_spl_uboot_seek} " | |
| fi | |
| if [ "x${build_img_file}" = "xenable" ] ; then | |
| dd_spl_uboot="${dd_spl_uboot}conv=notrunc " | |
| else | |
| if [ ! "x${dd_spl_uboot_conf}" = "x" ] ; then | |
| dd_spl_uboot="${dd_spl_uboot}conv=${dd_spl_uboot_conf} " | |
| fi | |
| fi | |
| if [ ! "x${dd_spl_uboot_bs}" = "x" ] ; then | |
| dd_spl_uboot="${dd_spl_uboot}bs=${dd_spl_uboot_bs}" | |
| fi | |
| echo "${spl_uboot_name}: dd if=${spl_uboot_name} of=${media} ${dd_spl_uboot}" | |
| echo "-----------------------------" | |
| dd if=${TEMPDIR}/dl/${SPL} of=${media} ${dd_spl_uboot} | |
| echo "-----------------------------" | |
| } | |
| format_partition_error () { | |
| echo "LC_ALL=C ${mkfs} ${mkfs_partition} ${mkfs_label}" | |
| echo "Failure: formating partition" | |
| exit | |
| } | |
| format_partition_try2 () { | |
| echo "-----------------------------" | |
| echo "BUG: [${mkfs_partition}] was not available so trying [${mkfs}] again in 5 seconds..." | |
| partprobe ${media} | |
| sync | |
| sleep 5 | |
| echo "-----------------------------" | |
| echo "Formating with: [${mkfs} ${mkfs_partition} ${mkfs_label}]" | |
| echo "-----------------------------" | |
| LC_ALL=C ${mkfs} ${mkfs_partition} ${mkfs_label} || format_partition_error | |
| sync | |
| } | |
| format_partition () { | |
| echo "Formating with: [${mkfs} ${mkfs_partition} ${mkfs_label}]" | |
| echo "-----------------------------" | |
| LC_ALL=C ${mkfs} ${mkfs_partition} ${mkfs_label} || format_partition_try2 | |
| sync | |
| } | |
| format_boot_partition () { | |
| mkfs_partition="${media_prefix}${media_boot_partition}" | |
| if [ "x${conf_boot_fstype}" = "xfat" ] ; then | |
| mount_partition_format="vfat" | |
| mkfs="mkfs.vfat -F 16" | |
| mkfs_label="-n ${BOOT_LABEL}" | |
| else | |
| mount_partition_format="${conf_boot_fstype}" | |
| mkfs="mkfs.${conf_boot_fstype}" | |
| mkfs_label="-L ${BOOT_LABEL}" | |
| fi | |
| format_partition | |
| } | |
| format_rootfs_partition () { | |
| if [ "x${option_ro_root}" = "xenable" ] ; then | |
| mkfs="mkfs.ext2" | |
| else | |
| mkfs="mkfs.${ROOTFS_TYPE}" | |
| fi | |
| mkfs_partition="${media_prefix}${media_rootfs_partition}" | |
| mkfs_label="-L ${ROOTFS_LABEL}" | |
| format_partition | |
| if [ "x${build_img_file}" = "xenable" ] ; then | |
| rootfs_drive="${conf_root_device}p${media_rootfs_partition}" | |
| else | |
| unset rootfs_uuid | |
| rootfs_uuid=$(/sbin/blkid -c /dev/null -s UUID -o value ${mkfs_partition} || true) | |
| if [ ! "x${rootfs_uuid}" = "x" ] ; then | |
| rootfs_drive="UUID=${rootfs_uuid}" | |
| else | |
| rootfs_drive="${conf_root_device}p${media_rootfs_partition}" | |
| fi | |
| fi | |
| if [ "x${option_ro_root}" = "xenable" ] ; then | |
| mkfs="mkfs.${ROOTFS_TYPE}" | |
| mkfs_partition="${media_prefix}${media_rootfs_var_partition}" | |
| mkfs_label="-L var" | |
| format_partition | |
| if [ "x${build_img_file}" = "xenable" ] ; then | |
| rootfs_var_drive="${conf_root_device}p${media_rootfs_var_partition}" | |
| else | |
| unset rootfs_var_uuid | |
| rootfs_var_uuid=$(/sbin/blkid -c /dev/null -s UUID -o value ${mkfs_partition} || true) | |
| if [ ! "x${rootfs_var_uuid}" = "x" ] ; then | |
| rootfs_var_drive="UUID=${rootfs_var_uuid}" | |
| else | |
| rootfs_var_drive="${conf_root_device}p${media_rootfs_var_partition}" | |
| fi | |
| fi | |
| fi | |
| } | |
| create_partitions () { | |
| unset bootloader_installed | |
| media_boot_partition=1 | |
| media_rootfs_partition=2 | |
| echo "" | |
| case "${bootloader_location}" in | |
| fatfs_boot) | |
| conf_boot_endmb=${conf_boot_endmb:-"12"} | |
| echo "Using sfdisk to create partition layout" | |
| echo "Version: `LC_ALL=C sfdisk --version`" | |
| echo "-----------------------------" | |
| if [ "x${bborg_production}" = "xenable" ] ; then | |
| conf_boot_endmb="96" | |
| fi | |
| sfdisk_partition_layout | |
| ;; | |
| dd_uboot_boot) | |
| echo "Using dd to place bootloader on drive" | |
| echo "-----------------------------" | |
| dd_uboot_boot | |
| bootloader_installed=1 | |
| sfdisk_single_partition_layout | |
| media_rootfs_partition=1 | |
| ;; | |
| dd_spl_uboot_boot) | |
| echo "Using dd to place bootloader on drive" | |
| echo "-----------------------------" | |
| dd_spl_uboot_boot | |
| dd_uboot_boot | |
| bootloader_installed=1 | |
| if [ "x${bborg_production}" = "xenable" ] ; then | |
| conf_boot_endmb="96" | |
| conf_boot_fstype="fat" | |
| sfdisk_fstype="0xE" | |
| sfdisk_partition_layout | |
| else | |
| sfdisk_single_partition_layout | |
| media_rootfs_partition=1 | |
| fi | |
| ;; | |
| *) | |
| echo "Using sfdisk to create partition layout" | |
| echo "Version: `LC_ALL=C sfdisk --version`" | |
| echo "-----------------------------" | |
| sfdisk_partition_layout | |
| ;; | |
| esac | |
| echo "Partition Setup:" | |
| echo "-----------------------------" | |
| LC_ALL=C fdisk -l "${media}" | |
| echo "-----------------------------" | |
| if [ "x${build_img_file}" = "xenable" ] ; then | |
| media_loop=$(losetup -f || true) | |
| if [ ! "${media_loop}" ] ; then | |
| echo "losetup -f failed" | |
| echo "Unmount some via: [sudo losetup -a]" | |
| echo "-----------------------------" | |
| losetup -a | |
| echo "sudo kpartx -d /dev/loopX ; sudo losetup -d /dev/loopX" | |
| echo "-----------------------------" | |
| exit | |
| fi | |
| losetup ${media_loop} "${media}" | |
| kpartx -av ${media_loop} | |
| sleep 1 | |
| sync | |
| test_loop=$(echo ${media_loop} | awk -F'/' '{print $3}') | |
| if [ -e /dev/mapper/${test_loop}p${media_boot_partition} ] && [ -e /dev/mapper/${test_loop}p${media_rootfs_partition} ] ; then | |
| media_prefix="/dev/mapper/${test_loop}p" | |
| else | |
| ls -lh /dev/mapper/ | |
| echo "Error: not sure what to do (new feature)." | |
| exit | |
| fi | |
| else | |
| partprobe ${media} | |
| fi | |
| if [ "x${media_boot_partition}" = "x${media_rootfs_partition}" ] ; then | |
| mount_partition_format="${ROOTFS_TYPE}" | |
| format_rootfs_partition | |
| else | |
| format_boot_partition | |
| format_rootfs_partition | |
| fi | |
| } | |
| populate_boot () { | |
| echo "Populating Boot Partition" | |
| echo "-----------------------------" | |
| if [ ! -d ${TEMPDIR}/disk ] ; then | |
| mkdir -p ${TEMPDIR}/disk | |
| fi | |
| partprobe ${media} | |
| if ! mount -t ${mount_partition_format} ${media_prefix}${media_boot_partition} ${TEMPDIR}/disk; then | |
| echo "-----------------------------" | |
| echo "BUG: [${media_prefix}${media_boot_partition}] was not available so trying to mount again in 5 seconds..." | |
| partprobe ${media} | |
| sync | |
| sleep 5 | |
| echo "-----------------------------" | |
| if ! mount -t ${mount_partition_format} ${media_prefix}${media_boot_partition} ${TEMPDIR}/disk; then | |
| echo "-----------------------------" | |
| echo "Unable to mount ${media_prefix}${media_boot_partition} at ${TEMPDIR}/disk to complete populating Boot Partition" | |
| echo "Please retry running the script, sometimes rebooting your system helps." | |
| echo "-----------------------------" | |
| exit | |
| fi | |
| fi | |
| lsblk | grep -v sr0 | |
| echo "-----------------------------" | |
| if [ "${spl_name}" ] ; then | |
| if [ -f ${TEMPDIR}/dl/${SPL} ] ; then | |
| if [ ! "${bootloader_installed}" ] ; then | |
| cp -v ${TEMPDIR}/dl/${SPL} ${TEMPDIR}/disk/${spl_name} | |
| echo "-----------------------------" | |
| fi | |
| fi | |
| fi | |
| if [ "${boot_name}" ] ; then | |
| if [ -f ${TEMPDIR}/dl/${UBOOT} ] ; then | |
| if [ ! "${bootloader_installed}" ] ; then | |
| cp -v ${TEMPDIR}/dl/${UBOOT} ${TEMPDIR}/disk/${boot_name} | |
| echo "-----------------------------" | |
| fi | |
| fi | |
| fi | |
| cd ${TEMPDIR}/disk | |
| sync | |
| cd "${DIR}"/ | |
| echo "Debug: Contents of Boot Partition" | |
| echo "-----------------------------" | |
| ls -lh ${TEMPDIR}/disk/ | |
| du -sh ${TEMPDIR}/disk/ | |
| echo "-----------------------------" | |
| umount ${TEMPDIR}/disk || true | |
| echo "Finished populating Boot Partition" | |
| echo "-----------------------------" | |
| } | |
| populate_rootfs () { | |
| echo "Populating rootfs Partition" | |
| echo "Please be patient, this may take a few minutes, as its transfering a lot of data.." | |
| echo "-----------------------------" | |
| if [ ! -d ${TEMPDIR}/disk ] ; then | |
| mkdir -p ${TEMPDIR}/disk | |
| fi | |
| partprobe ${media} | |
| if ! mount -t ${ROOTFS_TYPE} ${media_prefix}${media_rootfs_partition} ${TEMPDIR}/disk; then | |
| echo "-----------------------------" | |
| echo "BUG: [${media_prefix}${media_rootfs_partition}] was not available so trying to mount again in 5 seconds..." | |
| partprobe ${media} | |
| sync | |
| sleep 5 | |
| echo "-----------------------------" | |
| if ! mount -t ${ROOTFS_TYPE} ${media_prefix}${media_rootfs_partition} ${TEMPDIR}/disk; then | |
| echo "-----------------------------" | |
| echo "Unable to mount ${media_prefix}${media_rootfs_partition} at ${TEMPDIR}/disk to complete populating rootfs Partition" | |
| echo "Please retry running the script, sometimes rebooting your system helps." | |
| echo "-----------------------------" | |
| exit | |
| fi | |
| fi | |
| if [ "x${option_ro_root}" = "xenable" ] ; then | |
| if [ ! -d ${TEMPDIR}/disk/var ] ; then | |
| mkdir -p ${TEMPDIR}/disk/var | |
| fi | |
| if ! mount -t ${ROOTFS_TYPE} ${media_prefix}${media_rootfs_var_partition} ${TEMPDIR}/disk/var; then | |
| echo "-----------------------------" | |
| echo "BUG: [${media_prefix}${media_rootfs_var_partition}] was not available so trying to mount again in 5 seconds..." | |
| partprobe ${media} | |
| sync | |
| sleep 5 | |
| echo "-----------------------------" | |
| if ! mount -t ${ROOTFS_TYPE} ${media_prefix}${media_rootfs_var_partition} ${TEMPDIR}/disk/var; then | |
| echo "-----------------------------" | |
| echo "Unable to mount ${media_prefix}${media_rootfs_var_partition} at ${TEMPDIR}/disk/var to complete populating rootfs Partition" | |
| echo "Please retry running the script, sometimes rebooting your system helps." | |
| echo "-----------------------------" | |
| exit | |
| fi | |
| fi | |
| fi | |
| lsblk | grep -v sr0 | |
| echo "-----------------------------" | |
| if [ -f "${DIR}/${ROOTFS}" ] ; then | |
| if which pv > /dev/null ; then | |
| pv "${DIR}/${ROOTFS}" | tar --numeric-owner --preserve-permissions -xf - -C ${TEMPDIR}/disk/ | |
| else | |
| echo "pv: not installed, using tar verbose to show progress" | |
| tar --numeric-owner --preserve-permissions --verbose -xf "${DIR}/${ROOTFS}" -C ${TEMPDIR}/disk/ | |
| fi | |
| echo "Transfer of data is Complete, now syncing data to disk..." | |
| sync | |
| sync | |
| echo "-----------------------------" | |
| fi | |
| if [ -f "${DIR}"/zImage ] ; then | |
| mkdir -p ${TEMPDIR}/disk/boot/ | |
| cp -v "${DIR}"/zImage ${TEMPDIR}/disk/boot/ | |
| fi | |
| if [ -f "${DIR}"/zImage-am57xx-beagle-x15.dtb ] ; then | |
| mkdir -p ${TEMPDIR}/disk/boot/ | |
| cp -v "${DIR}"/zImage-am57xx-beagle-x15.dtb ${TEMPDIR}/disk/boot/am57xx-beagle-x15.dtb | |
| fi | |
| cd ${TEMPDIR}/disk/ | |
| sync | |
| sync | |
| cd "${DIR}/" | |
| if [ "x${option_ro_root}" = "xenable" ] ; then | |
| umount ${TEMPDIR}/disk/var || true | |
| fi | |
| umount ${TEMPDIR}/disk || true | |
| if [ "x${build_img_file}" = "xenable" ] ; then | |
| sync | |
| kpartx -d ${media_loop} || true | |
| losetup -d ${media_loop} || true | |
| fi | |
| echo "Finished populating rootfs Partition" | |
| echo "-----------------------------" | |
| echo "setup_sdcard.sh script complete" | |
| if [ -f "${DIR}/user_password.list" ] ; then | |
| echo "-----------------------------" | |
| echo "The default user:password for this image:" | |
| cat "${DIR}/user_password.list" | |
| echo "-----------------------------" | |
| fi | |
| if [ "x${build_img_file}" = "xenable" ] ; then | |
| echo "Image file: ${media}" | |
| echo "-----------------------------" | |
| fi | |
| } | |
| check_mmc () { | |
| FDISK=$(LC_ALL=C fdisk -l 2>/dev/null | grep "Disk ${media}:" | awk '{print $2}') | |
| if [ "x${FDISK}" = "x${media}:" ] ; then | |
| echo "" | |
| echo "I see..." | |
| echo "" | |
| echo "lsblk:" | |
| lsblk | grep -v sr0 | |
| echo "" | |
| unset response | |
| echo -n "Are you 100% sure, on selecting [${media}] (y/n)? " | |
| read response | |
| if [ "x${response}" != "xy" ] ; then | |
| exit | |
| fi | |
| echo "" | |
| else | |
| echo "" | |
| echo "Are you sure? I Don't see [${media}], here is what I do see..." | |
| echo "" | |
| echo "lsblk:" | |
| lsblk | grep -v sr0 | |
| echo "" | |
| exit | |
| fi | |
| } | |
| process_dtb_conf () { | |
| if [ "${conf_warning}" ] ; then | |
| show_board_warning | |
| fi | |
| echo "-----------------------------" | |
| #defaults, if not set... | |
| conf_boot_startmb=${conf_boot_startmb:-"1"} | |
| #https://wiki.linaro.org/WorkingGroups/KernelArchived/Projects/FlashCardSurvey | |
| conf_root_device=${conf_root_device:-"/dev/mmcblk0"} | |
| #error checking... | |
| if [ ! "${conf_boot_fstype}" ] ; then | |
| conf_boot_fstype="${ROOTFS_TYPE}" | |
| fi | |
| case "${conf_boot_fstype}" in | |
| fat) | |
| sfdisk_fstype="0xE" | |
| ;; | |
| ext2|ext3|ext4) | |
| sfdisk_fstype="0x83" | |
| ;; | |
| *) | |
| echo "Error: [conf_boot_fstype] not recognized, stopping..." | |
| exit | |
| ;; | |
| esac | |
| } | |
| usage () { | |
| echo "usage: sudo $(basename $0) --mmc /dev/sdX" | |
| #tabed to match | |
| cat <<-__EOF__ | |
| ----------------------------- | |
| Bugs email: "bugs at rcn-ee.com" | |
| Required Options: | |
| --mmc </dev/sdX> or --img <filename.img> | |
| Additional Options: | |
| -h --help | |
| --probe-mmc | |
| <list all partitions: sudo ./setup_sdcard.sh --probe-mmc> | |
| __EOF__ | |
| exit | |
| } | |
| checkparm () { | |
| if [ "$(echo $1|grep ^'\-')" ] ; then | |
| echo "E: Need an argument" | |
| usage | |
| fi | |
| } | |
| error_invalid_dtb=1 | |
| # parse commandline options | |
| while [ ! -z "$1" ] ; do | |
| case $1 in | |
| -h|--help) | |
| usage | |
| media=1 | |
| ;; | |
| --probe-mmc) | |
| media="/dev/idontknow" | |
| check_root | |
| check_mmc | |
| ;; | |
| --mmc) | |
| checkparm $2 | |
| media="$2" | |
| media_prefix="${media}" | |
| echo ${media} | grep mmcblk >/dev/null && media_prefix="${media}p" | |
| check_root | |
| check_mmc | |
| ;; | |
| --img|--img-[1248]gb) | |
| checkparm $2 | |
| name=${2:-image} | |
| gsize=$(echo "$1" | sed -ne 's/^--img-\([[:digit:]]\+\)gb$/\1/p') | |
| # --img defaults to --img-2gb | |
| gsize=${gsize:-2} | |
| imagename=${name%.img}-${gsize}gb.img | |
| media="${DIR}/${imagename}" | |
| build_img_file="enable" | |
| check_root | |
| if [ -f "${media}" ] ; then | |
| rm -rf "${media}" || true | |
| fi | |
| #FIXME: (should fit most microSD cards) | |
| #eMMC: (dd if=/dev/mmcblk1 of=/dev/null bs=1M #MB) | |
| #Micron 3744MB (bbb): 3925868544 bytes -> 3925.86 Megabyte | |
| #Kingston 3688MB (bbb): 3867148288 bytes -> 3867.15 Megabyte | |
| #Kingston 3648MB (x15): 3825205248 bytes -> 3825.21 Megabyte (3648) | |
| # | |
| ### seek=$((1024 * (700 + (gsize - 1) * 1000))) | |
| ## 1000 1GB = 700 #2GB = 1700 #4GB = 3700 | |
| ## 990 1GB = 700 #2GB = 1690 #4GB = 3670 | |
| # | |
| ### seek=$((1024 * (gsize * 850))) | |
| ## x 850 (85%) #1GB = 850 #2GB = 1700 #4GB = 3400 | |
| # | |
| dd if=/dev/zero of="${media}" bs=1024 count=0 seek=$((1024 * (gsize * 850))) | |
| ;; | |
| --ro) | |
| conf_var_startmb="2048" | |
| option_ro_root="enable" | |
| ;; | |
| --rootfs) | |
| checkparm $2 | |
| ROOTFS_TYPE="$2" | |
| ;; | |
| --boot_label) | |
| checkparm $2 | |
| BOOT_LABEL="$2" | |
| ;; | |
| --rootfs_label) | |
| checkparm $2 | |
| ROOTFS_LABEL="$2" | |
| ;; | |
| --spl) | |
| checkparm $2 | |
| LOCAL_SPL="$2" | |
| USE_LOCAL_BOOT=1 | |
| ;; | |
| --bootloader) | |
| checkparm $2 | |
| LOCAL_BOOTLOADER="$2" | |
| USE_LOCAL_BOOT=1 | |
| ;; | |
| --use-beta-bootloader) | |
| USE_BETA_BOOTLOADER=1 | |
| ;; | |
| --bbg-flasher) | |
| bbg_flasher="enable" | |
| ;; | |
| --bbb-usb-flasher|--usb-flasher) | |
| usb_flasher="enable" | |
| ;; | |
| --bbb-flasher|--emmc-flasher) | |
| emmc_flasher="enable" | |
| ;; | |
| --beagleboard.org-production) | |
| bborg_production="enable" | |
| ;; | |
| esac | |
| shift | |
| done | |
| if [ ! "${media}" ] ; then | |
| echo "ERROR: --mmc undefined" | |
| usage | |
| fi | |
| if ! is_valid_rootfs_type ${ROOTFS_TYPE} ; then | |
| echo "ERROR: ${ROOTFS_TYPE} is not a valid root filesystem type" | |
| echo "Valid types: ${VALID_ROOTFS_TYPES}" | |
| exit | |
| fi | |
| find_issue | |
| detect_software | |
| spl_name="MLO" | |
| boot_name="u-boot.img" | |
| LOCAL_SPL="MLO" | |
| LOCAL_BOOTLOADER="u-boot.img" | |
| USE_LOCAL_BOOT=1 | |
| #Bootloader Partition: | |
| conf_boot_fstype="fat" | |
| bootloader_location="fatfs_boot" | |
| spl_name="MLO" | |
| boot_name="u-boot.img" | |
| process_dtb_conf | |
| local_bootloader | |
| if [ ! "x${build_img_file}" = "xenable" ] ; then | |
| unmount_all_drive_partitions | |
| fi | |
| create_partitions | |
| populate_boot | |
| populate_rootfs | |
| # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment