Advertisement
Guest User

csb_patcher.sh - 20 Feb 2024 - http://dangerousprototypes.com/docs/Lenovo_G505S_hacking

a guest
Feb 20th, 2024
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 41.66 KB | Cybersecurity | 0 0
  1. #!/bin/sh
  2. #
  3. #    csb_patcher.sh: coreboot and SeaBIOS patcher script, 20 Feb 2024.
  4. #
  5. #  Conveniently and securely gets, checks SHA256 and installs some of my
  6. # patches from this page - https://review.coreboot.org/q/status:open+banon
  7. #   and also gets a collection of useful floppy-based operating systems.
  8. #  Use restore_agesa.sh script to restore AMD AGESA boards before running.
  9. #   More info at http://dangerousprototypes.com/docs/Lenovo_G505S_hacking
  10. #
  11. #      Please send your feedback to Mike Banon <mikebdp2@gmail.com>.
  12. #   Released under the terms of GNU GPL v3 by Free Software Foundation.
  13. #
  14.  
  15. # Keys
  16. enter=$( printf '\015' )
  17. ctrl_c=$( printf '\003' )
  18. ctrl_x=$( printf '\030' )
  19. ctrl_z=$( printf '\032' )
  20. # Formatting
  21. bold="\e[1m"
  22. bred="\e[1;31m"
  23. bgreen="\e[1;32m"
  24. byellow="\e[1;33m"
  25. bend="\e[0m"
  26.  
  27. # Asks a question '$1' and waits for Y/N user input, printing a decision - with '$2' message if Y.
  28. yesno () {
  29.     printf "$1 [Y/N] "
  30.     yesno_old_stty_cfg=$( stty -g )
  31.     stty raw -echo
  32.     while true ; do
  33.         yesno_answer=$( head -c 1 )
  34.         case "$yesno_answer" in
  35.             *"$ctrl_c"*|"$ctrl_x"*|"$ctrl_z"*)
  36.                 stty "$yesno_old_stty_cfg"
  37.                 printf "${bred}TERMINATED${bend}\n"
  38.                 exit 1
  39.                 ;;
  40.             *"y"*|"Y"*)
  41.                 stty "$yesno_old_stty_cfg"
  42.                 printf "${bgreen}YES${bend}$2\n"
  43.                 return 0
  44.                 ;;
  45.             *"n"*|"N"*)
  46.                 stty "$yesno_old_stty_cfg"
  47.                 printf "${byellow}NO${bend}\n"
  48.                 return 1
  49.                 ;;
  50.         esac
  51.     done
  52. }
  53.  
  54. # Waits until a user presses Enter.
  55. encontinue () {
  56.     printf "\npress [ENTER] to continue... "
  57.     encontinue_old_stty_cfg=$( stty -g )
  58.     stty raw -echo
  59.     while true ; do
  60.         encontinue_answer=$( head -c 1 )
  61.         case "$encontinue_answer" in
  62.             *"$ctrl_c"*|"$ctrl_x"*|"$ctrl_z"*)
  63.                 stty "$encontinue_old_stty_cfg"
  64.                 printf "${bred}TERMINATED${bend}\n"
  65.                 exit 1
  66.                 ;;
  67.             *"$enter"*)
  68.                 stty "$encontinue_old_stty_cfg"
  69.                 printf "\n"
  70.                 return 0
  71.                 ;;
  72.         esac
  73.     done
  74. }
  75.  
  76. # Checks if a command '$1' exists.
  77. command_exists() {
  78.     if [ ! -x "$( command -v $1 )" ] ; then
  79.         printf "\n${bred}ERROR${bend}: command ${bold}$1${bend} is not found !\n"
  80.         encontinue
  81.         return 1
  82.     else
  83.         return 0
  84.     fi
  85. }
  86.  
  87. # Checks if a file '$1' exists.
  88. file_exists () {
  89.     if [ ! -f "$1" ] ; then
  90.         printf "\n${byellow}WARNING${bend}: file ${bold}$1${bend} is not found !\n"
  91.         encontinue
  92.         return 1
  93.     else
  94.         return 0
  95.     fi
  96. }
  97.  
  98. # Force removes a file '$2' and then copies a file '$1' to '$2'.
  99. copier () {
  100.     if file_exists "$1" ; then
  101.         rm -f "$2"
  102.         cp "$1" "$2"
  103.         return 0
  104.     else
  105.         return 1
  106.     fi
  107. }
  108.  
  109. # Force removes a file '$2' and then moves a file '$1' to '$2'.
  110. mover () {
  111.     if file_exists "$1" ; then
  112.         rm -f "$2"
  113.         mv "$1" "$2"
  114.         return 0
  115.     else
  116.         return 1
  117.     fi
  118. }
  119.  
  120. # Checks if a line '$1' contains the text '$2'.
  121. checker () {
  122.     case "$1" in
  123.         *"$2"*)
  124.             return 0
  125.             ;;
  126.         *)
  127.             return 1
  128.             ;;
  129.     esac
  130. }
  131.  
  132. # Prints the lines of a file '$2' that contain the text '$1'.
  133. grepper () {
  134.     if file_exists "$2" ; then
  135.         while IFS= read -r grepper_line
  136.         do
  137.             case "$grepper_line" in
  138.             *"$1"*)
  139.                 printf '%s\n' "$grepper_line"
  140.                 ;;
  141.             *)
  142.                 ;;
  143.         esac
  144.         done < "$2"
  145.         return 0
  146.     else
  147.         return 1
  148.     fi
  149. }
  150.  
  151. # Checks if a file '$2' contains the text '$1'.
  152. grepcheck () {
  153.     if file_exists "$2" ; then
  154.         while IFS= read -r grepcheck_line
  155.         do
  156.             case "$grepcheck_line" in
  157.                 *"$1"*)
  158.                     return 0
  159.                     ;;
  160.                 *)
  161.                     ;;
  162.             esac
  163.         done < "$2"
  164.         return 1
  165.     else
  166.         return 1
  167.     fi
  168. }
  169.  
  170. # Prints the lines of a command '$2' output which contain the text '$1'.
  171. grepcmd () {
  172.     grepcmd_output=$( eval "$2" )
  173.     printf "$grepcmd_output\n" | while IFS= read -r grepcmd_line
  174.     do
  175.         case "$grepcmd_line" in
  176.         *"$1"*)
  177.             printf '%s\n' "$grepcmd_line"
  178.             ;;
  179.         *)
  180.             ;;
  181.     esac
  182.     done
  183.     return 0
  184. }
  185.  
  186. # Trims the leading and trailing whitespace characters of a line '$1'.
  187. trimmer () {
  188.     trimmer_line="$1"
  189.     trimmer_line="${trimmer_line#"${trimmer_line%%[![:space:]]*}"}"
  190.    trimmer_line="${trimmer_line%"${trimmer_line##*[![:space:]]}"}"
  191.     printf "$trimmer_line\n"
  192.     return 0
  193. }
  194.  
  195. # Replaces the lines containing the text '$2' of a file '$1' with a line '$3'.
  196. sedder () {
  197.     if file_exists "$1" ; then
  198.         csb_sedder_tmp="./.csb_sedder"
  199.         rm -f "$csb_sedder_tmp"
  200.         while IFS= read -r sedder_line
  201.         do
  202.             case "$sedder_line" in
  203.                 *"$2"*)
  204.                     if [ ! -z "$3" ] ; then
  205.                         printf '%s\n' "$3" >> "$csb_sedder_tmp"
  206.                     fi
  207.                     ;;
  208.                 *)
  209.                     printf '%s\n' "$sedder_line" >> "$csb_sedder_tmp"
  210.                     ;;
  211.             esac
  212.         done < "$1"
  213.         mover "$csb_sedder_tmp" "$1"
  214.         return 0
  215.     else
  216.         return 1
  217.     fi
  218. }
  219.  
  220. # Downloads a file '$1' from a link '$2' using the options '$3' and checks if this was successful.
  221. wgetter () {
  222.     rm -f "$1"
  223.     if [ -z "$3" ] ; then
  224.         wget "$2"
  225.     else
  226.         wget "$3" "$2"
  227.     fi
  228.     if [ -f "$1" ] ; then
  229.         wgetter_file_size=$(($( wc -c < "$1" )))
  230.         if [ "$wgetter_file_size" -eq "0" ] ; then
  231.             rm -f "$1"
  232.         fi
  233.     fi
  234.     if [ ! -f "$1" ] ; then
  235.         printf "\n${byellow}WARNING${bend}: can't download a ${bold}$1${bend} file !"
  236.         printf "\n         Please check your Internet connection and try again.\n"
  237.         encontinue
  238.         return 1
  239.     else
  240.         sleep 1
  241.         return 0
  242.     fi
  243. }
  244.  
  245. # Unzips the archive '$1', optional '$2' for -j path inside the archive, and then force removes it.
  246. unzipper () {
  247.     if file_exists "$1" ; then
  248.         if [ -z "$2" ] ; then
  249.             unzip "$1"
  250.         else
  251.             unzip -j "$1" "$2"
  252.         fi
  253.         rm -f "$1"
  254.         return 0
  255.     else
  256.         return 1
  257.     fi
  258. }
  259.  
  260. # Expands a file '$1' with zeroes using a dd to '$2' size - e.g. to a standard floppy size 1474560.
  261. expander () {
  262.     if file_exists "$1" && [ ! -z "$2" ] ; then
  263.         expander_file_size=$(($( wc -c < "$1" )))
  264.         if [ "$expander_file_size" -lt "$2" ] ; then
  265.             dd if=/dev/zero of=$1 bs=1 count=1 seek=$(( $2 - 1 )) conv=notrunc iflag=nocache
  266.         fi
  267.         return 0
  268.     else
  269.         return 1
  270.     fi
  271. }
  272.  
  273. # Compares sha256sum of '$1.img' floppy image with '$2' and creates a hidden '.$1' file if matches.
  274. floppy_verifier () {
  275.     rm -f "./.$1"
  276.     cd "./../"
  277.     if [ ! -z "$2" ] ; then
  278.         if file_exists "./floppies/$1.img" ; then
  279.             floppy_verifier_sha256sum_correct="$2  ./floppies/$1.img"
  280.             floppy_verifier_sha256sum_my=$( sha256sum "./floppies/$1.img" )
  281.             printf "\n=== sha256sum should be:\n${bold}$floppy_verifier_sha256sum_correct${bend}\n"
  282.             if [ "$floppy_verifier_sha256sum_my" = "$floppy_verifier_sha256sum_correct" ] ; then
  283.                 printf "^^^ this is correct, ./floppies/${bold}$1.img${bend} is verified and could be added.\n\n"
  284.                 cd "./floppies/"
  285.                 touch "./.$1"
  286.                 return 0
  287.             else
  288.                 printf "${bold}^^^ ! MISMATCH for ./floppies/$1.img ! Check sha256sum manually: sha256sum ./floppies/$1.img${bend}\n"
  289.                 encontinue
  290.                 cd "./floppies/"
  291.                 return 1
  292.             fi
  293.         else
  294.             printf "\n${byellow}WARNING${bend}: cannot find ./floppies/${bold}$1.img${bend} !\n"
  295.             printf "\n         Please re-download a set of floppies.\n"
  296.             encontinue
  297.             return 1
  298.         fi
  299.     else
  300.         printf "\n${byellow}WARNING${bend}: ./floppies/${bold}$1.img${bend} - is a rolling release, its' SHA256 checksum"
  301.         printf "\n         is changing constantly and not provided by $1 project, so not checked.\n"
  302.         encontinue
  303.         cd "./floppies/"
  304.         touch "./.$1"
  305.         return 0
  306.     fi
  307. }
  308.  
  309. # Downloads a collection of floppies, for the purpose of adding them later to a coreboot ROM image.
  310. floppy_mass_downloader () {
  311.     printf "\n"
  312.     if [ ! -d "./floppies/" ]; then
  313.         mkdir "./floppies/"
  314.     fi
  315.     cd "./floppies/"
  316.     # KOLCRPT
  317.     if wgetter   "./kolibri_r9977_vigenere.zip" "https://board.kolibrios.org/download/file.php?id=10577" "--output-document=kolibri_r9977_vigenere.zip" ; then
  318.         unzipper "./kolibri_r9977_vigenere.zip" "kolibri_r9977_vigenere/kolibri_r9977_vigenere.img"
  319.         mover "./kolibri_r9977_vigenere.img" "./kolcrpt.img"
  320.             floppy_verifier  "kolcrpt" "ed5ef330eaada5fa4ed585859654e4bda3ca3eefd817e891bd0fe3454e47078c"
  321.     fi
  322.     # KOLIBRI
  323.     if command_exists "7za" ; then
  324.         if wgetter "./latest-img.7z" "https://builds.kolibrios.org/eng/latest-img.7z" ; then
  325.             rm -f "./kolibri.img"
  326.             7za x "./latest-img.7z"
  327.             rm -f "./INSTALL.TXT"
  328.             rm -f "./latest-img.7z"
  329.             floppy_verifier  "kolibri" "" # IS A ROLLING RELEASE, NO SHA256 VERIFICATION
  330.         fi
  331.     else
  332.         printf "\n${byellow}WARNING${bend}: cannot get ./floppies/${bold}kolibri.img${bend} without ${bold}7za${bend}\n"
  333.         encontinue
  334.     fi
  335.     # FREEDOS
  336.     printf "\n${byellow}WARNING${bend}: getting ./floppies/${bold}freedos.img${bend} could take a couple of minutes...\n\n"
  337.     if wgetter   "./FD13-FloppyEdition.zip" "https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.3/official/FD13-FloppyEdition.zip" ; then
  338.         unzipper "./FD13-FloppyEdition.zip" "144m/x86BOOT.img"
  339.         mover "./x86BOOT.img" "./freedos.img"
  340.             floppy_verifier  "freedos" "3f7834ea4575ba05d106e4b8f59f886da7bfb1979ee386be2a2deba8df518925"
  341.     fi
  342.     # MICHALOS
  343.     if wgetter "./michalos.img" "https://github.com/mikebdp2/MichalOS/raw/master/build/images/michalos.flp" "--output-document=michalos.img" ; then
  344.             floppy_verifier "michalos" "c784ccfebfa6b191873284a79e8fda5b44e06f2626629b0b96f4841b30c03492"
  345.     fi
  346.     # VISOPSYS
  347.     if wgetter "./visopsys.img" "https://github.com/mikebdp2/visopsys/raw/main/utils/visopsys-2024-01-02-x86-floppy.img" "--output-document=visopsys.img" ; then
  348.             floppy_verifier "visopsys" "8040da380a96feee644191db880fcab44473e1ff42dc18cb4f80029de457a569"
  349.     fi
  350.     # SNOWDROP
  351.     if wgetter "./snowdrop.img" "http://sebastianmihai.com/downloads/snowdrop/snowdrop.img" ; then
  352.             floppy_verifier "snowdrop" "" # IS A ROLLING RELEASE, NO SHA256 VERIFICATION
  353.     fi
  354.     # FIWIX
  355.     if wgetter "./fiwix.img" "https://www.fiwix.org/FiwixOS-3.3-initrd-i386.img" "--output-document=fiwix.img" ; then
  356.             floppy_verifier    "fiwix" "55d4f030ca5a7ceef7a581ee9b777130475cd71dc337885ef717004658ce366a"
  357.     fi
  358.     # MEMTEST86+ x64
  359.     if wgetter "./memtst64.img" "https://github.com/mikebdp2/memtest86plus/raw/main/build64/floppy.img" "--output-document=memtst64.img" ; then
  360.             floppy_verifier "memtst64" "c26b0bcdaaff9e7bbf178af8ac054470b2231af932afb3c26545b079725f7c2d"
  361.     fi
  362.     # MEMTEST86+ x32
  363.     if wgetter "./memtst32.img" "https://github.com/mikebdp2/memtest86plus/raw/main/build32/floppy.img" "--output-document=memtst32.img" ; then
  364.             floppy_verifier "memtst32" "272eab857e9b4cffed2d15c588d59808853de7c4ab50049e5e386f2c69a8d53f"
  365.     fi
  366.     # TATOS
  367.     if wgetter "./tatos.img" "https://github.com/tatimmer/tatOS/raw/master/tatOS.img" "--output-document=tatos.img" ; then
  368.         expander "./tatos.img" "1474560"
  369.             floppy_verifier    "tatos" "2c66f884498a4fe7b469bc213aebfccd84a09fd7ace1b3b4b3e747e2392c35d1"
  370.     fi
  371.     # PLOP
  372.     if wgetter   "./plpbt-5.0.15.zip" "https://download.plop.at/files/bootmngr/plpbt-5.0.15.zip" ; then
  373.         unzipper "./plpbt-5.0.15.zip" "plpbt-5.0.15/plpbt.img"
  374.         mover "./plpbt.img" "./plop.img"
  375.             floppy_verifier     "plop" "f170759966ec4efe60c8531158344a234d7543c8de81e54c8c1bb9d2d69eaf27"
  376.     fi
  377.     # FLOPPYBIRD - IMPROVED FORK
  378.     if wgetter "./flopbird.img" "https://github.com/mikebdp2/floppybird/raw/master/build/img/floppybird.img" "--output-document=flopbird.img" ; then
  379.             floppy_verifier "flopbird" "249f77da69ba5d3295ed0c9180e4ffc646fb24f545630448fd55d5de2aec1455"
  380.     fi
  381.     # Some floppies have the weird permissions after their extraction
  382.     floppy_mass_downloader_floppies=$( find . -name "*.img" )
  383.     if [ ! -z "$floppy_mass_downloader_floppies" ] ; then
  384.         chmod 755 "./"*".img"
  385.     fi
  386.     # Return back to ./coreboot/
  387.     cd "./../"
  388.     return 0
  389. }
  390.  
  391. # Prints the remaining (empty) CBFS space at coreboot '$3' ROM using '$2' cbfstool.
  392. cbfs_emptyspacer () {
  393.     cbfs_emptyspacer_line=$( grepcmd "(empty)" "$2 $3 print" )
  394.     case "$cbfs_emptyspacer_line" in
  395.         *"(empty)"*)
  396.             cbfs_emptyspacer_line=${cbfs_emptyspacer_line#??????????????????????????????????????????????}
  397.             cbfs_emptyspacer_line=${cbfs_emptyspacer_line%????}
  398.             cbfs_emptyspacer_line=$( trimmer "$cbfs_emptyspacer_line" )
  399.             cbfs_emptyspacer_line=$(( $cbfs_emptyspacer_line / 1024 ))
  400.             printf "\n\n${bgreen}NOTE${bend}: your $3 has some (empty) space left: ${byellow}~$cbfs_emptyspacer_line K${bend}\n"
  401.             return 0
  402.             ;;
  403.         *)
  404.             printf "\n\n${byellow}WARNING${bend}: sorry, I can't find out the remaining (empty) space at ${bold}$3${bend}\n"
  405.             return 1
  406.             ;;
  407.    esac
  408. }
  409.  
  410. # Adds a './pci1002,$1.rom' to coreboot '$3' ROM using '$2' cbfstool, printing '$4'/'$5'/'$6' info.
  411. atombios_adder () {
  412.     if file_exists "$2" && file_exists "$3" ; then
  413.         if [ -f "./pci1002,$1.rom" ] ; then
  414.             atombios_adder_cbfs=$( "$2" "$3" print )
  415.             if checker "$atombios_adder_cbfs" "pci1002,$1.rom" ; then
  416.                 printf "\n${bgreen}NOTE${bend}: ./${bold}pci1002,$1.rom${bend} for ${bold}$5 : $6${bend} is already at your $3.\n"
  417.             else
  418.                 cbfs_emptyspacer "$1" "$2" "$3"
  419.                 if yesno "\nAdd a ./${bold}pci1002,$1.rom${bend} for ${bold}$5 : $6${bend} to your $3 now? ${bold}$4${bend}" ", adding..." ; then
  420.                     if "$2" "$3" add -f "./pci1002,$1.rom" -n "pci1002,$1.rom" -t optionrom ; then
  421.                         printf "adding... ${bgreen}SUCCESS${bend}\n"
  422.                     else
  423.                         printf   "adding... ${bred}FAILURE${bend}\n"
  424.                         printf "${bold}NOTE:${bend} to try again, restart your last csb_patcher command to remake ./build/coreflop.rom and choose wisely\n"
  425.                         encontinue
  426.                     fi
  427.                 else
  428.                     printf "\n${bold}You can add it later by running:${bend}"
  429.                     printf "\n${bold}        $2 $3 add -f ./pci1002,$1.rom -n pci1002,$1.rom -t optionrom${bend}\n\n"
  430.                 fi
  431.             fi
  432.             return 0
  433.         else
  434.             printf "\n${byellow}WARNING${bend}: cannot find ./${bold}pci1002,$1.rom${bend} ,"
  435.             printf "\n         please re-apply ${bold}AMD atombios${bend} patch.\n"
  436.             encontinue
  437.             return 1
  438.         fi
  439.     else
  440.         return 1
  441.     fi
  442. }
  443.  
  444. # Adds a '$1.img' floppy image to coreboot '$3' ROM using '$2' cbfstool, printing '$4' size info.
  445. floppy_adder () {
  446.     if file_exists "$2" && file_exists "$3" ; then
  447.         if [ -f "./floppies/$1.img" ] ; then
  448.             if [ -f "./floppies/.$1" ] ; then
  449.                 floppy_adder_cbfs=$( "$2" "$3" print )
  450.                 if checker "$floppy_adder_cbfs" "floppyimg/$1.lzma" ; then
  451.                     printf "\n${bgreen}NOTE${bend}: ./floppies/${bold}$1.img${bend} is already at your $3.\n"
  452.                 else
  453.                     if checker "$1" "plop" ; then
  454.                         printf "\n${byellow}WARNING${bend}: ./floppies/${bold}$1.img${bend} - is proprietary: all its' source code is closed !"
  455.                         printf "\n         Add it only if you really need it and trust the author of $1 project.\n"
  456.                         encontinue
  457.                     fi
  458.                     cbfs_emptyspacer "$1" "$2" "$3"
  459.                     if yesno "\nAdd a ./floppies/${bold}$1.img${bend} to your $3 now? ${bold}$4${bend}" ", adding..." ; then
  460.                         if "$2" "$3" add -f "./floppies/$1.img" -n "floppyimg/$1.lzma" -t raw -c lzma ; then
  461.                             printf "adding... ${bgreen}SUCCESS${bend}\n"
  462.                         else
  463.                             printf   "adding... ${bred}FAILURE${bend}\n"
  464.                             printf "${bold}NOTE:${bend} to try again, restart your last csb_patcher command to remake ./build/coreflop.rom and choose wisely\n"
  465.                             encontinue
  466.                         fi
  467.                     else
  468.                         printf "\n${bold}You can add it later by running:${bend}"
  469.                         printf "\n${bold}        $2 $3 add -f ./floppies/$1.img -n floppyimg/$1.lzma -t raw -c lzma${bend}\n\n"
  470.                     fi
  471.                 fi
  472.                 return 0
  473.             else
  474.                 printf "\n${byellow}WARNING${bend}: there was a SHA256 mismatch for ./floppies/${bold}$1.img${bend} -"
  475.                 printf "\n         check sha256sum manually: sha256sum ./floppies/${bold}$1.img${bend}\n"
  476.                 encontinue
  477.                 return 1
  478.             fi
  479.         else
  480.             printf "\n${byellow}WARNING${bend}: cannot find ./floppies/${bold}$1.img${bend} !\n"
  481.             printf "\n         Please re-download a set of floppies.\n"
  482.             encontinue
  483.             return 1
  484.         fi
  485.     else
  486.         return 1
  487.     fi
  488. }
  489.  
  490. # Adds a set of AtomBIOS/floppies ('$1') to coreboot '$3' ROM copied to '$4', using '$2' cbfstool.
  491. cbfs_mass_adder () {
  492.     if ! grepcheck "how to submit coreboot changes" ./MAINTAINERS ; then
  493.         printf "\n${byellow}WARNING${bend}: not sure if I am inside the coreboot directory,"
  494.         printf "\n         trying to add a ${bold}$1${bend} set from here - could fail.\n\n"
  495.     fi
  496.     if file_exists "$2" && file_exists "$3" ; then
  497.         if checker "$1" "atom" || checker "$1" "flop" ; then
  498.             copier "$3" "$4"
  499.             printf "\n${bold}=== $4 - initial memory map${bend}\n\n"
  500.             "$2" "$4" print
  501.             printf "\n"
  502.             if checker "$1" "atom" ; then
  503. ###
  504. ### https://review.coreboot.org/c/coreboot/+/58748
  505. ### G505S AtomBIOS ROMs: known good binaries with a script to check their SHA256
  506. ###
  507.            csb_patcher "atombios" "58748"  "2" "d3c12c8" "f6a0d71ef0ceef69e74419e0f8c90b4ac9c121d8d283f5605ad6c652cd1ab3d2" "$1" "AMD "
  508.                 atombios_adder "990b" "$2" "$4" "~62 K" "Lenovo G505S with A10-5750M"  "iGPU HD-8650G"
  509.                 atombios_adder "6663" "$2" "$4" "~33 K" "Lenovo G505S with A10-5750M"  "dGPU HD-8570M"
  510.                 atombios_adder "6665" "$2" "$4" "~32 K" "Lenovo G505S with A10-5750M"  "dGPU R5-M230"
  511.                 atombios_adder "9830" "$2" "$4" "~59 K" "ASUS AM1I-A with Athlon-5370" "iGPU HD-8400 / R3-Series"
  512.                 atombios_adder "990c" "$2" "$4" "~62 K" "ASUS A88XM-E with A10-6700"   "iGPU HD-8670D"
  513.             fi
  514.             if checker "$1" "flop" ; then
  515.                 if [ ! -d "./floppies/" ] ; then
  516.                     printf "\n"
  517.                     floppy_mass_downloader
  518.                 fi
  519.                 # Default boot order: the last floppy added - is the first floppy to boot!
  520.                 floppy_adder "flopbird" "$2" "$4"     "  ~3 K"
  521.                 floppy_adder "plop"     "$2" "$4" "     ~75 K"
  522.                 floppy_adder "tatos"    "$2" "$4"  "    ~60 K"
  523.                 floppy_adder "memtst32" "$2" "$4"     " ~60 K"
  524.                 floppy_adder "memtst64" "$2" "$4"     " ~60 K"
  525.                 floppy_adder "fiwix"    "$2" "$4"  "   ~414 K"
  526.                 floppy_adder "snowdrop" "$2" "$4"     "~182 K"
  527.                 floppy_adder "visopsys" "$2" "$4"     "~441 K"
  528.                 floppy_adder "michalos" "$2" "$4"     "~612 K"
  529.                 floppy_adder "freedos"  "$2" "$4"    " ~368 K"
  530.                 floppy_adder "kolibri"  "$2" "$4"    "~1284 K"
  531.                 floppy_adder "kolcrpt"  "$2" "$4"    "~1312 K"
  532.             fi
  533.             printf "\n${bold}=== $4 - final memory map${bend}\n\n"
  534.             "$2" "$4" print
  535.             printf "\nYou can use ./build/${bold}coreflop.rom${bend} now !\n\n"
  536.             return 0
  537.         else
  538.             return 1
  539.         fi
  540.     else
  541.         return 1
  542.     fi
  543. }
  544.  
  545. # Finds the files of '$1' extension, saves the result to '$2' log and prints a message with '$3'.
  546. csb_finder () {
  547.     csb_finder_files=$( find . -name "*.$1" )
  548.     if [ ! -z "$csb_finder_files" ] ; then
  549.         printf "%25s\n" "*.$1 - YES" >> "$2"
  550.         printf "\n${byellow}WARNING${bend}: found ${bold}*.$1${bend} files at these locations :\n"
  551.         printf "$csb_finder_files"
  552.         printf "\n  That means - Some patches $3\n"
  553.         encontinue
  554.         return 0
  555.     else
  556.         printf "%24s\n" "*.$1 - NO" >> "$2"
  557.         return 1
  558.     fi
  559. }
  560.  
  561. # Prints a csb_patcher_log '$1' with a custom highlighting.
  562. csb_printer () {
  563.     if ! file_exists "$1" ; then
  564.         return 1
  565.     fi
  566.     while IFS= read -r csb_printer_line
  567.     do
  568.         case "$csb_printer_line" in
  569.             *"orig - YES"*)
  570.                 printf "${csb_printer_line%???}${byellow}YES" # YELLOW
  571.                 ;;
  572.             *"rej - YES"*)
  573.                 printf "${csb_printer_line%???}${bred}YES" # RED
  574.                 ;;
  575.             *"YES"*)
  576.                 printf "${csb_printer_line%???}${bgreen}YES" # GREEN
  577.                 ;;
  578.             *"orig - NO"*|*"rej - NO"*)
  579.                 printf "${csb_printer_line%??}${bgreen}NO" # GREEN
  580.                 ;;
  581.             *"NO"*)
  582.                 printf "${csb_printer_line%??}${byellow}NO" # YELLOW
  583.                 ;;
  584.             *"FAILURE_1"*)
  585.                 printf "${csb_printer_line%?????????}${bred}FAILURE_1" # RED
  586.                 ;;
  587.             *"FAILURE_2"*)
  588.                 printf "${csb_printer_line%?????????}${bred}FAILURE_2" # RED
  589.                 ;;
  590.             *"FAILURE_3"*)
  591.                 printf "${csb_printer_line%?????????}${bred}FAILURE_3" # RED
  592.                 ;;
  593.             *"\\\\"*)
  594.                printf "${bold}${csb_printer_line%?????}\\\\\!//" # ALIEN HAIR
  595.                ;;
  596.            *)
  597.                printf "${bold}$csb_printer_line"
  598.                ;;
  599.        esac
  600.        printf "${bend}\n"
  601.    done < "$1"
  602.    return 0
  603. }
  604.  
  605. # Configure some popular options of a config file '$1'.
  606. csb_configurer () {
  607.    if file_exists "$1" ; then
  608.        csb_configurer_tmp="./.csb_configurer"
  609.        rm -f "$csb_configurer_tmp"
  610.        # Check if the configuration of this board is supported.
  611.        grepper "CONFIG_BOARD_" "$1" > "$csb_configurer_tmp"
  612.        if grepcheck "_LENOVO_G505S=y" "$csb_configurer_tmp" ; then
  613.            printf "\n\n${bgreen}[CONFIG]${bend} Questions about your Lenovo G505S\n\n"
  614.        else
  615.            if grepcheck "_ASUS_AM1I_A=y" "$csb_configurer_tmp" ; then
  616.                printf "\n\n${bgreen}[CONFIG]${bend} Questions about your ASUS AM1I-A\n\n"
  617.            else
  618.                if grepcheck "_ASUS_A88XM_E=y" "$csb_configurer_tmp" ; then
  619.                    printf "\n\n${bgreen}[CONFIG]${bend} Questions about your ASUS A88XM-E\n\n"
  620.                else
  621.                    printf "\n\n${byellow}WARNING${bend}: sorry, I don't know how to configure a board of ${bold}$1${bend}\n"
  622.                    encontinue
  623.                    return 1
  624.                fi
  625.            fi
  626.        fi
  627.        # Common part both for LENOVO G505S and ASUS AM1I-A / A88XM-E.
  628.        sedder "$1" "### CSB_CONFIGURER OPTIONS" ""
  629.        printf "### CSB_CONFIGURER OPTIONS\n" >> "$1"
  630.        sedder "$1" "# CONFIG_DRIVERS_INTEL_WIFI is not set" ""
  631.        sedder "$1" "CONFIG_DRIVERS_INTEL_WIFI=y" ""
  632.        if yesno "Do you have an Intel WiFi adapter?" "" ; then
  633.            printf "CONFIG_DRIVERS_INTEL_WIFI=y\n" >> "$1"
  634.        else
  635.            printf "# CONFIG_DRIVERS_INTEL_WIFI is not set\n" >> "$1"
  636.        fi
  637.        # This part is only for LENOVO G505S.
  638.        if grepcheck "_LENOVO_G505S=y" "$csb_configurer_tmp" ; then
  639.            sedder "$1" "# CONFIG_AMD_DGPU_WITHOUT_EEPROM is not set" ""
  640.            sedder "$1" "CONFIG_AMD_DGPU_WITHOUT_EEPROM=y" ""
  641.            sedder "$1" "# CONFIG_VGA_BIOS_DGPU is not set" ""
  642.            sedder "$1" "CONFIG_VGA_BIOS_DGPU=y" ""
  643.            sedder "$1" "CONFIG_VGA_BIOS_DGPU_FILE=\"pci1002,6663.rom\"" ""
  644.            sedder "$1" "CONFIG_VGA_BIOS_DGPU_ID=\"1002,6663\"" ""
  645.            sedder "$1" "CONFIG_VGA_BIOS_DGPU_FILE=\"pci1002,6665.rom\"" ""
  646.            sedder "$1" "CONFIG_VGA_BIOS_DGPU_ID=\"1002,6665\"" ""
  647.            if yesno "Do you have a Discrete GPU?" "" ; then
  648.                printf "CONFIG_AMD_DGPU_WITHOUT_EEPROM=y\n" >> "$1"
  649.                printf "CONFIG_VGA_BIOS_DGPU=y\n"         >> "$1"
  650.                if yesno "No for HD-8570M, Yes for R5-M230" "" ; then
  651.                    printf "CONFIG_VGA_BIOS_DGPU_FILE=\"pci1002,6665.rom\"\n" >> "$1"
  652.                    printf "CONFIG_VGA_BIOS_DGPU_ID=\"1002,6665\"\n"          >> "$1"
  653.                else
  654.                    printf "CONFIG_VGA_BIOS_DGPU_FILE=\"pci1002,6663.rom\"\n" >> "$1"
  655.                    printf "CONFIG_VGA_BIOS_DGPU_ID=\"1002,6663\"\n"          >> "$1"
  656.                fi
  657.            else
  658.                printf "# CONFIG_AMD_DGPU_WITHOUT_EEPROM is not set\n" >> "$1"
  659.                printf "# CONFIG_VGA_BIOS_DGPU is not set\n"         >> "$1"
  660.            fi
  661.        fi
  662.        # Common part both for LENOVO G505S and ASUS AM1I-A / A88XM-E.
  663.        # HUDSON_SATA_MODE=0
  664.        sedder "$1" "# NATIVE" ""
  665.        sedder "$1" "CONFIG_HUDSON_SATA_MODE=0" ""
  666.        # HUDSON_SATA_MODE=1
  667.        sedder "$1" "# RAID" ""
  668.        sedder "$1" "CONFIG_HUDSON_SATA_MODE=1" ""
  669.        sedder "$1" "CONFIG_RAID_ROM_ID=\"1022,7802\"" ""
  670.        sedder "$1" "CONFIG_RAID_ROM_FILE=\"src/southbridge/amd/agesa/hudson/raid.bin\"" ""
  671.        sedder "$1" "CONFIG_RAID_MISC_ROM_FILE=\"src/southbridge/amd/agesa/hudson/misc.bin\"" ""
  672.        sedder "$1" "CONFIG_RAID_MISC_ROM_POSITION=0xFFF00000" ""
  673.        # HUDSON_SATA_MODE=2
  674.        sedder "$1" "# AHCI" ""
  675.        sedder "$1" "CONFIG_HUDSON_SATA_MODE=2" ""
  676.        sedder "$1" "CONFIG_AHCI_ROM_ID=\"1022,7801\"" ""
  677.        sedder "$1" "# CONFIG_HUDSON_AHCI_ROM is not set" ""
  678.        # HUDSON_SATA_MODE=3
  679.        sedder "$1" "# LEGACY IDE" ""
  680.        sedder "$1" "CONFIG_HUDSON_SATA_MODE=3" ""
  681.        # HUDSON_SATA_MODE=4
  682.        sedder "$1" "# IDE to AHCI" ""
  683.        sedder "$1" "CONFIG_HUDSON_SATA_MODE=4" ""
  684.        # HUDSON_SATA_MODE=5
  685.        sedder "$1" "# AHCI7804" ""
  686.        sedder "$1" "CONFIG_HUDSON_SATA_MODE=5" ""
  687.        sedder "$1" "CONFIG_AHCI_ROM_ID=\"1022,7804\"" ""
  688.        # HUDSON_SATA_MODE=6
  689.        sedder "$1" "# IDE to AHCI7804" ""
  690.        sedder "$1" "CONFIG_HUDSON_SATA_MODE=6" ""
  691.        sedder "$1" "# CONFIG_HUDSON_AHCI_ROM is not set" ""
  692.        # HUDSON_SATA_MODE SETUP
  693.        if yesno "Do you have a SSD? (enable AHCI if Y)" "" ; then
  694.            printf "# AHCI\n" >> "$1"
  695.            printf "CONFIG_HUDSON_SATA_MODE=2\n" >> "$1"
  696.            printf "CONFIG_AHCI_ROM_ID=\"1022,7801\"\n" >> "$1"
  697.            printf "# CONFIG_HUDSON_AHCI_ROM is not set\n" >> "$1"
  698.        else
  699.            printf "# NATIVE\n" >> "$1"
  700.            printf "CONFIG_HUDSON_SATA_MODE=0\n" >> "$1"
  701.        fi
  702.        # Board has been configured.
  703.        printf "\n"
  704.        rm -f "$csb_configurer_tmp"
  705.        return 0
  706.    else
  707.        return 1
  708.    fi
  709. }
  710.  
  711. #
  712. # Conveniently and securely gets, checks SHA256 and installs a patch.
  713. # Arguments are the patch properties:
  714. #     $1 - new diff name, could be also a part of extracted scripts' filename
  715. #     $2 - change ID number,       part of download link to review.coreboot.org
  716. #     $3 - change revision number, part of download link to review.coreboot.org
  717. #     $4 - diff filename inside the downloaded archive, will be renamed to $1
  718. #     $5 - diff known good SHA256 checksum, will be used for SHA256 verification
  719. #     $6 - filepath where to save a csb_patcher_log which will be printed later
  720. #     $7 - info about the target of a patch, if not specified ("") it is common
  721. #
  722. csb_patcher () {
  723.     if ! wgetter "./patch?zip" "https://review.coreboot.org/changes/$2/revisions/$3/patch?zip" ; then
  724.         printf "${bold}^^^ ! Can't download a $7$1 patch ! Check your Internet.${bend}\n"
  725.         printf "%31s\n" "$7$1 - FAILURE_1" >> "$6"
  726.         csb_printer "$6"
  727.         exit 1
  728.     fi
  729.     unzipper "./patch?zip"
  730.     mover "./$4.diff" "./$1.diff"
  731.     csb_patcher_sha256sum_correct="$5  ./$1.diff"
  732.     csb_patcher_sha256sum_my=$( sha256sum "./$1.diff" )
  733.     printf "\n=== sha256sum should be:\n${bold}$csb_patcher_sha256sum_correct${bend}\n"
  734.     if [ "$csb_patcher_sha256sum_my" = "$csb_patcher_sha256sum_correct" ] ; then
  735.         printf "^^^ this is correct, "
  736.         csb_patcher_patch_title=$( grepper "Subject" "./$1.diff" )
  737.         csb_patcher_patch_title=${csb_patcher_patch_title#?????????????????}
  738.         if [ "$1" = "dgpu" ] || [ "$1" = "irq" ] || [ "$1" = "cfgsb" ] ; then
  739.             printf "will extract a ${bold}$7$1${bend} patch now...\n"
  740.             rm -f "./sha256sums_$1_correct.txt"
  741.             rm -f "./"*"_$1_patches.sh"
  742.             patch -p1 < "./$1.diff"
  743.             chmod +x "./"*"_$1_patches.sh"
  744.             "./get_$1_patches.sh"
  745.             if ! "./check_$1_patches.sh" ; then
  746.                 printf "%31s\n" "$7$1 - FAILURE_3" >> "$6"
  747.                 csb_printer "$6"
  748.                 exit 1
  749.             fi
  750.         else
  751.             printf "${bold}$7$1${bend} patch could be applied now...\n"
  752.         fi
  753.         if [ "$1" = "dgpu" ] || [ "$1" = "atombios" ] || [ "$1" = "irq" ] || \
  754.            [ "$1" = "amdfw" ] || [ "$1" = "seabios" ] || [ "$1" = "cfgsb" ] ; then
  755.             printf "\n\n${bgreen}[PATCH]${bend} $csb_patcher_patch_title\n\n"
  756.             if ! grepcheck "how to submit coreboot changes" ./MAINTAINERS ; then
  757.                 printf "\n${byellow}WARNING${bend}: not sure if I am inside the coreboot directory,"
  758.                 printf "\n         trying to add a ${bold}$1${bend} set from here - could fail.\n\n"
  759.             fi
  760.             if [ -f "./.$1" ] ; then
  761.                 printf "\n${byellow}WARNING${bend}: found a '.$1' hidden file at the current directory,"
  762.                 printf "\n         maybe you have applied this patch already.\n\n"
  763.             fi
  764.             if yesno "Apply a ${bold}$7$1${bend} patch now?" "" ; then
  765.                 if [ "$1" = "dgpu" ] || [ "$1" = "irq" ] || [ "$1" = "cfgsb" ] ; then
  766.                     "./apply_$1_patches.sh"
  767.                 else
  768.                     if [ "$1" = "atombios" ] ; then
  769.                         rm -f "./sha256sums_$1_correct.txt"
  770.                         rm -f "./"*"_$1_roms.sh"
  771.                         rm -f "./pci1002\,"*".rom"
  772.                         rm -f "./pci1002\,"*".rom.txt"
  773.                     fi
  774.                     if [ "$1" = "seabios" ] ; then
  775.                         rm -f "./payloads/external/SeaBIOS/"*".patch"
  776.                     fi
  777.                     patch -p1 < "./$1.diff"
  778.                     if [ "$1" = "atombios" ] ; then
  779.                         chmod +x "./"*"_$1_roms.sh"
  780.                         "./extract_$1_roms.sh"
  781.                         printf "\n"
  782.                         if ! "./check_$1_roms.sh" ; then
  783.                             printf "%31s\n" "$7$1 - FAILURE_3" >> "$6"
  784.                             csb_printer "$6"
  785.                             exit 1
  786.                         fi
  787.                     fi
  788.                 fi
  789.                 touch ".$1"
  790.                 printf "%25s\n" "$7$1 - YES" >> "$6"
  791.                 if [ "$1" = "atombios" ] ; then
  792.                     encontinue
  793.                 fi
  794.             else
  795.                 printf "%24s\n" "$7$1 - NO" >> "$6"
  796.                 printf "\n${bold}You can apply it later by running:${bend}"
  797.                 if [ "$1" = "dgpu" ] || [ "$1" = "irq" ] || [ "$1" = "cfgsb" ]; then
  798.                     printf "\n${bold}        ./apply_$1_patches.sh${bend}\n"
  799.                 else
  800.                     printf "\n${bold}        patch -p1 < ./$1.diff${bend}\n"
  801.                 fi
  802.                 encontinue
  803.             fi
  804.         fi
  805.         if checker "$1" "config" ; then
  806.             rm -f "./configs/$1"*
  807.             patch -p1 < "./$1.diff"
  808.             printf "\n\n${bgreen}[PATCH]${bend} $csb_patcher_patch_title\n\n"
  809.             ls "./configs" > "./.csb_configs"
  810.             csb_patcher_config_name=$( grepper "$1" "./.csb_configs" )
  811.             rm -f "./.csb_configs"
  812.             printf "\n${bold}$csb_patcher_config_name could now be found at ./configs/${bend}"
  813.             printf "\n${bold}To use it, it should be copied to '.config' of your ./coreboot directory.${bend}\n\n"
  814.             if [ -f "./.config" ] ; then
  815.                 printf "\n${byellow}WARNING${bend}: copying it to ./.config will overwrite your current '.config'\n\n"
  816.             fi
  817.             if yesno "Copy it to ./.config now?" "" ; then
  818.                 copier "./configs/$csb_patcher_config_name" "./.config"
  819.                 printf "\n"
  820.                 printf "%25s\n" "$7$1 - YES" >> "$6"
  821.                 if yesno "Configure this ./.config now?" "" ; then
  822.                     csb_configurer "./.config"
  823.                 else
  824.                     printf "\n${bold}You can configure it later by running:${bend}"
  825.                     printf "\n${bold}        ./csb_patcher.sh config${bend}\n\n"
  826.                 fi
  827.             else
  828.                 printf "%24s\n" "$7$1 - NO" >> "$6"
  829.                 printf "\n${bold}You can copy it later by running:${bend}"
  830.                 printf "\n${bold}        cp ./configs/$csb_patcher_config_name ./.config${bend}\n"
  831.             fi
  832.             printf "\n${byellow}WARNING${bend}: important README at the beginning of ./$1.diff\n"
  833.             encontinue
  834.         fi
  835.         printf "\n\n"
  836.         return 0
  837.     else
  838.         printf "${bold}^^^ ! MISMATCH for a $7$1 patch ! Check sha256sum manually: sha256sum ./$1.diff${bend}\n"
  839.         printf "%31s\n" "$7$1 - FAILURE_2" >> "$6"
  840.         csb_printer "$6"
  841.         exit 1
  842.     fi
  843. }
  844.  
  845. # Prints the currently-known errata: what you might need to do to ensure a stable coreboot build.
  846. csb_errata () {
  847.     printf "\n${byellow}WARNING${bend}: to restore AMD AGESA boards, downgrade a coreboot to revision"
  848.     printf "\n         mentioned in ${bold}restore_agesa.sh${bend} with ${bold}git reset --hard REVISION${bend}"
  849.     printf "\n         and then run ${bold}restore_agesa.sh${bend} before launching ${bold}csb_patcher.sh${bend}\n\n"
  850.     if yesno "This should be manually done before patching. ${bold}Continue patching?${bend}" "" ; then
  851.         return 0
  852.     else
  853.         exit 1
  854.     fi
  855. }
  856.  
  857. #
  858. # Conveniently and securely gets, checks SHA256 and applies my collection of unofficial patches.
  859. #     $1 - filepath where to save a csb_patcher_log which will be printed later
  860. #
  861. csb_mass_patcher () {
  862. ###
  863. ### https://review.coreboot.org/c/coreboot/+/58745
  864. ### G505S dGPU support: scripts for applying the unofficial (not-merged-yet) patches
  865. ###
  866.                csb_patcher "dgpu" "58745"  "6" "2b15173" "6ca5173052ec2fcd1da41f496c476ffa690df887d7853a8a3881cb9634177db7" "$1" "G505S "
  867. ###
  868. ### https://review.coreboot.org/c/coreboot/+/58748
  869. ### G505S AtomBIOS ROMs: known good binaries with a script to check their SHA256
  870. ###
  871.            csb_patcher "atombios" "58748"  "5" "ec16106" "25fb1d06e19c17f1d9addc2f8910f96920551601f2a4d3084419517ef7423329" "$1" "AMD "
  872. ###
  873. ### https://review.coreboot.org/c/coreboot/+/48427
  874. ### AMD good IRQs: scripts for applying the unofficial (not-merged-yet) patches
  875. ###
  876.                 csb_patcher "irq" "48427" "18" "039f67d" "1d917a56646fff22b1cad5eda9f2b1d3fb3e0c59054aabf4c505379632ad2334" "$1" "AMD good "
  877. ###
  878. ### https://review.coreboot.org/c/coreboot/+/79774
  879. ### src/southbridge/amd/agesa/hudson: avoid the apu/amdfw wasting CBFS space
  880. ###
  881.               csb_patcher "amdfw" "79774"  "1" "9ded40d" "c99efcddb22270f7cd573451f721067ed8a48759e2f5e9b946aaedc6f621eeaa" "$1" "stop-waster "
  882. ###
  883. ### https://review.coreboot.org/c/coreboot/+/32351
  884. ### SeaBIOS patches: advanced_bootmenu, multiple_floppies, smbios_mptable_768
  885. ###
  886.             csb_patcher "seabios" "32351" "18" "5f5eac5" "ef6a13b9253013682b93fab2ccdd6c68898cb8cf56d79ee5d2c766571982ef9b" "$1" ""
  887. ###
  888. ### https://review.coreboot.org/c/coreboot/+/44638
  889. ### Disable SeaBIOS options unsupported by hardware: scripts to apply the patches
  890. ###
  891.               csb_patcher "cfgsb" "44638"  "4" "caa6f79" "3180d82194d044e75b0e013083a162f164ab2e7f7c6e5852cf78baea67741820" "$1" "for-configs "
  892. ###
  893. ### https://review.coreboot.org/c/coreboot/+/79839
  894. ### configs: add Lenovo G505S sample configuration (use with dGPU patches)
  895. ###
  896. csb_patcher "config.lenovo_g505s" "79839"  "3" "44501eb" "47cfa5b6d62c490416890fa4e9fadf681dff9b3fed00cf3f1209a0ae48ef381b" "$1" ""
  897. ###
  898. ### https://review.coreboot.org/c/coreboot/+/79840
  899. ### configs: add ASUS AM1I-A sample configuration
  900. ###
  901.  csb_patcher "config.asus_am1i-a" "79840"  "4" "1114f50" "97a51f3c9093b119074ab905b853873e5cc39f0d7555b2ea4f178dd28d2d577e" "$1" ""
  902. ###
  903. ### https://review.coreboot.org/c/coreboot/+/79841
  904. ### configs: add ASUS A88XM-E sample configuration
  905. ###
  906. csb_patcher "config.asus_a88xm-e" "79841"  "3" "a0c7116" "89410ad5ee2a0f12494f2da42d1bd6f4158a3a84a6897a373107632238eb8cb5" "$1" ""
  907.  
  908.     return 0
  909. }
  910.  
  911. # Prints a usage info for this ./csb_patcher.sh script.
  912. csb_usage () {
  913.     printf "${bold}===============${bend} ${bgreen}USAGE${bend} ${bold}================${bend}\n\n"
  914.     printf "${bold}./csb_patcher.sh${bend}\n"
  915.     printf "  patch your coreboot source code\n\n"
  916.     printf "${bold}./csb_patcher.sh${bend} ${byellow}help${bend} ${bold}|${bend} ${byellow}usage${bend}\n"
  917.     printf "  print this usage info\n\n"
  918.     printf "${bold}==================== Before building :${bend}\n\n"
  919.     printf "${bold}./csb_patcher.sh ${byellow}config${bend}\n"
  920.     printf "  configure some popular options\n\n"
  921.     printf "${bold}==================== After building :${bend}\n\n"
  922.     printf "${bold}./csb_patcher.sh ${byellow}atom${bend}\n"
  923.     printf "  add the AtomBIOS ---> coreflop.rom\n\n"
  924.     printf "${bold}./csb_patcher.sh ${byellow}flop${bend}\n"
  925.     printf "  add the floppies ---> coreflop.rom\n\n"
  926.     printf "${bold}./csb_patcher.sh ${byellow}atomflop${bend}\n"
  927.     printf "  both AtomBIOS VGA ROMs and floppies\n\n"
  928.     printf "${bold}./csb_patcher.sh${bend} ${byellow}print${bend}\n"
  929.     printf "     print a ./.csb_patcher log\n\n"
  930.     return 0
  931. }
  932.  
  933. #
  934. # MAIN PART OF A CSB_PATCHER SCRIPT
  935. #
  936. if [ -z "$1" ] ; then
  937.     csb_patcher_log="./.csb_patcher"
  938.     rm -f "$csb_patcher_log"
  939.     if ! command_exists "wget" || \
  940.        ! command_exists "unzip" || \
  941.        ! command_exists "sha256sum" || \
  942.        ! command_exists "patch" || \
  943.        ! command_exists "xxd" ; then
  944.         exit 1
  945.     fi
  946.     printf '\n\n'                                       >> "$csb_patcher_log"
  947.     printf '                \\\\!//\n'                  >> "$csb_patcher_log"
  948.     printf '                (o o)\n'                    >> "$csb_patcher_log"
  949.     printf '            oOOo-(_)-oOOo\n'                >> "$csb_patcher_log"
  950.     printf 'Hi! I am coreboot and SeaBIOS patcher\n'    >> "$csb_patcher_log"
  951.     printf 'Please send your feedback to\n'             >> "$csb_patcher_log"
  952.     printf '      Mike Banon <mikebdp2@gmail.com>\n'    >> "$csb_patcher_log"
  953.     csb_printer "$csb_patcher_log"
  954.     encontinue
  955.  
  956.     csb_errata
  957.     printf '\n=== CSB_PATCHER LOG. Patches applied?\n'  >> "$csb_patcher_log"
  958.  
  959.     csb_mass_patcher "$csb_patcher_log"
  960.  
  961.     if yesno "Download a ${bold}floppies${bend} collection?" "" ; then
  962.         floppy_mass_downloader
  963.                       printf "%25s\n" "floppies - YES"  >> "$csb_patcher_log"
  964.     else
  965.         printf "\n"
  966.                       printf "%24s\n" "floppies - NO"   >> "$csb_patcher_log"
  967.     fi
  968.  
  969.     printf '==================== Bad files found?\n'    >> "$csb_patcher_log"
  970.     csb_finder "orig" "$csb_patcher_log" "applied correctly although at slightly different lines, can ignore it."
  971.      csb_finder "rej" "$csb_patcher_log" "perhaps failed to apply, could result in a broken build! ${bred}Please report${bend}"
  972.  
  973.     printf '\n'                                         >> "$csb_patcher_log"
  974.     csb_printer "$csb_patcher_log"
  975.     csb_usage
  976. else
  977.     case "$1" in
  978.         *"print"*)
  979.             csb_patcher_log="./.csb_patcher"
  980.             csb_printer "$csb_patcher_log"
  981.             ;;
  982.         *"config"*)
  983.             csb_configurer "./.config"
  984.             ;;
  985.         *"atom"*|*"flop"*)
  986.             if ! command_exists "wget" || \
  987.                ! command_exists "unzip" || \
  988.                ! command_exists "sha256sum" || \
  989.                ! command_exists "patch" || \
  990.                ! command_exists "xxd" ; then
  991.                 exit 1
  992.             fi
  993.             cbfs_mass_adder "$1" "./build/cbfstool" "./build/coreboot.rom" "./build/coreflop.rom"
  994.             ;;
  995.         *"help"*|*"usage"*)
  996.             printf "\n"
  997.             csb_usage
  998.             ;;
  999.         *)
  1000.             printf "\n${bred}ERROR${bend}: unknown argument ${bold}$1${bend} !\n\n"
  1001.             csb_usage
  1002.             exit 1
  1003.             ;;
  1004.     esac
  1005. fi
  1006. exit 0
  1007. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement