Remove most of the variables from the autoexec.bat template

Instead use a *.report file for each component and add data as we
go, culminating in the built image simply catting the report to the
screen to show the user what is about to occur.

This is on the path towards removing all variables from the autoexec
template - which would make it simpler to reuse the same template for
other commands (e.g the x200 series does not use dosflash.exe)
pull/36/head
Hamish Coleman 7 years ago
parent 409f88c75c
commit c0b2178942

1
.gitignore vendored

@ -13,6 +13,7 @@
# ignore generated files # ignore generated files
*.bat *.bat
*.report
.d .d
# Temp are (should be) just junk # Temp are (should be) just junk

@ -40,7 +40,7 @@ $(shell mkdir -p $(DEPSDIR))
clean: clean:
rm -f $(CLEAN_FILES) \ rm -f $(CLEAN_FILES) \
patched.*.iso patched.*.img *.FL2 *.FL2.orig *.img.enc \ patched.*.iso patched.*.img *.FL2 *.FL2.orig *.img.enc \
*.img.enc.orig *.img.orig *.bat \ *.img.enc.orig *.img.orig *.bat *.report \
*.img \ *.img \
*.txt.orig *.txt.orig
rm -rf *.iso.extract *.iso.orig.extract rm -rf *.iso.extract *.iso.orig.extract
@ -195,14 +195,14 @@ endef
# Generate a working file with any known patches applied # Generate a working file with any known patches applied
%.img: %.img.orig %.img: %.img.orig
cp --reflink=auto $< $@ cp --reflink=auto $< $@
./scripts/hexpatch.pl --rm_on_fail $@ $@.d/*.patch ./scripts/hexpatch.pl --rm_on_fail --report $@.report $@ $@.d/*.patch
# using both __DIR and __FL2 is a hack to get around needing to quote the # using both __DIR and __FL2 is a hack to get around needing to quote the
# DOS path separator. It feels like there should be a better way if I put # DOS path separator. It feels like there should be a better way if I put
# my mind to it.. # my mind to it..
# #
%.iso.bat: %.iso.orig autoexec.bat.template %.iso.bat: %.iso.orig autoexec.bat.template
sed -e "s%__DIR%`mdir -/ -b -i $<@@$(FAT_OFFSET) |grep FL2 |head -1|cut -d/ -f3`%; s%__FL2%`mdir -/ -b -i $<@@$(FAT_OFFSET) |grep FL2 |head -1|cut -d/ -f4`%; s%__DESC%`scripts/describe $(basename $<)`%; s/__BUILDINFO/$(BUILDINFO)/" autoexec.bat.template >$@.tmp sed -e "s%__DIR%`mdir -/ -b -i $<@@$(FAT_OFFSET) |grep FL2 |head -1|cut -d/ -f3`%; s%__FL2%`mdir -/ -b -i $<@@$(FAT_OFFSET) |grep FL2 |head -1|cut -d/ -f4`%" autoexec.bat.template >$@.tmp
mv $@.tmp $@ mv $@.tmp $@
touch -d @1 $@ touch -d @1 $@
@ -246,14 +246,14 @@ GETELTORITO := ./scripts/geteltorito
$(GETELTORITO) -o $@.tmp $< $(GETELTORITO) -o $@.tmp $<
./scripts/fix_mbr $@.tmp ./scripts/fix_mbr $@.tmp
mv $@.tmp $@ mv $@.tmp $@
$(call build_info,$<.bat) $(call build_info,$<.report)
# $1 is the lenovo named iso # $1 is the lenovo named iso
# $2 is the nicely named iso # $2 is the nicely named iso
define patched_iso define patched_iso
mv $1 $2 mv $1 $2
mv $1.bat $2.bat mv $1.report $2.report
$(call build_info,$2.bat) $(call build_info,$2.report)
endef endef
# $1 is the bat file # $1 is the bat file
@ -261,7 +261,27 @@ define build_info
@echo @echo
@echo @echo
@echo Your build has completed with the following details: @echo Your build has completed with the following details:
@grep Buil $1 @echo
@cat $1
endef
# Add information about the FL2 file to the current report
# $< is the IMG file
# $@ is the FL2 file being inserted into
define buildinfo_FL2
echo "Buildinfo: $(BUILDINFO)" >$@.report
echo "Built: `sha1sum $@`" >>$@.report
echo "" >>$@.report
cat $<.report >>$@.report
endef
# Add information about the ISO file to the current report
# $< is the FL2 file
# $@ is the ISO file being inserted into
define buildinfo_ISO
cp $<.report $@.report
echo "" >>$@.report
echo "Description: `scripts/describe $@`" >>$@.report
endef endef
# simple testing of images in an emulator # simple testing of images in an emulator
@ -317,8 +337,9 @@ rule_IMG_extract_DEPS = scripts/FL2_copyIMG mec-tools/mec_encrypt mec-tools/mec_
define rule_FL2_insert define rule_FL2_insert
cp --reflink=auto $@.orig $@.tmp cp --reflink=auto $@.orig $@.tmp
./scripts/ISO_copyFL2 to_iso $@.tmp $< $(1) ./scripts/ISO_copyFL2 to_iso $@.tmp $< $(1)
sed -i "s/__BUILT/`sha1sum $<`/" $@.bat $(call buildinfo_ISO)
mcopy -m -o -i $@.tmp@@$(FAT_OFFSET) $@.bat ::AUTOEXEC.BAT mcopy -t -m -o -i $@.tmp@@$(FAT_OFFSET) $@.report ::report.txt
mcopy -t -m -o -i $@.tmp@@$(FAT_OFFSET) $@.bat ::AUTOEXEC.BAT
-mdel -i $@.tmp@@$(FAT_OFFSET) ::EFI/Boot/BootX64.efi -mdel -i $@.tmp@@$(FAT_OFFSET) ::EFI/Boot/BootX64.efi
mv $@.tmp $@ mv $@.tmp $@
endef endef
@ -327,6 +348,10 @@ rule_FL2_insert_DEPS = scripts/ISO_copyFL2 # TODO - bat file
# - maybe mdel any FL1 files, so the image can not accidentally be used to # - maybe mdel any FL1 files, so the image can not accidentally be used to
# flash the BIOS? # flash the BIOS?
# - only delete the UEFI updater if it exists in the original ISO # - only delete the UEFI updater if it exists in the original ISO
# - continue removing variables from the AUTOEXEC bat - perhaps calculate
# its contents here
# - provide a simple mechanism for selecting the flash command to run, to
# allow for autoexec bat files that do not use dosflash
# Insert the new firmware into the FL2 file # Insert the new firmware into the FL2 file
# #
@ -338,6 +363,7 @@ define rule_IMG_insert
./scripts/FL2_copyIMG to_fl2 $@.tmp $<.enc.tmp ./scripts/FL2_copyIMG to_fl2 $@.tmp $<.enc.tmp
rm $<.enc.tmp rm $<.enc.tmp
mv $@.tmp $@ mv $@.tmp $@
$(call buildinfo_FL2)
endef endef
rule_IMG_insert_DEPS = scripts/FL2_copyIMG scripts/xx30.encrypt rule_IMG_insert_DEPS = scripts/FL2_copyIMG scripts/xx30.encrypt
@ -360,6 +386,7 @@ define rule_IMGnoenc_insert
cp --reflink=auto $@.orig $@.tmp cp --reflink=auto $@.orig $@.tmp
./scripts/FL2_copyIMG to_fl2 $@.tmp $< ./scripts/FL2_copyIMG to_fl2 $@.tmp $<
mv $@.tmp $@ mv $@.tmp $@
$(call buildinfo_FL2)
endef endef
rule_IMGnoenc_insert_DEPS = scripts/FL2_copyIMG rule_IMGnoenc_insert_DEPS = scripts/FL2_copyIMG

@ -1,24 +1,20 @@
@ECHO OFF @ECHO OFF
PROMPT $p$g PROMPT $p$g
cd c:\flash cd c:\flash
cls cls
echo. echo.
echo. echo.
echo This will flash your firmware to support a classic 7-row keyboard echo This will flash your Embedded controller firmware
echo. echo.
echo. echo.
echo WARNING: Incorrectly flashing your firmware can damage your laptop. echo WARNING: Incorrectly flashing your firmware can damage your laptop.
echo Ensure this is the right firmware version before attempting to flash echo Ensure this is the right firmware version before attempting to flash
echo the firmware - there are minimal checks done. echo the firmware - there are minimal checks done.
echo. echo.
echo This disc will flash the file __DIR\__FL2 echo This disc will flash the file __DIR\__FL2
echo. echo.
echo This disk is prepared for __DESC type c:\report.txt
echo. echo.
echo Buildinfo: __BUILDINFO pause
echo Built: __BUILT echo on
echo. dosflash /sd /ipf ec /file __DIR\__FL2
pause
echo on
dosflash /sd /ipf ec /file __DIR\__FL2

@ -20,7 +20,7 @@ sub usage() {
print("patching the right file\n"); print("patching the right file\n");
print("\n"); print("\n");
print("Usage:\n"); print("Usage:\n");
print(" hexpatch.pl [--rm_on_fail] binaryfile patchfile [patchfile...]\n"); print(" hexpatch.pl [--rm_on_fail] [--report file] binaryfile patchfile [patchfile...]\n");
print("\n"); print("\n");
exit(1); exit(1);
} }
@ -138,6 +138,7 @@ sub verify_context {
$fh->seek($addr,SEEK_SET); $fh->seek($addr,SEEK_SET);
$fh->read($found,length($expected)); $fh->read($found,length($expected));
# TODO - if found eq new warn "patch reversed?"
if ($found ne $expected) { if ($found ne $expected) {
warn("Address $addr mismatched data\n"); warn("Address $addr mismatched data\n");
return undef; return undef;
@ -167,6 +168,40 @@ sub apply_patch {
} }
} }
sub output_report {
my $filename = shift;
my @patches = @_;
my $fh = IO::File->new($filename, "w");
if (!defined($fh)) {
warn("Could not open report file $filename: $!\n");
exit(1);
}
if (!@patches) {
$fh->print("No patches applied: Lenovo default firmware\n");
return;
}
$fh->print("Patches applied:\n");
my $line = "";
for my $patch (@patches) {
if (length($line)+length($patch)+1 > 79) {
$line .= "\n";
$fh->print($line);
$line = "";
}
if ($line) {
$line .= " ";
}
$line .= $patch;
}
if ($line) {
$line .= "\n";
$fh->print($line);
}
}
sub rm_on_fail { sub rm_on_fail {
my ($bool, $filename) = @_; my ($bool, $filename) = @_;
@ -182,6 +217,12 @@ sub main() {
shift @ARGV; shift @ARGV;
} }
my $reportfile;
if (defined($ARGV[0]) && $ARGV[0] eq "--report") {
shift @ARGV;
$reportfile=shift @ARGV;
}
my $binaryfile = shift @ARGV; my $binaryfile = shift @ARGV;
if (!defined($binaryfile) or !defined($ARGV[0])) { if (!defined($binaryfile) or !defined($ARGV[0])) {
usage(); usage();
@ -195,6 +236,7 @@ sub main() {
print("Attempting to patch $binaryfile\n"); print("Attempting to patch $binaryfile\n");
my @report_patches;
while ($ARGV[0]) { while ($ARGV[0]) {
my $patchfile = shift @ARGV; my $patchfile = shift @ARGV;
@ -219,6 +261,11 @@ sub main() {
print("Applying ",$patchfile," ",$db->{name},"\n"); print("Applying ",$patchfile," ",$db->{name},"\n");
apply_patch($db,$fh); apply_patch($db,$fh);
push @report_patches,$patchfile;
}
if ($reportfile) {
output_report($reportfile,@report_patches);
} }
} }
main(); main();

Loading…
Cancel
Save