Remove the last set of the *.slice files and replace them with a script that can generically extract all currently known firmware images from their FL2 files

pull/36/head
Hamish Coleman 7 years ago
parent 5f34b3220b
commit ae52989189

@ -161,24 +161,6 @@ define patch_disable
$(call patch_mv,$1,$1.OFF)
endef
-include $(DEPSDIR)/slice.extract.deps
CLEAN_FILES += $(DEPSDIR)/slice.extract.deps
$(DEPSDIR)/slice.extract.deps: Makefile
for i in *.slice; do read SLICEE other <$$i; echo $$i: $$SLICEE; done >$@.tmp
mv $@.tmp $@
-include $(DEPSDIR)/slice.insert.deps
CLEAN_FILES += $(DEPSDIR)/slice.insert.deps
$(DEPSDIR)/slice.insert.deps: Makefile
for i in *.slice; do read SLICEE other <$$i; echo `basename $$SLICEE .orig`: $$i `basename $$i .slice`; done >$@.tmp
mv $@.tmp $@
# FIXME - the slice.deps targets basically do not handle add/del/change of
# the *.slice files. I dont use any of the regular tricks because I also
# dont want to download every .iso file as a result of depending on the %.slice
# file - and I dont want to work around that with makefile magic as that would
# defeat the purpose of keeping the makefile simple
# TODO - the scripts/describe output depends on Descriptions.txt -
# could parse that file and create some deps
@ -207,10 +189,6 @@ $(DEPSDIR)/slice.insert.deps: Makefile
# Generate all the orig images so that we can diff against them later
# A generic binary extractor
%.orig: %.slice scripts/slice.extract
./scripts/slice.extract $< $@
# TODO - checking the checksum here is probably too strict - it adds
# more barriers to downloading some random bios ISO and starting to port
# the code to it.
@ -328,7 +306,7 @@ mec-tools/mec_encrypt: mec-tools/Makefile
# $1 = encoded EC firmware
# $2 = FL2 filename
define rule_fl2_patch
$(2): $(1) ; ./scripts/slice.insert $(1).slice $(1) $(2)
$(2): $(1) ; cp --reflink=auto $(2).orig $(2) && ./scripts/FL2_copyIMG to_fl2 $(2) $(1)
endef
# Create a new ISO image with patches applied
@ -342,8 +320,8 @@ endef
# accidentally be used for BIOS updates
# Extract the FL2 file from an ISO image
# Note that the parameters here are essentially the same as rule_iso, but you cannot
# define two targets with one define..
# Note that the parameters here are intentionally the same as rule_iso,
# but you cannot define two targets with one define..
# $1 = FL2 linux filename basename
# $2 = pattern to match FL2 file in ISO image
# $3 = ISO image basename
@ -357,9 +335,20 @@ define rule_fl2_extract
$(1).orig: $(3).orig ; ./scripts/copyFL2 from_iso $(3).orig $(1).orig $(2)
endef
# Extract the IMG file from an FL2 file
# Note that the parameters here are intentionallty the same as rule_fl2_patch,
# but you cannot define two targets with one define..
# $1 = IMG file basename
# $2 = FL2 file basename
define rule_img_extract
$(1).orig: $(2).orig ./scripts/FL2_copyIMG ; ./scripts/FL2_copyIMG from_fl2 $(2).orig $(1).orig
endef
#
# TODO:
# - add a simple method to autogenerate these non-generic rules
# - this is getting closer with the replacement of the .slice files with
# generic scripts.
# - once that is done, convert the defines back to action bodies, not
# rule definitions
@ -372,6 +361,15 @@ $(call rule_fl2_patch,w530.G4HT39WW.img.enc,w530.G4HT39WW.s01D5200.FL2)
$(call rule_fl2_patch,x230.G2HT35WW.img.enc,x230.G2HT35WW.s01D3000.FL2)
$(call rule_fl2_patch,x230t.GCHT25WW.img.enc,x230t.GCHT25WW.s01DA000.FL2)
$(call rule_img_extract,x220.8DHT34WW.img.enc,x220.8DHT34WW.s01CB000.FL2)
$(call rule_img_extract,t430.G1HT34WW.img.enc,t430.G1HT34WW.s01D2000.FL2)
$(call rule_img_extract,t430.G1HT35WW.img.enc,t430.G1HT35WW.s01D2000.FL2)
$(call rule_img_extract,t430s.G7HT39WW.img.enc,t430s.G7HT39WW.s01D8000.FL2)
$(call rule_img_extract,t530.G4HT39WW.img.enc,t530.G4HT39WW.s01D5100.FL2)
$(call rule_img_extract,w530.G4HT39WW.img.enc,w530.G4HT39WW.s01D5200.FL2)
$(call rule_img_extract,x230.G2HT35WW.img.enc,x230.G2HT35WW.s01D3000.FL2)
$(call rule_img_extract,x230t.GCHT25WW.img.enc,x230t.GCHT25WW.s01DA000.FL2)
$(call rule_iso,t430.G1HT34WW.s01D2000.FL2,01D2000.FL2,g1uj25us.iso)
$(call rule_iso,t430.G1HT35WW.s01D2000.FL2,01D2000.FL2,g1uj40us.iso)
$(call rule_iso,x230.G2HT35WW.s01D3000.FL2,01D3000.FL2,g2uj25us.iso)
@ -380,6 +378,7 @@ $(call rule_iso,w530.G4HT39WW.s01D5200.FL2,01D5200.FL2,g5uj28us.iso)
$(call rule_iso,t430s.G7HT39WW.s01D8000.FL2,01D8000.FL2,g7uj19us.iso)
$(call rule_iso,x230t.GCHT25WW.s01DA000.FL2,01DA000.FL2,gcuj24us.iso)
$(call rule_fl2_extract,x220.8DHT34WW.s01CB000.FL2,01CB000.FL2,8duj27us.iso)
$(call rule_fl2_extract,t430.G1HT35WW.s01D2000.FL2,01D2000.FL2,g1uj40us.iso)
$(call rule_fl2_extract,t430.G1HT34WW.s01D2000.FL2,01D2000.FL2,g1uj25us.iso)
$(call rule_fl2_extract,x230.G2HT35WW.s01D3000.FL2,01D3000.FL2,g2uj25us.iso)

