2016-04-23 04:02:28 +00:00
|
|
|
#
|
|
|
|
# Infrastructure to manage patching thinkpad EC firmware
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 Hamish Coleman
|
|
|
|
#
|
2016-04-19 08:54:06 +00:00
|
|
|
|
2016-05-20 01:24:23 +00:00
|
|
|
all: list_laptops
|
2016-04-29 10:36:28 +00:00
|
|
|
$(info See README file for additional details)
|
|
|
|
$(info )
|
2016-04-24 08:18:06 +00:00
|
|
|
|
2016-05-20 01:24:23 +00:00
|
|
|
.PHONY: all
|
|
|
|
|
2016-06-06 01:16:02 +00:00
|
|
|
GITVERSION = $(shell git describe --dirty --abbrev=6 ) ($(shell date +%Y%m%d))
|
|
|
|
BUILDINFO = $(GITVERSION) $(MAKECMDGOALS)
|
|
|
|
|
2016-05-20 01:24:23 +00:00
|
|
|
list_laptops:
|
|
|
|
$(info )
|
2016-05-20 03:15:18 +00:00
|
|
|
$(info The following make targets are the supported usb images:)
|
2016-05-20 01:24:23 +00:00
|
|
|
$(info )
|
2016-05-20 03:15:18 +00:00
|
|
|
$(info patched.t430.img - for patching Thinkpad T430)
|
|
|
|
$(info patched.t430s.img - for patching Thinkpad T430s)
|
|
|
|
$(info patched.t530.img - for patching Thinkpad T530)
|
|
|
|
$(info patched.t530i.img - for patching Thinkpad T530i)
|
|
|
|
$(info patched.w530.img - for patching Thinkpad W430)
|
|
|
|
$(info patched.x230.img - for patching Thinkpad X230)
|
|
|
|
$(info patched.x230t.img - for patching Thinkpad X230t)
|
2016-05-20 01:24:23 +00:00
|
|
|
$(info )
|
2016-06-03 03:01:04 +00:00
|
|
|
$(info patched.t430.257.img - for patching Thinkpad T430 BIOS 2.57 - no keyboard patch)
|
|
|
|
$(info )
|
2016-05-20 01:24:23 +00:00
|
|
|
|
|
|
|
.PHONY: list_laptops
|
|
|
|
|
2016-07-19 04:52:03 +00:00
|
|
|
# Remove all the usual junk (including any patched firmware images)
|
2016-05-28 12:21:22 +00:00
|
|
|
clean:
|
|
|
|
rm -f patched.*.iso patched.*.img *.FL2 *.FL2.orig *.img.enc \
|
2016-07-19 04:52:03 +00:00
|
|
|
*.img.enc.orig *.img.orig *.bat \
|
|
|
|
*.img
|
2016-05-28 12:21:22 +00:00
|
|
|
|
2016-07-19 04:52:03 +00:00
|
|
|
# Also remove the large downloaded iso images
|
2016-05-28 12:21:22 +00:00
|
|
|
really_clean: clean
|
2016-07-19 04:52:03 +00:00
|
|
|
rm -f *.iso.orig
|
2016-05-28 12:21:22 +00:00
|
|
|
|
2016-05-20 01:24:23 +00:00
|
|
|
# manually managed list of laptops - update this if the BIOS versions change
|
|
|
|
|
|
|
|
patched.t430.iso: g1uj38us.iso
|
2016-06-06 01:59:57 +00:00
|
|
|
$(call patched_iso,$<,$@)
|
2016-05-20 01:24:23 +00:00
|
|
|
|
2016-06-02 21:44:14 +00:00
|
|
|
patched.t430.257.iso: g1uj25us.iso
|
2016-06-06 01:59:57 +00:00
|
|
|
$(call patched_iso,$<,$@)
|
2016-06-02 21:44:14 +00:00
|
|
|
|
2016-06-06 07:12:48 +00:00
|
|
|
patched.t430s.iso: g7uj19us.iso
|
2016-06-06 01:59:57 +00:00
|
|
|
$(call patched_iso,$<,$@)
|
2016-05-20 01:24:23 +00:00
|
|
|
|
|
|
|
patched.t530.iso: g4uj30us.iso
|
2016-06-06 01:59:57 +00:00
|
|
|
$(call patched_iso,$<,$@)
|
2016-05-20 01:24:23 +00:00
|
|
|
|
|
|
|
patched.t530i.iso: g4uj30us.iso
|
2016-06-06 01:59:57 +00:00
|
|
|
$(call patched_iso,$<,$@)
|
2016-05-20 01:24:23 +00:00
|
|
|
|
|
|
|
patched.w530.iso: g5uj28us.iso
|
2016-06-06 01:59:57 +00:00
|
|
|
$(call patched_iso,$<,$@)
|
2016-05-20 01:24:23 +00:00
|
|
|
|
|
|
|
patched.x230.iso: g2uj23us.iso
|
2016-06-06 01:59:57 +00:00
|
|
|
$(call patched_iso,$<,$@)
|
2016-05-20 01:24:23 +00:00
|
|
|
|
|
|
|
patched.x230t.iso: gcuj24us.iso
|
2016-06-06 01:59:57 +00:00
|
|
|
$(call patched_iso,$<,$@)
|
2016-05-20 01:24:23 +00:00
|
|
|
|
|
|
|
|
2016-04-27 01:43:31 +00:00
|
|
|
list_iso:
|
2016-04-29 10:36:28 +00:00
|
|
|
$(info )
|
2016-04-27 01:54:10 +00:00
|
|
|
$(info The following make targets are available to produce patched and)
|
2016-04-29 10:36:28 +00:00
|
|
|
$(info bootable ISO images:)
|
2016-04-27 01:43:31 +00:00
|
|
|
$(info )
|
2016-04-27 01:54:10 +00:00
|
|
|
@for i in *.desc; do echo `basename $$i .orig.desc` - for patching `cat $$i`; done
|
2016-04-27 02:46:47 +00:00
|
|
|
@echo
|
2016-04-27 01:43:31 +00:00
|
|
|
|
2016-05-20 01:24:23 +00:00
|
|
|
.PHONY: list_iso
|
|
|
|
|
2016-04-27 01:43:31 +00:00
|
|
|
# FIXME - need to automatically generate the iso image target list
|
|
|
|
|
2016-04-24 08:18:06 +00:00
|
|
|
list_images:
|
|
|
|
$(info The following make targets are available to produce firmware images:)
|
|
|
|
$(info )
|
|
|
|
$(info $(basename $(wildcard *.d)))
|
|
|
|
$(info )
|
|
|
|
$(info The following make targets are available to produce FL2 files:)
|
|
|
|
$(info )
|
|
|
|
$(info $(foreach i,$(basename $(basename $(wildcard *.d))),$(basename $(wildcard $(i).*.FL2.slice))))
|
|
|
|
$(info )
|
|
|
|
@true
|
|
|
|
|
2016-05-20 01:24:23 +00:00
|
|
|
.PHONY: list_images
|
2016-04-19 08:54:06 +00:00
|
|
|
|
2016-04-26 14:43:48 +00:00
|
|
|
# All the bios update iso images I have checked have had a fat16 filesystem
|
|
|
|
# embedded in a dos mbr image as the el-torito ISO payload. They also all
|
|
|
|
# had the same offset to this fat filesystem, so hardcode that offset here.
|
|
|
|
FAT_OFFSET := 71680
|
|
|
|
|
2016-05-28 13:35:51 +00:00
|
|
|
# Some versions of mtools need this flag set to allow them to work with the
|
|
|
|
# dosfs images used by Lenovo - from my tests, it may be that Debian has
|
|
|
|
# applied some patch
|
|
|
|
export MTOOLS_SKIP_CHECK=1
|
|
|
|
|
2016-04-19 08:54:06 +00:00
|
|
|
#
|
2016-04-26 14:35:57 +00:00
|
|
|
# Radare didnt seem to let me specify the directory to store the project file,
|
2016-04-19 08:54:06 +00:00
|
|
|
# so this target hacks around that
|
|
|
|
#
|
|
|
|
install.radare.projects:
|
|
|
|
mkdir -p ~/.config/radare2/projects/x220.8DHT34WW.d
|
2016-04-21 02:15:37 +00:00
|
|
|
cp -fs $(PWD)/radare/x220.8DHT34WW ~/.config/radare2/projects
|
|
|
|
mkdir -p ~/.config/radare2/projects/x230.G2HT35WW.d
|
|
|
|
cp -fs $(PWD)/radare/x230.G2HT35WW ~/.config/radare2/projects
|
2016-04-29 10:36:28 +00:00
|
|
|
mkdir -p ~/.config/radare2/projects/x260.R02HT29W.d/
|
|
|
|
cp -fs $(PWD)/radare/x260.R02HT29W ~/.config/radare2/projects
|
2016-04-19 08:54:06 +00:00
|
|
|
|
2016-04-27 01:16:19 +00:00
|
|
|
DEPSDIR := .d
|
|
|
|
$(shell mkdir -p $(DEPSDIR))
|
|
|
|
-include $(DEPSDIR)/slice.extract.deps
|
2016-04-27 07:22:04 +00:00
|
|
|
$(DEPSDIR)/slice.extract.deps: Makefile
|
2016-05-26 06:59:15 +00:00
|
|
|
for i in *.slice; do read SLICEE other <$$i; echo $$i: $$SLICEE; done >$@.tmp
|
|
|
|
mv $@.tmp $@
|
2016-04-27 01:16:19 +00:00
|
|
|
-include $(DEPSDIR)/slice.insert.deps
|
2016-04-27 07:22:04 +00:00
|
|
|
$(DEPSDIR)/slice.insert.deps: Makefile
|
2016-05-26 06:59:15 +00:00
|
|
|
for i in *.slice; do read SLICEE other <$$i; echo `basename $$SLICEE .orig`: $$i `basename $$i .slice`; done >$@.tmp
|
|
|
|
mv $@.tmp $@
|
2016-04-27 01:16:19 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2016-04-19 09:02:49 +00:00
|
|
|
#
|
|
|
|
# Download any ISO image that we have a checksum for
|
|
|
|
# NOTE: makes an assumption about the Lenovo URL not changing
|
2016-04-19 10:52:09 +00:00
|
|
|
%.iso.orig: %.iso.orig.sha1
|
|
|
|
wget -O $@ https://download.lenovo.com/pccbbs/mobiles/$(basename $@)
|
2016-04-19 09:02:49 +00:00
|
|
|
sha1sum -c $<
|
|
|
|
touch $@
|
|
|
|
|
2016-04-24 05:47:23 +00:00
|
|
|
# Generate all the orig images so that we can diff against them later
|
2016-04-19 09:20:27 +00:00
|
|
|
|
2016-04-24 05:47:23 +00:00
|
|
|
# a the generic binary extractor
|
2016-04-24 06:25:56 +00:00
|
|
|
%.orig: %.slice slice.extract
|
2016-04-24 05:47:23 +00:00
|
|
|
./slice.extract $< $@
|
2016-04-24 05:29:44 +00:00
|
|
|
|
|
|
|
%.img.orig: %.img.enc.orig %.img.orig.sha1 mec-tools/mec_encrypt
|
2016-05-28 07:46:10 +00:00
|
|
|
mec-tools/mec_encrypt -d $< $@
|
2016-04-23 01:52:10 +00:00
|
|
|
sha1sum -c $@.sha1
|
|
|
|
|
2016-04-23 02:02:04 +00:00
|
|
|
# a generic encryptor
|
|
|
|
%.img.enc: %.img xx30.encrypt
|
|
|
|
./xx30.encrypt $< $@
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
# - if we ever get generic extraction or encryption for more than
|
|
|
|
# just the Xx30 series, these generic rules will need to be reworked
|
2016-04-20 00:53:07 +00:00
|
|
|
|
2016-04-19 10:07:09 +00:00
|
|
|
# keep intermediate files
|
2016-04-24 07:42:31 +00:00
|
|
|
.PRECIOUS: %.orig
|
|
|
|
.PRECIOUS: %.img
|
2016-04-19 10:07:09 +00:00
|
|
|
.PRECIOUS: %.img.orig
|
|
|
|
|
2016-04-22 06:50:48 +00:00
|
|
|
# Generate a working file with any known patches applied
|
2016-04-19 09:54:56 +00:00
|
|
|
%.img: %.img.orig
|
2016-04-22 06:50:48 +00:00
|
|
|
cp --reflink=auto $< $@
|
2016-04-23 01:52:10 +00:00
|
|
|
./hexpatch.pl $@ $@.d/*.patch
|
2016-04-22 06:50:48 +00:00
|
|
|
|
2016-05-24 01:30:08 +00:00
|
|
|
# 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 beter way if I put
|
|
|
|
# my mind to it..
|
|
|
|
#
|
2016-04-27 01:28:21 +00:00
|
|
|
%.iso.bat: %.iso.orig %.iso.orig.desc autoexec.bat.template
|
2016-06-06 01:16:02 +00:00
|
|
|
sed -e "s%__DIR%`mdir -/ -b -i $<@@$(FAT_OFFSET) |grep FL2 |cut -d/ -f3`%; s%__FL2%`mdir -/ -b -i $<@@$(FAT_OFFSET) |grep FL2 |cut -d/ -f4`%; s%__DESC%`cat $<.desc`%; s/__BUILDINFO/$(BUILDINFO)/" autoexec.bat.template >$@.tmp
|
2016-05-26 06:59:15 +00:00
|
|
|
mv $@.tmp $@
|
2016-06-04 05:03:29 +00:00
|
|
|
touch -d @1 $@
|
2016-04-26 14:43:48 +00:00
|
|
|
|
2016-04-27 02:47:10 +00:00
|
|
|
# helper to write the ISO onto a cdrw
|
|
|
|
%.iso.blank_burn: %.iso
|
|
|
|
wodim -eject -v speed=40 -tao gracetime=0 blank=fast $<
|
|
|
|
|
2016-04-22 07:13:50 +00:00
|
|
|
# if you want to work on more patches, you probably want the pre-patched ver
|
|
|
|
%.img.prepatch: %.img.orig
|
|
|
|
cp --reflink=auto $< $(basename $<)
|
|
|
|
|
2016-04-22 06:50:48 +00:00
|
|
|
%.hex: %
|
2016-05-26 06:59:15 +00:00
|
|
|
hd -v $< >$@.tmp
|
|
|
|
mv $@.tmp $@
|
2016-04-22 06:50:48 +00:00
|
|
|
|
|
|
|
# Generate a patch report
|
|
|
|
%.diff: %.hex %.orig.hex
|
2016-05-26 06:59:15 +00:00
|
|
|
-diff -u $(basename $@).orig.hex $(basename $@).hex >$@.tmp
|
|
|
|
mv $@.tmp $@
|
2016-04-24 05:29:44 +00:00
|
|
|
cat $@
|
2016-04-19 09:54:56 +00:00
|
|
|
|
2016-04-27 01:05:14 +00:00
|
|
|
# If we ever want a copy of the dosflash.exe, just get it from the iso image
|
|
|
|
%.dosflash.exe.orig: %.iso.orig
|
2016-06-04 05:03:29 +00:00
|
|
|
mcopy -m -i $^@@$(FAT_OFFSET) ::FLASH/DOSFLASH.EXE $@
|
2016-04-27 01:05:14 +00:00
|
|
|
|
2016-05-20 03:15:18 +00:00
|
|
|
## Use the system provided geteltorito script, if there is one
|
|
|
|
#GETELTORITO := $(shell if type geteltorito >/dev/null; then echo geteltorito; else echo ./geteltorito; fi)
|
|
|
|
|
|
|
|
# use the included geteltorito script always, since we know it does not have
|
|
|
|
# the hdd size bug
|
|
|
|
GETELTORITO := ./geteltorito
|
|
|
|
|
|
|
|
# extract the DOS boot image from an iso (and fix it up so qemu can boot it)
|
|
|
|
%.img: %.iso
|
|
|
|
$(GETELTORITO) -o $@ $<
|
2016-08-11 07:28:07 +00:00
|
|
|
./hexpatch.pl $@ fix-hdd-image-`stat -c %s $@`.patch
|
2016-06-06 01:59:57 +00:00
|
|
|
$(call build_info,$<.bat)
|
|
|
|
|
|
|
|
# $1 is the lenovo named iso
|
|
|
|
# $2 is the nicely named iso
|
|
|
|
define patched_iso
|
|
|
|
mv $1 $2
|
|
|
|
mv $1.bat $2.bat
|
|
|
|
$(call build_info,$2.bat)
|
|
|
|
endef
|
|
|
|
|
|
|
|
# $1 is the bat file
|
|
|
|
define build_info
|
|
|
|
@echo
|
|
|
|
@echo
|
|
|
|
@echo Your build has completed with the following details:
|
|
|
|
@grep Buil $1
|
|
|
|
endef
|
2016-05-20 03:15:18 +00:00
|
|
|
|
|
|
|
# simple testing of images in an emulator
|
|
|
|
%.iso.test: %.iso
|
|
|
|
qemu-system-x86_64 -enable-kvm -cdrom $<
|
|
|
|
|
|
|
|
%.img.test: %.img
|
|
|
|
qemu-system-x86_64 -enable-kvm -hda $<
|
|
|
|
|
2016-04-19 09:39:23 +00:00
|
|
|
mec-tools/Makefile:
|
|
|
|
git submodule update --init --remote
|
|
|
|
|
|
|
|
mec-tools/mec_encrypt: mec-tools/Makefile
|
2016-05-28 13:35:51 +00:00
|
|
|
git submodule update
|
2016-04-19 09:39:23 +00:00
|
|
|
make -C mec-tools
|
|
|
|
|
2016-04-28 03:08:24 +00:00
|
|
|
# using function calls to build rules with actions is kind of a hack,
|
|
|
|
# which is why these are all on oneline.
|
|
|
|
|
|
|
|
# $1 = encoded EC firmware
|
|
|
|
# $2 = FL2 filename
|
|
|
|
define rule_fl2
|
|
|
|
$(2): $(1) ; ./slice.insert $(1).slice $(1) $(2)
|
|
|
|
endef
|
|
|
|
|
|
|
|
# $1 = FL2 filename
|
|
|
|
# $2 = ISO image
|
|
|
|
define rule_iso
|
2016-06-22 01:02:06 +00:00
|
|
|
$(2): $(1) $(2).bat ; ./slice.insert $(1).slice $(1) $(2) && sed -i "s/__BUILT/`sha1sum $(1)`/" $(2).bat && mcopy -m -o -i $(2)@@$(FAT_OFFSET) $(2).bat ::AUTOEXEC.BAT && mdel -i $(2)@@$(FAT_OFFSET) ::EFI/Boot/BootX64.efi
|
2016-04-28 03:08:24 +00:00
|
|
|
endef
|
|
|
|
|
2016-04-19 09:39:23 +00:00
|
|
|
#
|
|
|
|
# TODO:
|
2016-04-27 01:16:19 +00:00
|
|
|
# - add a simple method to autogenerate these non-generic rules
|
2016-04-28 03:08:24 +00:00
|
|
|
# - once that is done, convert the defines back to action bodies, not
|
|
|
|
# rule definitions
|
2016-04-26 14:43:48 +00:00
|
|
|
|
2016-04-24 14:50:24 +00:00
|
|
|
# Hacky, non generic rules
|
2016-04-28 03:08:24 +00:00
|
|
|
$(call rule_fl2,t430.G1HT35WW.img.enc,t430.G1HT35WW.s01D2000.FL2)
|
2016-06-02 21:44:14 +00:00
|
|
|
$(call rule_fl2,t430.G1HT34WW.img.enc,t430.G1HT34WW.s01D2000.FL2)
|
2016-04-28 03:08:24 +00:00
|
|
|
$(call rule_fl2,t430s.G7HT39WW.img.enc,t430s.G7HT39WW.s01D8000.FL2)
|
|
|
|
$(call rule_fl2,t530.G4HT39WW.img.enc,t530.G4HT39WW.s01D5100.FL2)
|
|
|
|
$(call rule_fl2,w530.G4HT39WW.img.enc,w530.G4HT39WW.s01D5200.FL2)
|
|
|
|
$(call rule_fl2,x230.G2HT35WW.img.enc,x230.G2HT35WW.s01D3000.FL2)
|
|
|
|
$(call rule_fl2,x230t.GCHT25WW.img.enc,x230t.GCHT25WW.s01DA000.FL2)
|
|
|
|
|
|
|
|
$(call rule_iso,t430.G1HT35WW.s01D2000.FL2,g1uj38us.iso)
|
2016-06-02 21:44:14 +00:00
|
|
|
$(call rule_iso,t430.G1HT34WW.s01D2000.FL2,g1uj25us.iso)
|
2016-04-28 03:08:24 +00:00
|
|
|
$(call rule_iso,x230.G2HT35WW.s01D3000.FL2,g2uj23us.iso)
|
|
|
|
$(call rule_iso,t530.G4HT39WW.s01D5100.FL2,g4uj30us.iso)
|
|
|
|
$(call rule_iso,w530.G4HT39WW.s01D5200.FL2,g5uj28us.iso)
|
2016-06-06 07:12:48 +00:00
|
|
|
$(call rule_iso,t430s.G7HT39WW.s01D8000.FL2,g7uj19us.iso)
|
2016-04-28 03:08:24 +00:00
|
|
|
$(call rule_iso,x230t.GCHT25WW.s01DA000.FL2,gcuj24us.iso)
|
2016-04-27 08:10:49 +00:00
|
|
|
|