1.1 --- a/makesd-partition-summary Tue May 28 00:30:18 2019 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,187 +0,0 @@
1.4 -#!/bin/sh
1.5 -
1.6 -# Emit a partition summary for a device employing parameters such as the start,
1.7 -# size, and type.
1.8 -#
1.9 -# Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
1.10 -#
1.11 -# This program is free software; you can redistribute it and/or modify it under
1.12 -# the terms of the GNU General Public License as published by the Free Software
1.13 -# Foundation; either version 3 of the License, or (at your option) any later
1.14 -# version.
1.15 -#
1.16 -# This program is distributed in the hope that it will be useful, but WITHOUT
1.17 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 -# details.
1.20 -#
1.21 -# You should have received a copy of the GNU General Public License along with
1.22 -# this program. If not, see <http://www.gnu.org/licenses/>.
1.23 -
1.24 -PROGNAME=`basename "$0"`
1.25 -THISDIR=`dirname "$0"`
1.26 -
1.27 -
1.28 -
1.29 -# Emit any partition details as a complete record.
1.30 -
1.31 -emit_partition()
1.32 -{
1.33 - echo "${START:--}\t${SIZE:--}\t${TYPE:--}\t${BOOTLOADER:--}\t" \
1.34 - "${CONFIG:--}\t${DEVICETREE:--}\t${KERNEL:--}\t${MODULES:--}\t" \
1.35 - "${ROOTFS:--}"
1.36 -}
1.37 -
1.38 -# Reset the current partition details.
1.39 -
1.40 -reset_partition()
1.41 -{
1.42 - START=
1.43 - SIZE=
1.44 - TYPE=
1.45 -
1.46 - BOOTLOADER=
1.47 - CONFIG=
1.48 - DEVICETREE=
1.49 - KERNEL=
1.50 - MODULES=
1.51 - ROOTFS=
1.52 -}
1.53 -
1.54 -# Emit the current partition details and proceed to the next partition.
1.55 -
1.56 -next_partition()
1.57 -{
1.58 - if [ "$START" ] || [ "$SIZE" ] || [ "$TYPE" ] ; then
1.59 - emit_partition
1.60 - reset_partition
1.61 - fi
1.62 -}
1.63 -
1.64 -# test_partition <value>
1.65 -#
1.66 -# Test for the presence of the given value, starting a new partition if already
1.67 -# defined.
1.68 -
1.69 -test_partition()
1.70 -{
1.71 - if [ "$1" ] ; then
1.72 - next_partition
1.73 - fi
1.74 -}
1.75 -
1.76 -# replace_in_partition <name> <value>
1.77 -#
1.78 -# Set in the partition the parameter of the given name to value.
1.79 -
1.80 -replace_in_partition()
1.81 -{
1.82 - eval "$1=\"\$2\""
1.83 -}
1.84 -
1.85 -# set_in_partition <name> <value>
1.86 -#
1.87 -# Set the partition parameter of the given name to value, starting a new
1.88 -# partition if necessary.
1.89 -
1.90 -set_in_partition()
1.91 -{
1.92 - eval "test_partition \$$1"
1.93 - replace_in_partition "$1" "$2"
1.94 -}
1.95 -
1.96 -
1.97 -
1.98 -# Emit the help message if requested.
1.99 -
1.100 -if [ "$1" = '--help' ] ; then
1.101 - cat 1>&2 <<EOF
1.102 -Usage: $PROGNAME <option>...
1.103 -
1.104 -Produce partition descriptions, indicating partition type, start position and
1.105 -size for each partition. Each new occurrence of an active partitioning option
1.106 -starts a new partition description.
1.107 -
1.108 -Partitioning options are as follows:
1.109 -
1.110 --f <type> - partition type (ext2, ext3, ext4, fat, swap...)
1.111 --p <start position> - start position/sector
1.112 --s <size> - partition size as a percentage of device capacity
1.113 -
1.114 -Alongside partitioning options, the following population options can be given:
1.115 -
1.116 --b <bootloader> - bootloader payload
1.117 --c <config> - configuration archive
1.118 --d <device tree> - device tree binary archive
1.119 --k <kernel> - kernel payload
1.120 --m <modules> - kernel modules archive
1.121 --r <root filesystem> - root filesystem archive
1.122 -
1.123 -Each line of the produced description is tab-separated with '-' indicating an
1.124 -empty field.
1.125 -EOF
1.126 - exit 0
1.127 -fi
1.128 -
1.129 -# Process the arguments, building a partition description.
1.130 -
1.131 -reset_partition
1.132 -
1.133 -while [ "$1" ] ; do
1.134 - case "$1" in
1.135 -
1.136 - # Partition type, position, size.
1.137 -
1.138 - -f )
1.139 - set_in_partition "TYPE" "$2"
1.140 - shift 2
1.141 - ;;
1.142 - -p )
1.143 - set_in_partition "START" "$2"
1.144 - shift 2
1.145 - ;;
1.146 - -s )
1.147 - set_in_partition "SIZE" "$2"
1.148 - shift 2
1.149 - ;;
1.150 -
1.151 - # Bootloader, configuration, device tree, kernel, modules, root
1.152 - # filesystem.
1.153 -
1.154 - -b )
1.155 - replace_in_partition "BOOTLOADER" "$2"
1.156 - shift 2
1.157 - ;;
1.158 - -c )
1.159 - replace_in_partition "CONFIG" "$2"
1.160 - shift 2
1.161 - ;;
1.162 - -dd )
1.163 - # NOTE: To be supported.
1.164 - shift 1
1.165 - ;;
1.166 - -d )
1.167 - replace_in_partition "DEVICETREE" "$2"
1.168 - shift 2
1.169 - ;;
1.170 - -k )
1.171 - replace_in_partition "KERNEL" "$2"
1.172 - shift 2
1.173 - ;;
1.174 - -m )
1.175 - replace_in_partition "MODULES" "$2"
1.176 - shift 2
1.177 - ;;
1.178 - -r )
1.179 - replace_in_partition "ROOTFS" "$2"
1.180 - shift 2
1.181 - ;;
1.182 - * )
1.183 - shift 1
1.184 - ;;
1.185 - esac
1.186 -done
1.187 -
1.188 -# Terminate any unfinished partition.
1.189 -
1.190 -next_partition