Rewrite of card scripts completely

Reduce the card specific code to what's needed.

Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
This commit is contained in:
Andreas Müller
2018-10-02 09:58:24 +02:00
parent 3cc5a3b448
commit ca5f873b08
18 changed files with 773 additions and 541 deletions

View File

@@ -0,0 +1,15 @@
#! /bin/bash
# imx-card-kernel-write.sh
# (c) Copyright 2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script writes kernel+modules to SDCard. To
# select card device a dialog based GUI is used.
# Includes
. `dirname $0`/include/common-helpers.inc
. `dirname $0`/include/card-helpers.inc
. `dirname $0`/include/machine-imx.inc
StartCardKernelWrite

14
scripts/imx-card-write.sh Executable file
View File

@@ -0,0 +1,14 @@
#! /bin/bash
# imx-card-write.sh
# (c) Copyright 2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script writes image to sdcard and aligns rootfs partition to max size.
# Includes
. `dirname $0`/include/common-helpers.inc
. `dirname $0`/include/card-helpers.inc
. `dirname $0`/include/machine-imx.inc
StartCardWrite

View File

@@ -0,0 +1,279 @@
#! /bin/bash
# card-helpers.inc
# (c) Copyright 2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script contains some helper functions and can be sourced by other
# scripts
# SelectCardDevice() creates a dialog to select one of all available removable
# devices. The path to the selected device is stored in the variale DevicePath.
SelectCardDevice() {
if [ -z "$DevicePath" ]; then
iCount=0
for dev in /dev/sd[a-z] ; do
DeviceFile=`basename $dev`
# we are only interested in removable devices
if [ `cat /sys/block/$DeviceFile/removable` = '1' ] && [ `cat /sys/block/$DeviceFile/size` -gt "0" ]; then
iCount=`expr $iCount + 1`
DevicePathArr[${iCount}]=$dev
# pretify display
secondline=
display=
IFS=$'\n'
for line in `lsblk --raw --noheadings --output NAME,LABEL,MODEL $dev` ; do
# a bug in lsblk?
line=`echo $line | sed 's:\\\x20: :g'`
if [ "x$secondline" = "x" ]; then
# first line - it is for device
secondline="1"
display="$line"
else
if [ "x$secondline" = "x1" ]; then
secondline="2"
# second line - header + partition
display="$display / partitions: $line"
else
# second line - separator + partition
display="$display + $line"
fi
fi
done
display=`echo $display | sed 's: : :g'`
display=`echo $display | sed 's: : :g'`
display=`echo $display | sed 's: : :g'`
unset IFS
menuitems+=( "$iCount" "$display" )
fi
done
if [ $iCount -eq 0 ]; then
ErrorOut 'No removable devices found!'
fi
dialog --title 'Select card device'\
--menu 'Move using [UP] [DOWN],[Enter] to select' 10 100 $iCount\
"${menuitems[@]}"\
2>/tmp/menuitem.$$
# get OK/Cancel
sel=$?
# get selected menuitem
menuitem=`cat /tmp/menuitem.$$`
rm -f /tmp/menuitem.$$
# Cancel Button or <ESC>
if [ $sel -eq 1 -o $sel -eq 255 ] ; then
ErrorOut 'Cancel selected at SelectCardDevice().'
fi
DevicePath=${DevicePathArr[$menuitem]}
fi
}
# SelectDeployedFile() opens a dialog to select file containing rootfs/kernel/...
# It expects one parameter which contains find parameters e.g for raspberrypi:
# '-name *.rpi-sdimg -type l'.
# Output variables:
# DeployedFile: The file selected
# DeployFileDir: Path of the file selected
SelectDeployedFile() {
if [ -z "$DeployedFile" ]; then
# OE environment found?
if [ -z "$BUILDDIR" ]; then
ErrorOut "The environment variable BUILDDIR is not set. It is usually set before running bitbake."
fi
iCount=0
strSelection=
for grep_result in `grep -h TMPDIR $BUILDDIR/conf/*.conf | sed -e s/' '/''/g -e s/'\"'/''/g`; do
# exclude comments
tmp_dir=`echo $grep_result | grep '^TMPDIR='`
if [ ! -z "$tmp_dir" ]; then
OeTmpDir=`echo $tmp_dir | sed -e s/'TMPDIR='/''/g`
fi
done
for BuildPath in ${OeTmpDir}-*; do
for i in `find ${BuildPath}/deploy/images/${Machine} $FindString | sort` ; do
iCount=`expr $iCount + 1`
RootFileNameArr[${iCount}]=$i
strSelection="$strSelection $iCount "`basename $i`
done
done
# were files found?
if [ $iCount -eq 0 ]; then
ErrorOut "No files found in ${OeTmpDir}-\* matching $FindString"
fi
dialog --title 'Select rootfs'\
--menu 'Move using [UP] [DOWN],[Enter] to select' 30 100 $iCount\
${strSelection}\
2>/tmp/menuitem.$$
# get OK/Cancel
sel=$?
# get selected menuitem
menuitem=`cat /tmp/menuitem.$$`
rm -f /tmp/menuitem.$$
# Cancel Button or <ESC>
if [ $sel -eq 1 -o $sel -eq 255 ] ; then
ErrorOut "Cancel selected at SelectDeployedFile()."
fi
DeployedFile=${RootFileNameArr[$menuitem]}
fi
DeployFileDir=`dirname $DeployedFile`
# Now that we know the file, exact_machine can be set without wildcards
Machine=`basename $DeployFileDir`
}
SelectSuSudo() {
# Select su/sudo
dialog --title 'Select how you want to logon as root'\
--menu 'Move using [UP] [DOWN],[Enter] to select' 10 100 2 1 su 2 sudo \
2>/tmp/menuitem.$$
# get OK/Cancel
sel=$?
# get selected menuitem
menuitem=`cat /tmp/menuitem.$$`
rm -f /tmp/menuitem.$$
# Cancel Button or <ESC>
if [ $sel -eq 1 -o $sel -eq 255 ] ; then
ErrorOut "Cancel selected at SelectSuSudo()."
fi
}
SelectInOut() {
# DevicePath for target card
SelectCardDevice
# select rootfs source
SelectDeployedFile
}
# EnsureUnmount() tests if a device partition is mounted. If so partition is
# unmounted. Device name is expected in first parameter.
EnsureUnmount() {
# check if the card is currently mounted
MOUNTSTR=$(mount | grep $1)
if [ -n "$MOUNTSTR" ] ; then
echo -e "\n$1 is mounted. Unmounting..."
umount -f ${1}?*
echo "${style_green}Unmount done${style_normal}"
fi
}
# PrepareWrite performs actions required before data write can start:
# * Check if source and destination locations are valid
# * Extract source path to variable DeployFileDir
# * eventually unmount destination
# The following variables are expected:
# * DevicePath: destination block-device e.g '/dev/sdc'
# * DeployedFile (optional): source file (rootfs/kernel/..)
PrepareWrite() {
# device node valid?
if [ ! -b "${DevicePath}" ] ; then
ErrorOut "$DevicePath is not a valid block device!"
fi
if [ -n "${DeployedFile}" ] ; then
# rootfs/kernel valid?
if [ ! -e "${DeployedFile}" ] ; then
ErrorOut "$DeployedFile can not be found!"
fi
fi
EnsureUnmount $DevicePath
}
# RunUserStartRoot() tests if we are running as root. If not, it calls SelectInOut. It expects
# SelectInOut to leave the required parameters for root call in variable RootParams.
# After this it asks user how to log on as root. Then the main script is started
# as root.
RunUserStartRoot() {
# we are not already root?
if [ ! $( id -u ) -eq 0 ]; then
SelectInOut
SelectSuSudo
# prepare passing params to root-run - make sure they have same
# signature as loaded at the end of this file
RootParams="$DevicePath $DeployedFile $DeployFileDir $Machine $FindString $KernelImageType"
# dialog's gui is done here
clear
echo
if [ "x$1" = "x" ] ; then
# No message text passed: use standard
echo "${style_bold}All data currenly stored on $DevicePath will be overwritten!${style_normal}"
else
# Use message text passed
echo $1 | sed "s|\%DevicePath\%|$DevicePath|"
fi
if [ $menuitem -eq 1 ]; then
echo -e "\nEnter valid root password if you are sure you want to continue"
# Call this prog as root
exec su -c "${0} $RootParams"
else
echo -e "\nEnter valid sudo password if you are sure you want to continue"
sudo -k
# Call this prog as root
exec sudo ${0} $RootParams
fi
# sice we're 'execing' above, we wont reach this exit unless something
# goes wrong.
ErrorOut "RunUserStartRoot() should not have reached here!"
fi
}
StartCardWrite() {
# If not set on call - get defaults from machine.inc
if [ -z "$Machine" ]; then
Machine="$DEFAULT_MACHINE_FAMILY"
fi
if [ -z "$FindString" ]; then
FindString="$DEFAULT_FIND_ROOTFS"
fi
RunUserStartRoot
PrepareWrite
RootCardWriteCallback
}
StartCardKernelWrite() {
# If not set on call - get defaults from machine.inc
if [ -z "$Machine" ]; then
Machine="$DEFAULT_MACHINE_FAMILY"
fi
if [ -z "$FindString" ]; then
FindString="$DEFAULT_FIND_KERNEL"
fi
if [ -z "$KernelImageType" ]; then
KernelImageType="$DEFAULT_KERNEL_IMAGE_TYPE"
fi
RunUserStartRoot "${style_bold}The kernel images on %DevicePath% will be overwritten!${style_normal}"
PrepareWrite
RootCardKernelWriteCallback
}
# check common prerequisites
CheckPrerequisite "dialog"
CheckPrerequisite "lsblk"
# For user call the first two params can be set optionally - the first
# target/source dialogs won't be displayed then
DevicePath=$1
DeployedFile=$2
# For root call all params are mandatory
if [ $( id -u ) -eq 0 ]; then
DeployFileDir=$3
Machine=$4
FindString=$5
KernelImageType=$6
fi

