# Firmware update action # # 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 . get_dist() { local dist_ids='' local i=0 local dist='' dist_ids="$(board_get_dists)" if [ $(printf '%s' "${dist_ids}" | wc -w | cut -d ' ' -f 1) -gt 1 ] then set -- for dist_id in ${dist_ids}; do set -- "${@}" "$(dist_get_name "${dist_id}")" done if ! i=$(show_menu 'Select a firmware distributor' "${@}"); then return 1 fi i=$(($i + 1)) dist="$(printf '%s ' ${dist_ids} | cut -d ' ' -f ${i})" else dist="$(printf '%s' ${dist_ids})" fi select_dist "${dist}" dbg 'Distributor: %s' "${dist}" return 0 } get_mirror() { local mirror_url='' local mirror_label='' local mirror_urls='' local i=0 set -- while :; do if ! read -r mirror_url || ! read -r mirror_label; then break fi mirror_urls="${mirror_urls} ${mirror_url}" set -- "${@}" "${mirror_label}" done <<-EOF $(dist_get_mirrors) EOF if ! i=$(show_menu 'Select a mirror' "${@}"); then return 1 fi i=$(($i + 1)) mirror_url="$(printf '%s ' ${mirror_urls} | cut -d ' ' -f ${i})" dbg 'Mirror: %s' "${mirror_url}" printf '%s' "${mirror_url}" return 0 } get_version() { local mirror="${1}" shift 1 local versions='' local i=0 local version='' if ! versions="$(dist_get_versions "${mirror}" "$(board_get)")"; then return 1 fi if ! i=$(show_menu 'Select a version' ${versions}); then return 1 fi i=$(($i + 1)) version="$(printf '%s ' ${versions} | cut -d ' ' -f ${i})" dbg 'Version: %s' "${version}" printf '%s' "${version}" return 0 } do_update() { local mirror='' local version='' local rom='' dbg 'Updating firmware' # Probe for board and chip. if ! flashrom_probe; then return 1 fi # Select firmware distributor, mirror, and version. if ! get_dist; then return 1 fi if ! mirror="$(get_mirror)"; then return 1 fi if ! version="$(get_version "${mirror}")"; then return 1 fi # Get and prepare a ROM. if ! dist_get_rom "${mirror}" "${version}" "$(board_get_id)"; then return 1 fi if ! board_prepare_rom; then rm_temp 'rom' return 1 fi # Write the ROM to flash. info 'Installing new firmware...' if flashrom_write "$(board_get_chip)"; then info 'Firmware installation complete' sleep 5 rm_temp 'rom' return 1 fi # Clean up the ROM. rm_temp 'rom' return 0 }