Advertisement
Guest User

csb_patcher.sh public FINAL STABLE release - 15th July 2019

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