View File

@@ -0,0 +1,54 @@
#! /bin/bash
# common-helpers.inc
# (c) Copyright 2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script contains some helper functions and can be sourced by other
# scripts
# set terminal styles
# are we on terrminal?
if [ -t 1 ] ; then
# tput available?
if [ ! "x`which tput 2>/dev/null`" = "x" ] ; then
# supports colors ?
ncolors=`tput colors`
if [ -n "$ncolors" -a $ncolors -ge 8 ] ; then
style_bold="`tput bold`"
style_underline="`tput smul`"
style_standout="`tput smso`"
style_normal="`tput sgr0`"
style_black="`tput setaf 0`"
style_red="`tput setaf 1`"
style_green="`tput setaf 2`"
style_yellow="`tput setaf 3`"
style_blue="`tput setaf 4`"
style_magenta="`tput setaf 5`"
style_cyan="`tput setaf 6`"
style_white="`tput setaf 7`"
fi
fi
fi
# base tempdir
base_tempdir=`mktemp -u`
base_tempdir=`dirname "$base_tempdir"`
# ErrorOut outputs error text in first param and exits script
ErrorOut() {
clear
echo "${style_red}${style_bold}${1}${style_normal}"
echo
exit -1
}
# CheckPrerequisite checks if required hosttool is found on host. In case not
# it outputs a message and exits script.
CheckPrerequisite() {
if [ "x`which $1 2>/dev/null`" = "x" ] ; then
ErrorOut "You need to install $1 first!"
fi
}

View File

@@ -0,0 +1,95 @@
#! /bin/bash
# machine-imx.inc
# (c) Copyright 2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script contains settings and callbacks for NXP imx boards
# default settings
DEFAULT_MACHINE_FAMILY='*imx*'
DEFAULT_FIND_ROOTFS='-name *.sdcard -o -name *.wic.gz -type l'
DEFAULT_KERNEL_IMAGE_TYPE='uImage'
DEFAULT_FIND_KERNEL="-name ${DEFAULT_KERNEL_IMAGE_TYPE}-abiversion-* -type l"
# callback for card-write
RootCardWriteCallback() {
# rootfs write/resize to card fit
time(
# write
echo "Write $DeployedFile to $DevicePath..."
if echo $DeployedFile | grep -q '.wic.gz'; then
gunzip -c $DeployedFile | dd of=$DevicePath bs=1024K
else
dd of=$DevicePath if=$DeployedFile bs=1024K
fi
sync
echo "${style_green}Write done.${style_normal}"
# resize
echo "Resize ${DevicePath}2..."
parted -s $DevicePath -- resizepart 2 -0
resize2fs "${DevicePath}2"
echo "${style_green}Resize done.${style_normal}"
)
}
# callback for card-kernel-write
RootCardKernelWriteCallback() {
tmpdir=`mktemp -d`
# initial kernel
mount ${DevicePath}1 $tmpdir || exit 1
echo "Write initial kernel and devicetrees to boot partition..."
rm -f $tmpdir/${KernelImageType}*
cp -f $DeployedFile $tmpdir/$KernelImageType
# devicetrees
rm -f $tmpdir/*.dtb
for dtb in `find ${DeployFileDir} -name "${KernelImageType}*.dtb" -type l`; do
dtbname=`basename $dtb | sed 's:'${KernelImageType}'-::'`
cp -f $dtb $tmpdir/${dtbname}
done
echo "${style_green}Write done.${style_normal}"
echo "Unmount boot partition..."
sleep 1
umount ${DevicePath}1 || exit 1
echo "${style_green}Unmount done.${style_normal}"
# rootfs/boot
mount ${DevicePath}2 $tmpdir || exit 1
echo "Write kernel to rootfs..."
rm -f $tmpdir/boot/${KernelImageType}*
KernelWithAbiName=`basename $DeployedFile | sed -e 's:-abiversion-::'`
cp $DeployedFile $tmpdir/boot/$KernelWithAbiName
ln -sf $KernelWithAbiName $tmpdir/boot/$KernelImageType
echo "${style_green}Write done.${style_normal}"
# rootfs/lib/modules
echo "Write modules to rootfs..."
kernel_abi_ver=`echo $KernelWithAbiName | sed 's:'${KernelImageType}'::g'`
for modules in `find ${DeployFileDir} -name "modules-${Machine}.tgz"`; do
tar xvzf ${modules} -C $tmpdir/
done
echo "${style_green}Write done.${style_normal}"
# run depmod (stolen from dempodwrapper)
sys_map=`realpath ${DeployFileDir}/../../../pkgdata/${Machine}/kernel-depmod/System.map-$kernel_abi_ver`
echo "Run depmod on modules..."
depmod -a -b $tmpdir -F "$sys_map" "$kernel_abi_ver"
echo "${style_green}Run done.${style_normal}"
# cleanup
echo "Unmount rootfs partition..."
umount ${DevicePath}2 || exit 1
echo "${style_green}Unmount done.${style_normal}"
rm -rf $tmpdir
}
CheckPrerequisite "time"
CheckPrerequisite "gunzip"
CheckPrerequisite "dd"
CheckPrerequisite "parted"
CheckPrerequisite "resize2fs"
CheckPrerequisite "depmod"

View File

@@ -0,0 +1,103 @@
#! /bin/bash
# machine-raspberrypi.inc
# (c) Copyright 2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script contains settings and callbacks fir raspberrypi boards
# default settings
DEFAULT_MACHINE_FAMILY='raspberrypi*'
DEFAULT_FIND_ROOTFS='-name *.rpi-sdimg -type l'
DEFAULT_KERNEL_IMAGE_TYPE='Image'
DEFAULT_FIND_KERNEL="-name ${DEFAULT_KERNEL_IMAGE_TYPE}-abiversion-* -type l"
# callback for card-write
RootCardWriteCallback() {
# rootfs write/resize to card fit
time(
# write
echo "Write $DeployedFile to $DevicePath..."
dd of=$DevicePath if=$DeployedFile bs=1024K
sync
echo "${style_green}Write done.${style_normal}"
echo "Resize ${DevicePath}2..."
parted -s $DevicePath -- resizepart 2 -0
resize2fs "${DevicePath}2"
echo "${style_green}Resize done.${style_normal}"
)
}
# callback for card-kernel-write
RootCardKernelWriteCallback() {
tmpdir=`mktemp -d`
# initial kernel / devicetrees
mount ${DevicePath}1 $tmpdir || exit 1
echo "Write initial kernel and devicetrees to boot partition..."
# kernel (REVISIT for aarch64)
cp -f $DeployedFile $tmpdir/kernel7.img
# devicetrees
rm -f $tmpdir/*.dtb
for dtb in `find ${DeployFileDir} -name "bcm27*.dtb"`; do
cp -f $dtb $tmpdir/
done
echo "${style_green}Write done.${style_normal}"
# devicetree overlays
echo "Write devicetree-overlays to boot partition..."
rm -f $tmpdir/overlays/*.dtbo
for dtbo in `find ${DeployFileDir} -name "*.dtbo"`; do
bname=`basename $dtbo`
if ! echo "${bname}" | grep -q 'Image-'; then
cp -f ${dtbo} $tmpdir/overlays/
fi
done
echo "${style_green}Write done.${style_normal}"
# TODO bootfiles?
echo "Unmount boot partition..."
sleep 1
umount ${DevicePath}1 || exit 1
echo "${style_green}Unmount done.${style_normal}"
# rootfs/boot
mount ${DevicePath}2 $tmpdir || exit 1
echo "Write kernel to rootfs..."
rm -f $tmpdir/boot/${KernelImageType}*
KernelFileName=`basename $DeployedFile`
cp $DeployedFile $tmpdir/boot/
ln -sf $KernelFileName $tmpdir/boot/$KernelImageType
echo "${style_green}Write done.${style_normal}"
# rootfs/lib/modules
echo "Write modules to rootfs..."
kernel_abi_ver=`echo $KernelFileName | sed 's:'${KernelImageType}'-::g'`
rm -rf $tmpdir/lib/modules/$kernel_abi_ver
for modules in `find ${DeployFileDir} -name "modules-${Machine}.tgz"`; do
tar xvzf ${modules} -C $tmpdir/
done
echo "${style_green}Write done.${style_normal}"
# run depmod (stolen from dempodwrapper)
sys_map=`realpath ${DeployFileDir}/../../../pkgdata/${Machine}/kernel-depmod/System.map-$kernel_abi_ver`
echo "Run depmod on modules..."
depmod -a -b $tmpdir -F "$sys_map" "$kernel_abi_ver"
echo "${style_green}Run done.${style_normal}"
# cleanup
echo "Unmount rootfs partition..."
umount ${DevicePath}2 || exit 1
echo "${style_green}Unmount done.${style_normal}"
rm -rf $tmpdir
}
CheckPrerequisite "time"
CheckPrerequisite "gunzip"
CheckPrerequisite "dd"
CheckPrerequisite "parted"
CheckPrerequisite "resize2fs"
CheckPrerequisite "depmod"

View File

@@ -0,0 +1,118 @@
#! /bin/bash
# machine-ti-old-omap.inc
# (c) Copyright 2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script contains settings and callbacks fir raspberrypi boards
# default settings
DEFAULT_MACHINE_FAMILY=''
DEFAULT_FIND_ROOTFS='-name *.rootfs.tar.bz2 -type l'
DEFAULT_KERNEL_IMAGE_TYPE='Image'
DEFAULT_FIND_KERNEL="-name ${DEFAULT_KERNEL_IMAGE_TYPE}-abiversion-* -type l"
# callback for card-write
RootCardWriteCallback() {
tmpdir=`mktemp -d`
# bootloaders and environment
echo "Writing bootloaders and environment to boot partition"
mount ${DevicePath}1 $tmpdir || exit 1
rm -rf $tmpdir/*
if [ -e ${DeployFileDir}/MLO ] ; then
cp ${DeployFileDir}/MLO $tmpdir/MLO
fi
cp ${DeployFileDir}/u-boot.img $tmpdir/u-boot.img
if [ -e ${DeployFileDir}/uEnv.txt ] ; then
cp ${DeployFileDir}/uEnv.txt $tmpdir
fi
sleep 1
umount ${DevicePath}1 || exit 1
# rootfs
time(
mount ${DevicePath}2 $tmpdir || exit 1
rm -rf $tmpdir/*
cd $tmpdir
tar xvjf $DeployedFile
cd ..
umount ${DevicePath}2 || exit 1
)
rm -rf $tmpdir
}
# callback for card-kernel-write
RootCardKernelWriteCallback() {
# TODO
tmpdir=`mktemp -d`
# initial kernel / devicetrees
mount ${DevicePath}1 $tmpdir || exit 1
echo "Write initial kernel and devicetrees to boot partition..."
# kernel (REVISIT for aarch64)
cp -f $DeployedFile $tmpdir/kernel7.img
# devicetrees
rm -f $tmpdir/*.dtb
for dtb in `find ${DeployFileDir} -name "bcm27*.dtb"`; do
cp -f $dtb $tmpdir/
done
echo "${style_green}Write done.${style_normal}"
# devicetree overlays
echo "Write devicetree-overlays to boot partition..."
rm -f $tmpdir/overlays/*.dtbo
for dtbo in `find ${DeployFileDir} -name "*.dtbo"`; do
bname=`basename $dtbo`
if ! echo "${bname}" | grep -q 'Image-'; then
cp -f ${dtbo} $tmpdir/overlays/
fi
done
echo "${style_green}Write done.${style_normal}"
# TODO bootfiles?
echo "Unmount boot partition..."
sleep 1
umount ${DevicePath}1 || exit 1
echo "${style_green}Unmount done.${style_normal}"
# rootfs/boot
mount ${DevicePath}2 $tmpdir || exit 1
echo "Write kernel to rootfs..."
rm -f $tmpdir/boot/${KernelImageType}*
KernelFileName=`basename $DeployedFile`
cp $DeployedFile $tmpdir/boot/
ln -sf $KernelFileName $tmpdir/boot/$KernelImageType
echo "${style_green}Write done.${style_normal}"
# rootfs/lib/modules
echo "Write modules to rootfs..."
kernel_abi_ver=`echo $KernelFileName | sed 's:'${KernelImageType}'-::g'`
rm -rf $tmpdir/lib/modules/$kernel_abi_ver
for modules in `find ${DeployFileDir} -name "modules-${Machine}.tgz"`; do
tar xvzf ${modules} -C $tmpdir/
done
echo "${style_green}Write done.${style_normal}"
# run depmod (stolen from dempodwrapper)
sys_map=`realpath ${OeTmpDir}/pkgdata/${Machine}/kernel-depmod/System.map-$kernel_abi_ver`
echo "Run depmod on modules..."
depmod -a -b $tmpdir -F "$sys_map" "$kernel_abi_ver"
echo "${style_green}Run done.${style_normal}"
# cleanup
echo "Unmount rootfs partition..."
umount ${DevicePath}2 || exit 1
echo "${style_green}Unmount done.${style_normal}"
rm -rf $tmpdir
}
CheckPrerequisite "time"
CheckPrerequisite "gunzip"
CheckPrerequisite "dd"
CheckPrerequisite "parted"
CheckPrerequisite "resize2fs"
CheckPrerequisite "depmod"

View File

@@ -0,0 +1,15 @@
#! /bin/bash
# raspberrypi-card-kernel-write.sh
# (c) Copyright 2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script writes kernel+modules to SDCard. To
# select card device a dialog based GUI is used.
# Includes
. `dirname $0`/include/common-helpers.inc
. `dirname $0`/include/card-helpers.inc
. `dirname $0`/include/machine-raspberrypi.inc
StartCardKernelWrite

View File

@@ -0,0 +1,14 @@
#! /bin/bash
# raspberrypi-card-write.sh
# (c) Copyright 2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script writes image to sdcard and aligns rootfs partition to max size.
# Includes
. `dirname $0`/include/common-helpers.inc
. `dirname $0`/include/card-helpers.inc
. `dirname $0`/include/machine-raspberrypi.inc
StartCardWrite

View File

@@ -1,153 +0,0 @@
#! /bin/bash
# card-kernel-write.sh
# (c) Copyright 2013-2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script writes kernel+modules to SDCard. To
# select card device a dialog based GUI is used.
SelectKernel() {
# OE environment found?
if [ -z $BUILDDIR ]; then
echo "The environment variable BUILDDIR is not set. It is usually set before running bitbake."
exit 1
fi
iCount=0
strSelection=
for grep_result in `grep -h TMPDIR $BUILDDIR/conf/*.conf | sed -e s/' '/''/g -e s/'\"'/''/g`; do
# exclude comments
tmp_dir=`echo $grep_result | grep '^TMPDIR='`
if [ ! -z $tmp_dir ]; then
TMPDIR=`echo $tmp_dir | sed -e s/'TMPDIR='/''/g`
fi
done
for BuildPath in ${TMPDIR}-*; do
# Find avaliable kernels
for i in `find ${BuildPath}/deploy/images/${MACHINE} -name ${KERNEL_IMAGE_TYPE}-abiversion-* | sort` ; do
iCount=`expr $iCount + 1`
KernelNameArr[${iCount}]=$i
strSelection="$strSelection $iCount "`basename $i`
done
done
# were files found?
if [ $iCount -eq 0 ]; then
echo "No kernel images found in ${TMPDIR}-\*"
exit 1
fi
dialog --title 'Select kernel'\
--menu 'Move using [UP] [DOWN],[Enter] to select' 30 100 $iCount\
${strSelection}\
2>/tmp/menuitem.$$
# get OK/Cancel
sel=$?
# get selected menuitem
menuitem=`cat /tmp/menuitem.$$`
rm -f /tmp/menuitem.$$
# Cancel Button or <ESC>
if [ $sel -eq 1 -o $sel -eq 255 ] ; then
echo Cancel selected 1
return 1
fi
KernelImage=${KernelNameArr[$menuitem]}
}
run_user() {
if [ -z $DevicePath ]; then
# DevicePath for memory card
SelectCardDevice || exit 1
fi
if [ -z $KernelImage ]; then
# select rootfs
SelectKernel || exit 1
fi
RootParams="$DevicePath $KernelImage $KERNEL_IMAGE_TYPE"
}
run_root() {
# device node valid?
if [ ! -b $DevicePath ] ; then
echo "$DevicePath is not a valid block device!"
exit 1
fi
# rootfs valid?
if [ ! -e $KernelImage ] ; then
echo "$KernelImage can not be found!"
exit 1
fi
IMAGEDIR=$(dirname $KernelImage)
# check if the card is currently mounted
chk_umount $DevicePath
# create temp mount path
if [ ! -d /tmp/tmp_mount$$ ] ; then
mkdir /tmp/tmp_mount$$
fi
# initial kernel
mount ${DevicePath}1 /tmp/tmp_mount$$ || exit 1
echo "Writing initial kernel and devicetrees to boot partition"
rm -f /tmp/tmp_mount$$/${KernelImageType}*
cp -f $KernelImage /tmp/tmp_mount$$/$KernelImageType
# devicetrees
rm -f /tmp/tmp_mount$$/*.dtb
for dtb in `find ${IMAGEDIR} -name "${KernelImageType}*.dtb" -type l`; do
dtbname=`basename $dtb | sed 's:'${KernelImageType}'-::'`
cp -f $dtb /tmp/tmp_mount$$/${dtbname}
done
sleep 1
umount ${DevicePath}1 || exit 1
# rootfs/boot
mount ${DevicePath}2 /tmp/tmp_mount$$ || exit 1
echo "Writing kernel to rootfs"
rm -f /tmp/tmp_mount$$/boot/${KernelImageType}*
KernelWithAbiName=`basename $KernelImage | sed -e 's:-abiversion-::'`
cp $KernelImage /tmp/tmp_mount$$/boot/$KernelWithAbiName
ln -sf $KernelWithAbiName /tmp/tmp_mount$$/boot/$KernelImageType
# rootfs/lib/modules
echo "Writing modules to rootfs..."
kernel_abi_ver=`echo $KernelWithAbiName | sed 's:'${KernelImageType}'::g'`
for modules in `find ${IMAGEDIR} -name "modules-${MACHINE}.tgz"`; do
tar xvzf ${modules} -C /tmp/tmp_mount$$/
done
# run depmod (stolen from dempodwrapper
sys_map=`realpath ${IMAGEDIR}/../../../pkgdata/${MACHINE}/kernel-depmod/System.map-$kernel_abi_ver`
echo "Running depmod on modules"
depmod -a -b /tmp/tmp_mount$$ -F "$sys_map" "$kernel_abi_ver"
echo "Unmount / write cache..."
umount ${DevicePath}2 || exit 1
rm -rf /tmp/tmp_mount$$
}
. `dirname $0`/machine.inc
. `dirname $0`/../tools.inc
if [ -z $MACHINE ]; then
MACHINE=$DEFAULT_MACHINE
fi
if [ -z $KERNEL_IMAGE_TYPE ]; then
KERNEL_IMAGE_TYPE=$DEFAULT_KERNEL_IMAGE_TYPE
fi
DevicePath=$1
KernelImage=$2
KernelImageType=$3
# On the 1st call: run user
# After the 2nd call: run root
RootParams='$DevicePath $KernelImage $KERNEL_IMAGE_TYPE'
chk_root "The kernel images on %DevicePath% will be overwritten!!" && run_root

View File

@@ -1,77 +0,0 @@
#! /bin/bash
# write-card.sh
# (c) Copyright 2013-2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script writes image to sdcard and aligns rootfs partition to max size.
run_user() {
if [ -z $DevicePath ]; then
# DevicePath for memory card
SelectCardDevice || exit 1
fi
if [ -z $RootFsFile ]; then
# select rootfs
SelectRootfs '-name *.sdcard -o -name *.wic.gz -type l' || exit 1
fi
RootParams="$DevicePath $RootFsFile"
}
run_root() {
# device node valid?
if [ ! -b $DevicePath ] ; then
echo "$DevicePath is not a valid block device!"
exit 1
fi
# rootfs valid?
if [ ! -e $RootFsFile ] ; then
echo "$RootFsFile can not be found!"
exit 1
fi
IMAGEDIR=$(dirname $RootFsFile)
# check if the card is currently mounted
chk_umount $DevicePath
# rootfs write/resize to card fit
time(
echo "Writing $RootFsFile to $DevicePath..."
if echo $RootFsFile | grep -q '.wic.gz'; then
gunzip -c $RootFsFile | dd of=$DevicePath bs=1024K
else
dd of=$DevicePath if=$RootFsFile bs=1024K
fi
sync
echo "Resizing ${DevicePath}2..."
parted -s $DevicePath -- resizepart 2 -0
resize2fs "${DevicePath}2"
)
}
# includes
. `dirname $0`/machine.inc
. `dirname $0`/../tools.inc
CheckPrerequisite "dd"
CheckPrerequisite "time"
CheckPrerequisite "parted"
CheckPrerequisite "resize2fs"
if [ -z $MACHINE ]; then
MACHINE=$DEFAULT_MACHINE
fi
DevicePath=$1
RootFsFile=$2
# On the 1st call: run user
# After the 2nd call: run root
RootParams='$DevicePath $RootFsFile'
chk_root&&run_root

View File

@@ -1,4 +0,0 @@
# default settings
DEFAULT_MACHINE='*imx*'
DEFAULT_KERNEL_IMAGE_TYPE=uImage
KERNEL_MAJOR_VERSION=4

View File

@@ -1,70 +0,0 @@
#! /bin/bash
# write-card.sh
# (c) Copyright 2013-2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script writes image to sdcard and aligns rootfs partition to max size.
run_user() {
if [ -z $DevicePath ]; then
# DevicePath for memory card
SelectCardDevice || exit 1
fi
if [ -z $RootFsFile ]; then
# select rootfs
SelectRootfs '-name *.rpi-sdimg -type l' || exit 1
fi
RootParams="$DevicePath $RootFsFile"
}
run_root() {
# device node valid?
if [ ! -b $DevicePath ] ; then
echo "$DevicePath is not a valid block device!"
exit 1
fi
# rootfs valid?
if [ ! -e $RootFsFile ] ; then
echo "$RootFsFile can not be found!"
exit 1
fi
IMAGEDIR=$(dirname $RootFsFile)
# check if the card is currently mounted
chk_umount $DevicePath
# rootfs write/resize to card fit
time(
echo "Writing $RootFsFile to $DevicePath..."
dd of=$DevicePath if=$RootFsFile bs=1024K
sync
echo "Resizing ${DevicePath}2..."
parted -s $DevicePath -- resizepart 2 -0
resize2fs "${DevicePath}2"
)
}
# includes
. `dirname $0`/machine.inc
. `dirname $0`/../tools.inc
CheckPrerequisite "dd"
CheckPrerequisite "time"
CheckPrerequisite "parted"
CheckPrerequisite "resize2fs"
if [ -z $MACHINE ]; then
MACHINE=$DEFAULT_MACHINE
fi
DevicePath=$1
RootFsFile=$2
# On the 1st call: run user
# After the 2nd call: run root
RootParams='$DevicePath $RootFsFile'
chk_root&&run_root

View File

@@ -1,6 +0,0 @@
# default settings
DEFAULT_MACHINE='raspberrypi*'
DEFAULT_KERNEL_IMAGE_TYPE=Image
# TODO card-kernel-write!!!
KERNEL_MAJOR_VERSION=4

View File

@@ -1,231 +0,0 @@
#! /bin/bash
# tools.inc
# (c) Copyright 2013-2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script contains some helper functions and can be sourced by other
# scripts
# set terminal styles
# are we on terrminal?
if [ -t 1 ] ; then
# tput available?
if [ ! "x`which tput 2>/dev/null`" = "x" ] ; then
# supports colors ?
ncolors=`tput colors`
if [ -n "$ncolors" -a $ncolors -ge 8 ] ; then
style_bold="`tput bold`"
style_underline="`tput smul`"
style_standout="`tput smso`"
style_normal="`tput sgr0`"
style_black="`tput setaf 0`"
style_red="`tput setaf 1`"
style_green="`tput setaf 2`"
style_yellow="`tput setaf 3`"
style_blue="`tput setaf 4`"
style_magenta="`tput setaf 5`"
style_cyan="`tput setaf 6`"
style_white="`tput setaf 7`"
fi
fi
fi
# ErrorOut outputs error text in first param and exits script
ErrorOut() {
echo
echo "${style_red}${style_bold}${1}!${style_normal}"
echo
exit -1
}
# CheckPrerequisite checks if required hosttool is found on host. In case not
# it outputs a message and exits script.
CheckPrerequisite() {
if [ "x`which $1 2>/dev/null`" = "x" ] ; then
ErrorOut "You need to install $1 first!"
fi
}
# SelectCardDevice() creates a dialog to select one of all available removable
# devices. The path to the selected device is stored in the variale DevicePath.
SelectCardDevice() {
iCount=0
for dev in /dev/sd[a-z] ; do
DeviceFile=`basename $dev`
# we are only interested in removable devices
if [ `cat /sys/block/$DeviceFile/removable` = '1' ] && [ `cat /sys/block/$DeviceFile/size` -gt "0" ]; then
iCount=`expr $iCount + 1`
DevicePathArr[${iCount}]=$dev
# pretify display
secondline=
display=
IFS=$'\n'
for line in `lsblk --raw --noheadings --output NAME,LABEL,MODEL $dev` ; do
# a bug in lsblk?
line=`echo $line | sed 's:\\\x20: :g'`
if [ "x$secondline" = "x" ]; then
# first line - it is for device
secondline="1"
display="$line"
else
if [ "x$secondline" = "x1" ]; then
secondline="2"
# second line - header + partition
display="$display / partitions: $line"
else
# second line - separator + partition
display="$display + $line"
fi
fi
done
display=`echo $display | sed 's: : :g'`
display=`echo $display | sed 's: : :g'`
display=`echo $display | sed 's: : :g'`
unset IFS
menuitems+=( "$iCount" "$display" )
fi
done
if [ $iCount -eq 0 ]; then
ErrorOut 'No removable devices found!'
fi
dialog --title 'Select card device'\
--menu 'Move using [UP] [DOWN],[Enter] to select' 10 100 $iCount\
"${menuitems[@]}"\
2>/tmp/menuitem.$$
# get OK/Cancel
sel=$?
# get selected menuitem
menuitem=`cat /tmp/menuitem.$$`
rm -f /tmp/menuitem.$$
# Cancel Button or <ESC>
if [ $sel -eq 1 -o $sel -eq 255 ] ; then
echo 'Cancel selected SelectCardDevice()'
return 1
fi
DevicePath=${DevicePathArr[$menuitem]}
}
# SelectRootfs() opens a dialog to select file containing rootfs. It expects
# one parameter which contains find parameters e.g for raspberrypi: '
SelectRootfs() {
# OE environment found?
if [ -z $BUILDDIR ]; then
ErrorOut "The environment variable BUILDDIR is not set. It is usually set before running bitbake."
fi
iCount=0
strSelection=
for grep_result in `grep -h TMPDIR $BUILDDIR/conf/*.conf | sed -e s/' '/''/g -e s/'\"'/''/g`; do
# exclude comments
tmp_dir=`echo $grep_result | grep '^TMPDIR='`
if [ ! -z $tmp_dir ]; then
TMPDIR=`echo $tmp_dir | sed -e s/'TMPDIR='/''/g`
fi
done
for BuildPath in ${TMPDIR}-*; do
for i in `find ${BuildPath}/deploy/images/${MACHINE} $1 | sort` ; do
iCount=`expr $iCount + 1`
RootFileNameArr[${iCount}]=$i
strSelection="$strSelection $iCount "`basename $i`
done
done
# were files found?
if [ $iCount -eq 0 ]; then
ErrorOut "No rootfs files found in ${TMPDIR}-\*"
fi
dialog --title 'Select rootfs'\
--menu 'Move using [UP] [DOWN],[Enter] to select' 30 100 $iCount\
${strSelection}\
2>/tmp/menuitem.$$
# get OK/Cancel
sel=$?
# get selected menuitem
menuitem=`cat /tmp/menuitem.$$`
rm -f /tmp/menuitem.$$
# Cancel Button or <ESC>
if [ $sel -eq 1 -o $sel -eq 255 ] ; then
echo Cancel selected 1
return 1
fi
RootFsFile=${RootFileNameArr[$menuitem]}
echo
}
# chk_root() tests if we are running as root. If not, it calls run_user and then
# asks operator how to log on as root. Then the main script is started as root
chk_root() {
# we are not already root?
if [ ! $( id -u ) -eq 0 ]; then
# do all non root operations
run_user
# abort in case run_user was performed without success
if [ $? -ne 0 ] ; then
return 1
fi
dialog --title 'Select how you want to logon as root'\
--menu 'Move using [UP] [DOWN],[Enter] to select' 10 100 2 1 su 2 sudo \
2>/tmp/menuitem.$$
# get OK/Cancel
sel=$?
# get selected menuitem
menuitem=`cat /tmp/menuitem.$$`
rm -f /tmp/menuitem.$$
# Cancel Button or <ESC>
if [ $sel -eq 1 -o $sel -eq 255 ] ; then
echo 'Cancel selected chk_root()'
return 1
fi
clear
if [ "x$1" = "x" ] ; then
echo "All data currenly stored on $DevicePath will be overwritten!!"
else
echo $1 | sed "s|\%DevicePath\%|$DevicePath|"
fi
if [ $menuitem -eq 1 ]; then
echo -e "\nEnter valid root password if you are sure you want to continue"
# Call this prog as root
exec su -c "${0} $RootParams"
else
echo -e "\nEnter valid sudo password if you are sure you want to continue"
sudo -k
# Call this prog as root
exec sudo ${0} $RootParams
fi
return 1 # sice we're 'execing' above, we wont reach this exit
# unless something goes wrong.
fi
}
# chk_umount() tests if a device partition is mounted. If so partition is
# unmounted. Devic name is expected in first parameter.
chk_umount() {
# check if the card is currently mounted
MOUNTSTR=$(mount | grep $1)
if [ -n "$MOUNTSTR" ] ; then
echo -en "\n$1 is mounted. Unmounting..."
umount -f ${1}?*
echo " ${style_green}done${style_normal}"
fi
}
# common prerequisites
CheckPrerequisite "dialog"
CheckPrerequisite "lsblk"

View File

@@ -0,0 +1,5 @@
ti-old-omap:
These scripts are used when using old image style (non WKS / dd) for TI
omap3/zitara machines. Intended for images build with meta-bbone and
meta-gumstix-community (would like to let them die but we still have active
products based on these very old layers).

View File

@@ -0,0 +1,47 @@
#! /bin/bash
# card-part.sh
# (c) Copyright 2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script prepares partitions on SDCards. It wraps
# http://omappedia.org/wiki/Minimal-FS_SD_Configuration by dialog based GUI.
# includes
. `dirname $0`/include/common-helpers.inc
. `dirname $0`/../tools.inc
# overrride default
SelectInOut() {
# DevicePath for target card
SelectCardDevice
RootParams="$DevicePath"
}
# implement here - not im machine-ti-old-omap.inc
RootCardWriteCallback() {
# kill u-boot environment
dd if=/dev/zero of=$DevicePath bs=1024 count=1024
# Create the FAT partition of 64MB and make it bootable
parted -s $DevicePath mklabel msdos
parted -s $DevicePath mkpart primary fat32 63s 64MB
parted -s $DevicePath toggle 1 boot
# Create the rootfs partition until end of device
parted -s $DevicePath -- mkpart primary ext4 64MB -0
# write partitions
mkfs.vfat -F 32 -n "boot" -I ${DevicePath}1
mke2fs -F -j -t ext4 -L "rootfs" ${DevicePath}2
}
CheckPrerequisite "parted"
CheckPrerequisite "dd"
CheckPrerequisite "mkfs.vfat"
CheckPrerequisite "mkfs.vfat"
StartCardWrite

View File

@@ -0,0 +1,14 @@
#! /bin/bash
# raspberrypi-card-write.sh
# (c) Copyright 2018 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script writes image to sdcard and aligns rootfs partition to max size.
# Includes
. `dirname $0`/include/common-helpers.inc
. `dirname $0`/include/card-helpers.inc
. `dirname $0`/include/machine-ti-old-omap.inc
StartCardWrite