Guest User

csb_patcher.sh - 17th Sep 2020

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