build.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/bin/bash
  2. usage() {
  3. echo "Usage : ./build.sh <distro> <options>"
  4. echo "# Distros compatible :"
  5. echo "Arch-based/ManJaro-based : arch"
  6. echo "Debian-based/Ubuntu-based : debian"
  7. echo "Fedora-based/RedHat-based/CentOS-based : fedora"
  8. echo "# Options available :"
  9. echo "Save logs (useful for reporting) : log"
  10. echo "Do not use 'clear' : noclr"
  11. }
  12. if [ "$1" == "arch" ]; then
  13. distro="arch"
  14. elif [ "$1" == "debian" ]; then
  15. distro="debian"
  16. elif [ "$1" == "fedora" ]; then
  17. distro="fedora"
  18. elif [ "$1" == "help" ]; then
  19. usage
  20. elif [ "$1" != "arch" ]; then
  21. usage
  22. echo "SCRIPT NEEDS ARGUMENTS"
  23. exit 1
  24. elif [ $1 != "debian" ]; then
  25. usage
  26. echo "SCRIPT NEEDS ARGUMENTS"
  27. exit 1
  28. elif [ $1 != "fedora" ]; then
  29. usage
  30. echo "SCRIPT NEEDS ARGUMENTS"
  31. exit 1
  32. elif [ "$2" == "log" ]; then
  33. log="true"
  34. mkdir LOGS
  35. echo "Logs enabled ! Logs are available in the 'LOGS/' directory"
  36. elif [ "$2" == "noclr" ]; then
  37. alias clear="echo"
  38. fi
  39. error() {
  40. echo "FATAL ERROR, PLEASE REPORT : $1" && exit 1
  41. }
  42. welcome() {
  43. echo "Welcome to "
  44. echo "This coreboot fork adding features not available upstream, to the MacBook!"
  45. sleep 2
  46. }
  47. dependencies() {
  48. clear
  49. echo "Before we start, we need to download dependencies for coreboot ..."
  50. sleep 1
  51. if [ "$log" == "true" ]; then
  52. if [ "$distro" == "arch" ]; then
  53. sudo pacman --sync --needed --noconfirm base-devel curl git gcc-ada ncurses zlib > LOGS/Dependencies.log
  54. elif [ "$distro" == "debian" ]; then
  55. sudo apt-get install -y bison build-essential curl flex git gnat libncurses5-dev m4 zlib1g-dev > LOGS/Dependencies.log
  56. else
  57. sudo dnf install git make gcc-gnat flex bison xz bzip2 gcc g++ ncurses-devel wget zlib-devel > LOGS/Dependencies.log
  58. fi
  59. else
  60. if [ "$distro" == "arch" ]; then
  61. sudo pacman --sync --needed --noconfirm base-devel curl git gcc-ada ncurses zlib
  62. elif [ "$distro" == "debian" ]; then
  63. sudo apt-get install -y bison build-essential curl flex git gnat libncurses5-dev m4 zlib1g-dev
  64. else
  65. sudo dnf install git make gcc-gnat flex bison xz bzip2 gcc g++ ncurses-devel wget zlib-devel
  66. fi
  67. fi
  68. if [ "$?" != 1 ]; then
  69. echo "done!"
  70. else
  71. error "Failed to install dependencies !"
  72. fi
  73. sleep 1
  74. }
  75. toolchain() {
  76. clear
  77. echo "Now, let's build the coreboot toolchain ... This is gonna take a while ..."
  78. sleep 1
  79. if [ $log == "true" ]; then
  80. make crossgcc-i386 CPUS="$(nproc)" > LOGS/Toolchain.log
  81. else
  82. make crossgcc-i386 CPUS="$(nproc)"
  83. fi
  84. if [ "$?" != 1 ]; then
  85. echo "done!"
  86. else
  87. error "Failed to build toolchain !"
  88. fi
  89. sleep 1
  90. }
  91. configure() {
  92. clear
  93. echo "Now, let's configure coreboot !"
  94. echo "Before doing your own configuration, please, at least do the following :"
  95. echo "-----------------------"
  96. echo "Mainboard --->"
  97. echo " Mainboard vendor --->"
  98. echo " Apple"
  99. echo " Mainboard model --->"
  100. echo " MacBook1,1 or MacBook2,1 (choose the right one, should work with both but is only tested on MacBook2,1)"
  101. echo "Devices --->"
  102. echo " [*] Use native graphics initialization"
  103. echo "Payload --->"
  104. echo " Add a payload -->"
  105. echo " SeaBIOS or GRUB (only tested with SeaBIOS)"
  106. echo "Chipset --->"
  107. echo " *** CPU ***"
  108. echo " Include CPU microcode in CBFS --->"
  109. echo " Do not include microcode updates"
  110. echo "-----------------------"
  111. sleep 10
  112. echo "Starting menuconfig ..."
  113. make menuconfig
  114. if [ $? != 1 ]; then
  115. echo "done!"
  116. else
  117. error "Failed to configure coreboot !"
  118. fi
  119. }
  120. build() {
  121. clear
  122. echo "Now, everything is ready, now, let's build the actual rom !"
  123. sleep 1
  124. if [ "$log" == "true" ]; then
  125. make > LOGS/Build.log
  126. else
  127. make
  128. fi
  129. if [ "$?" != 1 ]; then
  130. echo "done!"
  131. else
  132. error "Failed to compile coreboot !"
  133. fi
  134. }
  135. finish() {
  136. echo "Your coreboot rom is now ready ! Enjoy your new firmware !"
  137. echo "Exiting ..."
  138. exit 0
  139. }
  140. # RUN ALL OF THIS
  141. welcome
  142. dependencies
  143. toolchain
  144. configure
  145. build
  146. finish