1#!/bin/sh 2 3# 4# Manually create a .fw file that has a hole at the end. 5# 6 7. "$(cd "$(dirname "$0")" && pwd)/common.sh" 8 9# Create the "sparse" resource. 10SPARSE_FILE=$WORK/sparse.bin 11cp $TESTFILE_1K $SPARSE_FILE 12dd seek=2 count=1 if=/dev/zero of=$SPARSE_FILE 2>/dev/null 13 14cat >$CONFIG <<EOF 15file-resource sparsefile { 16 host-path = "${TESTFILE_1K}" 17} 18task raw { 19 on-resource sparsefile { raw_write(0) } 20} 21task fat { 22 on-resource sparsefile { 23 fat_mkfs(0, 32760) 24 fat_write(4, "sparse.bin") 25 } 26} 27EOF 28 29NEW_META_CONF=$WORK/new-meta.conf 30cat >$NEW_META_CONF <<EOF 31file-resource "sparsefile" { 32length={1024,512} 33blake2b-256="b25c2dfe31707f5572d9a3670d0dcfe5d59ccb010e6aba3b81aad133eb5e378b" 34} 35task "raw" { 36on-resource "sparsefile" { 37funlist={"2","raw_write","4"} 38} 39} 40task "fat" { 41on-resource "sparsefile" { 42funlist={"3","fat_mkfs","0","32760","3","fat_write","0","sparse.bin"} 43} 44} 45EOF 46 47# Create the firmware file 48$FWUP_CREATE -c -f $CONFIG -o $FWFILE 49 50# Verify the file 51$FWUP_VERIFY -V -i $FWFILE 52 53# Create the new "sparse" fw file 54NEW_FWFILE=$WORK/new.fw 55unzip -q $FWFILE -d $UNZIPDIR 56cp $NEW_META_CONF $UNZIPDIR/meta.conf 57cd $UNZIPDIR 58zip -q $NEW_FWFILE meta.conf data/sparsefile 59cd - 60 61# It should still verify 62$FWUP_VERIFY -V -i $NEW_FWFILE 63 64# Check that raw_write works with the sparse file 65$FWUP_APPLY -a -d $IMGFILE -i $NEW_FWFILE -t raw 66cmp_bytes 1536 $SPARSE_FILE $IMGFILE 0 2048 67 68# Check that fat_write works with the sparse file 69rm $IMGFILE 70$FWUP_APPLY -a -d $IMGFILE -i $NEW_FWFILE -t fat 71 72EXPECTED_FAT_OUTPUT=$WORK/expected.out 73ACTUAL_FAT_OUTPUT=$WORK/actual.out 74 75cat >$EXPECTED_FAT_OUTPUT << EOF 76 Volume in drive : has no label 77 Volume Serial Number is 0021-7FF8 78Directory for ::/ 79 80sparse bin 1536 1980-01-01 0:00 81 1 file 1 536 bytes 82 16 623 616 bytes free 83 84EOF 85 86# Check that the directory looks right 87mdir -i $WORK/fwup.img > $ACTUAL_FAT_OUTPUT 88diff -w $EXPECTED_FAT_OUTPUT $ACTUAL_FAT_OUTPUT 89 90# Check the contents of the file 91mcopy -n -i $WORK/fwup.img ::/sparse.bin $WORK/actual.sparse.bin 92cmp $SPARSE_FILE $WORK/actual.sparse.bin 93 94