Скрипт mk_mx28_sd_v2, нашел на вашем форуме.
#!/bin/bash
# Copyright (c) 2010 Freescale Semiconductor, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# o Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# o Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# o Neither the name of Freescale Semiconductor, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This script prepares a SD card with a boot image for the i.MX28 EVK
# Requires the root file system with a valid imx28 boot stream
#
# Modification History
#
# 1.0.0 23Apr2010 Chris S. Original version.
#
# 1.0.1 04Aug2010 Franz W. Modified to avoid already-mounted sdX drives.
# This will help you to avoid trashing your
# hard drive.
#
# 1.0.2 20Aug2010 Franz W. This version now uses "dd" to copy the binary image of rootfs
# onto the SD card.
#
# 1.0.3 26Aug2010 Brad B. Sometimes Linux hosts will automount /dev/sdX3
# after MBR is written and before the filesystem
# is transferred. Added check for this and appropriate
# umount command.
#
# 1.0.4 15Sep2010 creed Added -d -u -x options.
#
# 1.0.5 16Sep2010 Franz W Fixed -x option, which was not working with
# inserted un-mountable media.
# 1.1 27Sep2010 Rob L Added -b -r options.
# Fixed the grep/if issue that was causing the script to fail on some
# machines.
# Script can now be called from anywhere as long as mk_hdr.sh
# is pathed or in the local directory that mk_mx28_sd is being called from.
set -e
opt=''
function print_usage() {
echo -e "\nUsage: $0 [-hndux] /dev/sd# \nwhere /dev/sd# is a valid devnode for the SD card."
echo " -h Help. (This information.)"
echo " -n Do nothing. Just echo intended actions."
echo " -d Use HAB disabled boot images."
echo " -u Place U-boot on the SD card instead of Linux."
echo " -x Enable expert mode (see below)."
echo " -b Do not install the rootfs (bootstream only)."
echo " -r Do not install the bootstream (rootfs only)."
echo -e ""
echo -e "Run this script in the ltib directory."
echo -e "The ./rootfs/boot directory contains the kernel and boot stream files to be installed."
echo -e ""
echo -e "This utility uses sudo to: "
echo -e " 1. erase the MBR on the given /dev/sd#"
echo -e " 2. repartitions the device as required to boot the imx28 from sd media"
echo -e " 3. installs the boot stream, kernel, and root filesystem to the sd card"
echo -e ""
echo -e "Notes:"
echo -e "This script will refuse to work on /dev/sda, which is usually a hard disk."
echo -e "This script will refuse to work on any medium which is ALREADY MOUNTED"
echo -e "when the script starts. Therefore, start the script, then insert the card"
echo -e "when asked if you want to continue."
echo -e "\nExpert mode causes the script to run even if the device is already"
echo -e "mounted, and will not ask if you want to continue."
echo -e ""
exit 1
}
DEBUG=
put_uboot=0
use_hab=1
require_unmounted=1
dont_ask=0
no_rootfs=0
no_bootstream=0
while getopts "hnduxbr" Option
do
case $Option in
h ) print_usage
exit 0
;;
n ) DEBUG="echo"
echo "*** DEBUG mode. No changes will be applied. ***"
;;
d ) use_hab=0
;;
u ) put_uboot=1
;;
x ) require_unmounted=0
dont_ask=1
;;
b ) no_rootfs=1
;;
r ) no_bootstream=1
;;
esac
done
# Shift out the used-up command-line arguments.
shift $(($OPTIND - 1))
if [[ ! $1 ]]
then
print_usage
exit 1
fi
# The disk-name is in $1.
# Disallow the use of sda
if [[ $1 == *sda* ]]
then
echo -e "This script will not work on /dev/sda, which is usually a hard disk."
echo -e "Exiting."
exit 1
fi
# Remember the device name
p0=$1
# Construct three volume-names
p1=$1"1"
p2=$1"2"
p3=$1"3"
# This function tests to see if the given device $1 is
# mounted, as shown in /etc/mtab.
# Return value $bMounted==1 if mounted, zero otherwise.
function is_mounted() {
if grep -q -e "^$1.*" /etc/mtab; then
# mounted
bMounted=1
else
# not mounted
bMounted=0
fi
}
# This function partitions uses "sudo fdisk" to partition device "/dev/sdX"
# named by parameter $1 as follows:
# Device Size Id System
# /dev/sdX1 32 Mbytes b W95 FAT32
# /dev/sdX2 32 Mbytes 53 OnTrack DM6 Aux3
# /dev/sdX3 All remaining 83 Linux
#
# $1 contains the name of the device to partition.
function make_nominal_partition() {
if [[ $DEBUG ]] ;
then
WRITE=q
else
WRITE=w
fi
echo "o
n
p
1
1
+32M
t
b
n
p
2
+32M
t
2
53
n
p
3
t
3
83
p
$WRITE" | sudo fdisk $1
}
# This function installs the boot stream named in $1
# into the device named in $2 in partition number $3.
function install_boot_stream() {
echo -e "\nInstalling boot stream $1 on $2$3..."
if [ -f ./mk_hdr.sh ]
then
mk_hdr="./mk_hdr.sh"
else
mk_hdr="mk_hdr.sh"
fi
$DEBUG $mk_hdr `sudo fdisk -lu $2 | awk '$5==53 {print $2}'` 1 > temp.bin
$DEBUG sudo dd if=temp.bin of=$2$3 ibs=512 conv=sync
$DEBUG sudo dd if=$1 of=$2$3 ibs=512 obs=512 seek=1 conv=sync
# place uImage to first partition if using uboot
if [[ $put_uboot -eq 1 ]] ;
then
if grep -q -e "^$p1.*" /etc/mtab; then
$DEBUG sudo umount $p1
fi
$DEBUG sudo dd if=./rootfs/boot/uImage of=$2 ibs=512 obs=512 seek=256 conv=sync
fi
$DEBUG sync
rm temp.bin
echo -e "...finished installing boot stream on $2$3.\n"
}
# This function installs the rootfs directory named in $1
# into the device named in $2 in partition number $3.
function install_ext2_rootfs() {
$DEBUG sudo mkdir ./zzzsdcard
echo -e "\nFormatting rootfs partition...\n"
$DEBUG sudo mkfs.ext2 $2$3
$DEBUG sudo mount -t ext2 $2$3 ./zzzsdcard
echo -e "\nInstalling rootfs on $2$3..."
$DEBUG sudo cp -ar $1 ./zzzsdcard
$DEBUG sudo umount ./zzzsdcard # This may take some time to sync the files before unmounting.
echo -e "\nCleaning up..."
$DEBUG sudo rmdir ./zzzsdcard
echo -e "...finished installing rootfs on $2$3.\n"
}
#############################################
# OK, here it goes.
#############################################
is_mounted $p0
if [[ $require_unmounted -eq 1 ]]; then
# This script is not running in "expert" mode.
# We care if the target volume is already mounted. We don't
# want to clobber the contents accidentally.
if [[ $bMounted -eq 1 ]]; then
# The target volume is indeed already mounted.
echo
echo "The requested volume $p0 is already mounted."
echo "Possibly this volume is a hard disk or some other important medium."
echo "Therefore, this script will exit and not touch it."
echo "Please make sure your sd card is unmounted before running this script."
exit 1
fi
else
# This script is running in "expert" mode.
# We will clobber any contents of the target volume.
echo
fi
# If we got to here, then we are ready to process the target volume.
echo -e "\nInsert the specified device ($p0) now, if you have not already done so.\n"
# Ask the user if they want to make changes unless they said to skip this.
if [[ $dont_ask -eq 0 ]]; then
echo -e "\nThis script requires the use of 'sudo' and erases the content of the specified device ($p0)"
echo -e "Are you sure you want to continue? (yes/no): "
read opt
if [ ! "$opt" = "yes" ]; then
echo -e "\nAborting..., nothing was altered!"
exit 1
fi
fi
# Pick boot stream based on whether to use HAB and whether to write uboot or linux.
if [[ $no_bootstream -ne 1 ]]; then
ivt=""
if [[ $use_hab -eq 1 ]]; then
ivt="ivt_"
fi
if [[ $put_uboot -eq 1 ]]; then
app_name="uboot"
else
app_name="linux"
fi
sb_name="imx28_${ivt}${app_name}.sb"
$DEBUG make_nominal_partition $p0
$DEBUG install_boot_stream ./rootfs/boot/$sb_name $p0 2
fi
if [[ $no_rootfs -ne 1 ]]; then
# Linux may automount /dev/sdX3 at this point, check and unmount if so...
is_mounted $p3
if [[ $bMounted -eq 1 ]] ;
then
echo
echo "$p3 was automounted, unmounting..."
sudo umount $p3
fi
install_ext2_rootfs "./rootfs/*" $p0 3
fi
echo -e "\nDone! Plug the SD/MMC card into the i.MX board and power-on."
#End