summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/flashrom.sh85
-rw-r--r--src/local.mk1
2 files changed, 86 insertions, 0 deletions
diff --git a/src/flashrom.sh b/src/flashrom.sh
new file mode 100644
index 0000000..078dc79
--- /dev/null
+++ b/src/flashrom.sh
@@ -0,0 +1,85 @@
+# Functions for working with flashrom
+#
+# Copyright (C) 2015 Patrick "P. J." McDermott
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+flashrom_probe()
+{
+ local board_vendor=''
+ local board_part=''
+ local board_found=false
+ local chip_vendor=''
+ local chip_device=''
+ local chip_size=''
+ local chip_bus=''
+ local chip_found=false
+
+ IFS=''
+ while read -r line; do
+ unset IFS
+ case "${line}" in
+ 'Vendor ID: '*', part ID: '*)
+ board_vendor="${line%, part ID: *}"
+ board_vendor="${board_vendor#Vendor ID: }"
+ board_part="${line#*, part ID: }"
+ dbg 'Found board:'
+ dbg ' Vendor: %s' "${board_vendor}"
+ dbg ' Part: %s' "${board_part}"
+ board_found=true
+ ;;
+ 'Found '*' flash chip "'*'" ('*' kB, '*').')
+ if ! ${board_found}; then
+ err 'Failed to probe board'
+ return 1
+ fi
+ chip_vendor="${line% flash chip *}"
+ chip_vendor="${line#Found }"
+ chip_device="${line#* flash chip \"}"
+ chip_device="${chip_device%\" (*}"
+ chip_size="${line#* (}"
+ chip_size="${chip_size% kB, *}"
+ chip_bus="${line#* kB, }"
+ chip_bus="${chip_bus%).}"
+ dbg 'Found chip:'
+ dbg ' Vendor: %s' "${chip_vendor}"
+ dbg ' Device: %s' "${chip_device}"
+ dbg ' Size: %u' "${chip_size}"
+ dbg ' Bus: %s' "${chip_bus}"
+ if find_board "${board_vendor}" \
+ "${board_part}" "${chip_device}"
+ then
+ chip_found=true
+ break
+ fi
+ ;;
+ esac
+ IFS=''
+ done <flashrom.log
+ #done <<-EOF
+ # $(${FLASHROM} -p internal -V)
+ # EOF
+ unset IFS
+
+ if ! ${board_found}; then
+ err 'Failed to probe board'
+ return 1
+ fi
+ if ! ${chip_found}; then
+ err 'Failed to probe chip'
+ return 1
+ fi
+
+ return 0
+}
diff --git a/src/local.mk b/src/local.mk
index bc953dc..75bbd68 100644
--- a/src/local.mk
+++ b/src/local.mk
@@ -1,6 +1,7 @@
firman_SOURCES += \
src/board.sh \
src/dist.sh \
+ src/flashrom.sh \
src/main.sh \
src/ui.sh