flashrom 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env bash
  2. # helper script: builds flashrom source code
  3. #
  4. # Copyright (C) 2014, 2015 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. # This script assumes that the working directory is the root
  21. # of git or release archive
  22. [ "x${DEBUG+set}" = 'xset' ] && set -v
  23. set -u -e
  24. if [ -z ${NPROC+x} ]; then
  25. cores="$(nproc)"
  26. else
  27. case ${NPROC} in
  28. ''|*[!0-9]*)
  29. printf "value '%s' for NPROC is invalid. non-numeric. Exiting.\n" "${NPROC}"
  30. exit 1
  31. ;;
  32. esac
  33. cores="${NPROC}"
  34. fi
  35. # Build "flashrom" (utility for flashing/dumping ROMs)
  36. # --------------------------------------------------------------------
  37. printf "Building flashrom\n"
  38. cd "flashrom/"
  39. make clean
  40. if (( $# != 1 )); then
  41. make -j${cores}
  42. else
  43. if [ "${1}" = "static" ]; then
  44. make SHARED=0 CC='gcc -static' -j${cores} CONFIG_ENABLE_LIBUSB1_PROGRAMMERS=no
  45. else
  46. make -j${cores} CONFIG_ENABLE_LIBUSB1_PROGRAMMERS=no
  47. fi
  48. fi
  49. mv "flashrom" "flashrom_normal"
  50. # build patched binaries for MX25L1605D and SST25VF016B flash chips
  51. # - these patches are needed for initial installation on an X60 or T60
  52. # - these patches are for people who have lenovo bios running
  53. for patchname in "lenovobios_macronix" "lenovobios_sst"
  54. do
  55. # first remove the existing build
  56. rm -f "flashrom_${patchname}"
  57. # backup the unpatched flashchips.c (it will be patched)
  58. cp "flashchips.c" "flashchips.c_"
  59. # patch flashchips.c
  60. patch "flashchips.c" < "../resources/flashrom/patch/${patchname}.diff"
  61. make clean
  62. if (( $# != 1 )); then
  63. make -j${cores} CONFIG_ENABLE_LIBUSB1_PROGRAMMERS=no
  64. else
  65. if [ "${1}" = "static" ]; then
  66. make SHARED=0 CC='gcc -static' -j${cores} CONFIG_ENABLE_LIBUSB1_PROGRAMMERS=no
  67. else
  68. make -j${cores} CONFIG_ENABLE_LIBUSB1_PROGRAMMERS=no
  69. fi
  70. fi
  71. # Rename the binary based on the patch name
  72. mv "flashrom" "flashrom_${patchname}"
  73. # restore unpatched flashchips.c
  74. rm -f "flashchips.c"
  75. mv "flashchips.c_" "flashchips.c"
  76. done
  77. mv "flashrom_normal" "flashrom"
  78. cd "../"