blob: 4040337dd2d433533a7bbfc9c1518926275e58b8 [file] [log] [blame]
Stefan Tauner196c28b2014-08-03 13:13:06 +02001#!/bin/sh
2# This program is free software; you can redistribute it and/or modify
3# it under the terms of the GNU General Public License as published by
4# the Free Software Foundation; either version 2 of the License, or
5# (at your option) any later version.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program; if not, write to the Free Software
14# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15# MA 02110-1301, USA.
16#
17# Takes a path to a file as first and only argument, removes the first 2048 B
18# from that file and stores the result with the same name plus a '.bin' suffix.
19# Useable to remove the header from UEFI Capsule files to use the resulting
20# binary with flashrom.
21
22main () {
23 if [ "$#" -lt 1 -o ! -r "$1" ]; then
24 echo "Removes the 2048 B header of UEFI Capsule files.\n"\
25 "Usage: $0 <FILE.CAP>"
26 return 1
27 fi
28
29 capsize=$(wc -c "$1" | cut -f 1 -d ' ')
30 binsize=$(($capsize-2048))
31 ispowoftwo=$(($binsize & ($binsize-1)))
32 if [ $ispowoftwo -ne 0 -o $binsize -eq 0 ]; then
33 echo "The size of the resulting file would not be a power of 2 (but $binsize B)."
34 return 1
35 fi
36
37 dd bs=2048 skip=1 if="$1" of="$1.bin"
38}
39
40main $*