-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add extractor for *.FL[12] files #162
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2019 onwards, Samveen S. Gulati | ||
# | ||
# Script to extract FL1 or FL2 files from Lenovo BIOS update ISO image | ||
# | ||
|
||
# EL TORITO offset count (thanks to Hamish Coleman) | ||
FAT_OFFSET=71680 | ||
|
||
USAGE="${0} [[-1|--fl1] [-2|--fl2]] {[-i|--iso] ISO_FILE} {[-d|--desc] DESC_FILE} [[-m|--model] PREFIX] [[-s|--suffix] SUFFIX] | [-h|--help] | ||
-1|--fl1 Extract BIOS update file (.FL1) | ||
-2|--fl2 Extract EC update file (.FL2) (Default if no option) | ||
-i|--iso Update ISO to extract the file from | ||
-d|--desc Path of Descriptions.txt file | ||
-m|--model Optional model prefix to attach to extracted filenames. | ||
-s|--suffix Optional suffix to attach to extracted filenames. | ||
-h|--help Show this help" | ||
|
||
# Get and parse options | ||
OPTIONS=$(getopt -o 12i:d:m:s:h --long fl1,fl2,iso:,desc:,model:,suffix:,help -n "$0" -- "$@") | ||
# Note the quotes around `$OPTIONS': they are essential! | ||
eval set -- "$OPTIONS" | ||
|
||
while true ; do | ||
case "$1" in | ||
-1|--fl1) FL1=Y ; shift ;; | ||
-2|--fl2) FL2=Y ; shift ;; | ||
-i|--iso) ISO=$2 ; shift 2 ;; | ||
-d|--desc) DESC=$2 ; shift 2 ;; | ||
-m|--model) MODEL="${2%%.}." ; shift 2 ;; | ||
-s|--suffix) SUFFIX=".${2##.}" ; shift 2 ;; | ||
-h|--help) echo "$USAGE"; exit ;; | ||
--) shift ; break ;; | ||
*) echo "Internal error!" ; exit 1 ;; | ||
esac | ||
done | ||
|
||
# Reasonable Defaults: extract only FL2 | ||
if [[ -z $FL1 ]] && [[ -z $FL2 ]]; then | ||
FL2=Y | ||
fi | ||
|
||
[[ -n "$ISO" ]] || { echo -e "Error: Missing ISO filename\n${USAGE}" >&2; exit 2; } | ||
[[ -f "$ISO" ]] || { echo -e "Error: ${ISO} not found or not a file\n${USAGE}" >&2; exit 4; } | ||
[[ -f "$DESC" ]] || { echo -e "Error: Missing Descriptions file.\n${USAGE}" >&2; exit 8; } | ||
[[ -n "$MODEL" ]] && echo "Using ${MODEL} as prefix" >&2 || echo "No model name provided. Not using any prefix" >&2 | ||
[[ -n "$SUFFIX" ]] && echo "Using ${SUFFIX} as suffix" >&2 || echo "Not using any suffix." >&2 | ||
|
||
# ./scripts/ISO_copyFL2 from_iso $< $@ $(1) | ||
|
||
if ! which mdir >/dev/null; then | ||
echo "Fatal: mtools package not installed or not in path" >&2 | ||
exit 16 | ||
fi | ||
|
||
read -r FL1VERNUM FL1VER FL2VERNUM FL2VER < <(grep -E "^${ISO%%.iso*}" ../Descriptions.txt| \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean "$DESC" here, instead of ../Descriptions.txt ? Also, you are treating a free-form text string as a set of fixed format fields when you extract the various version numbers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah. That's a typo. I'll fix it.
I looked at the format of the file, and I see that there is a bit of commonality between all the version lines, so I'm counting on this structure. The issue is that for the EC versioning. there is no way that I know off to figure out the EC version number from the contents of a given ISO. However, I'm hoping there is something, which I have not yet figured out myself, which allows that. It is possible for the BIOS version string (not the number itself), which I can implement. Any suggestions? |
||
grep BIOS| \ | ||
grep -v BROKEN| \ | ||
sed 's/.\+ BIOS //; s/ EC / /; s/[()]//g') | ||
|
||
# The "internal" filename pattern to match - used in the BIOS update image | ||
FILELIST="$(mdir -/ -b -f -i "$ISO"@@"$FAT_OFFSET")" | ||
|
||
if [[ -n $FL1 ]]; then | ||
FL1PATH="$(echo "$FILELIST" |grep '.FL1$')" | ||
if [ -z "$FL1PATH" ]; then | ||
echo "Error: could not find any files in $ISO matching *.FL1" >&2 | ||
exit 32 | ||
fi | ||
if [[ $(echo "$FL1PATH" |wc -l) -gt 1 ]]; then | ||
echo "Error: $ISO has more than one FL1 files" >&2 | ||
echo "$FL1PATH" | ||
exit 64 | ||
fi | ||
|
||
|
||
FL1NAME="${MODEL}${FL1VER}.${FL1PATH##*/}${SUFFIX}" | ||
echo "Extracting $FL1PATH (ver $FL1VERNUM) to ${FL1NAME/$/s}" | ||
mcopy -n -i "$ISO"@@"$FAT_OFFSET" "$FL1PATH" "${FL1NAME/\$/s}" | ||
fi | ||
|
||
if [[ -n $FL2 ]]; then | ||
FL2PATH="$(echo "$FILELIST" |grep '.FL2$')" | ||
if [ -z "$FL2PATH" ]; then | ||
echo "Error: could not find any files in $ISO matching *.FL2" >&2 | ||
exit 32 | ||
fi | ||
if [[ $(echo "$FL2PATH" |wc -l) -gt 1 ]]; then | ||
echo "Error: $ISO has more than one FL2 files" >&2 | ||
echo "$FL2PATH" | ||
exit 64 | ||
fi | ||
FL2NAME="${MODEL}${FL2VER}.${FL2PATH##*/}${SUFFIX}" | ||
echo "Extracting $FL2PATH (ver $FL2VERNUM) to ${FL2NAME/$/s}" | ||
mcopy -n -i "$ISO"@@"$FAT_OFFSET" "$FL2PATH" "${FL2NAME/$/s}" | ||
fi | ||
|
||
# vim: expandtab sw=4 ts=4: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be sure you are aware - this number has been known to change, and is an artifact of the Lenovo build process (and not guaranteed). There is a way to calculate it, if needed