@ -113,6 +113,38 @@ sub _extract {
return $self;
}
# Helper function, called by the real classes if they support insertion
sub _insert {
my $self = shift;
my $imgfile = shift;
my $fh = IO::File->new($imgfile, "r");
if (!defined($fh)) {
warn("Could not open $imgfile: $!");
return undef;
}
my $buf;
my $count = $fh->sysread($buf, $self->size());
if ($count != $self->size()) {
unlink($imgfile);
die("bad read");
}
if (!$self->{fh}->seek($self->offset(), 0)) {
unlink($imgfile);
die("bad seek");
}
$count = $self->{fh}->syswrite($buf);
if ($count != $self->size()) {
unlink($imgfile);
die("bad write");
}
return $self;
}
1;
package FL2::prefix_ff;
@ -154,6 +186,10 @@ sub extract {
return shift->_extract(shift);
}
sub insert {
return shift->_insert(shift);
}
1;
package FL2::prefix_garbage;
@ -194,6 +230,10 @@ sub extract {
return shift->_extract(shift);
}
sub insert {
return shift->_insert(shift);
}
1;
package FL2::prefix_nothing;
@ -227,6 +267,10 @@ sub extract {
return shift->_extract(shift);
}
sub insert {
return shift->_insert(shift);
}
1;
package FL2::prefix_head;
@ -295,6 +339,16 @@ sub extract {
}
# Note, no insert() will work until we know how to generate the checksum
#sub insert {
# my $self = shift;
# my $imgfile = shift;
#
# my $write = $self->_insert($imgfile);
#
# Calculate checksum
# write checksum to header
#}
1;
@ -322,7 +376,7 @@ use IO::File;
sub detect_img {
my $fl2name = shift;
my $fh = IO::File->new($fl2name, "r"); # FIXME - openmode
my $fh = IO::File->new($fl2name, "r+");
if (!defined($fh)) {
warn("Could not open $fl2name: $!");
return undef;

@ -1,27 +0,0 @@
#!/bin/bash
#
# Quick and dirty extractor to slice out a section of a binary file
# Copyright (C) 2016 Hamish Coleman
#
# TODO:
# - a tool that is portable to Windows
# - should output dependency information
INFOFILE="$1"
if [ ! -r "$INFOFILE" ]; then
echo Need file with source and offset info
exit 1
fi
shift
OUT="$1"
if [ -z "$OUT" ]; then
echo Need output filename
exit 1
fi
read SOURCE OFFSET LENGTH <"$INFOFILE"
set -x
dd status=none iflag=count_bytes,skip_bytes if="$SOURCE" skip="$((OFFSET))" count="$((LENGTH))" of="$OUT"

@ -1,36 +0,0 @@
#!/bin/bash
#
# Quick and dirty script to insert a slice into a binary file
# Copyright (C) 2016 Hamish Coleman
#
# TODO:
# - a tool that is portable to Windows
# - should output dependency information
INFOFILE="$1"
if [ ! -r "$INFOFILE" ]; then
echo Need file with source and offset info
exit 1
fi
shift
INPUT="$1"
if [ -z "$INPUT" ]; then
echo Need input filename
exit 1
fi
shift
OUT="$1"
if [ -z "$OUT" ]; then
echo Need output filename
exit 1
fi
read SOURCE OFFSET LENGTH <"$INFOFILE"
set -x
cp --reflink=auto "$SOURCE" "$OUT"
dd status=none if="$INPUT" bs="$((LENGTH))" count=1 | dd status=none conv=notrunc bs="$((OFFSET))" seek=1 of="$OUT"

@ -1 +0,0 @@
t430.G1HT34WW.s01D2000.FL2.orig 0x00500000 196608

@ -1 +0,0 @@
t430.G1HT35WW.s01D2000.FL2.orig 0x00500000 196608

@ -1 +0,0 @@
t430s.G7HT39WW.s01D8000.FL2.orig 0x500000 196608

@ -1,2 +0,0 @@
t530.G4HT39WW.s01D5100.FL2.orig 0x00500000 196608

@ -1,2 +0,0 @@
w530.G4HT39WW.s01D5200.FL2.orig 0x00500000 196608

@ -1 +0,0 @@
x220.8DHT34WW.s01CB000.FL2.orig 0x00500000 0x20000

@ -1 +0,0 @@
8duj27us.iso.orig 0x000e2a00 8523776

@ -1,2 +0,0 @@
x230.G2HT35WW.s01D3000.FL2.orig 0x00500000 196608

@ -1,2 +0,0 @@
x230t.GCHT25WW.s01DA000.FL2.orig 0x00500000 196608

@ -1 +0,0 @@
x250.N10HT17W.s01E5000.FL2.orig 0x20 196608

@ -1 +0,0 @@
x260.R02HT29W.s0AR0200.FL2.orig 0x20 286720

@ -1 +0,0 @@
x270.R0IHT30W.s0AR0I00.FL2.orig 0x20 286720
Loading…
Cancel
Save