#!/bin/bash -e # # Copyright © 2008 Andres Salomon # # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. check_for_cmds() { for cmd in $@; do which $cmd >/dev/null || { echo "Missing required command '$cmd'!" 1>&2 return 1 } done return 0 } check_for_cmds dd sha256sum usage() { echo "" 1>&2 echo "Usage: $0 " 1>&2 echo "Produces .plc" echo "For use in secure reflash, the resulting placement control file" echo "(*.plc) must be included as data.img in an OLPC-signed fs.zip." echo "" 1>&2 exit 1 } if [ "$#" != "1" ]; then usage fi IMAGE_FILE_NAME=$1 IMAGE_FILE_BASENAME=`basename $IMAGE_FILE_NAME` PLACEMENT_CONTROL_FILE=${IMAGE_FILE_BASENAME/.img/.plc} do_sha256() { f=$1 eblocks=$((`stat --printf "%s\n" $f` / (128*1024))) for b in $(seq 0 $(($eblocks - 1))); do sha=$(dd status=noxfer bs=128KiB skip=$b count=1 if=$f 2>/dev/null | sha256sum | cut -d\ -f1) echo "eblock: `printf '%x' $b` sha256 $sha" >> ${PLACEMENT_CONTROL_FILE} done } cat >${PLACEMENT_CONTROL_FILE}<>${PLACEMENT_CONTROL_FILE}<