mkuimage.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #!/bin/bash
  2. # Create U-Boot image and Chrome image script.
  3. # Copyright (C) 2015 Márcio Alexandre Silva Delgado <coadde@parabola.nu>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. # Set default dirs and files variables
  18. _prefix='/'
  19. _bindir="${_prefix}/usr/bin"
  20. _bootdir="${_prefix}/boot"
  21. _dtbdir='dtbs'
  22. _pimgfile='preImage'
  23. _uimgfile='uImage'
  24. _lcuimgfile='vmlinux.kpart'
  25. _uboot_litsfile='kernel.its'
  26. _uboot_luimgfile='vmlinux.uimg'
  27. _cmdlinefile='cmdline.txt'
  28. _vboot_keyblk='kernel.keyblock'
  29. _vboot_signprv='kernel_data_key.vbprivk'
  30. _empty_blfile='bootloader.bin'
  31. # Check if exist executable files to use this script
  32. if [ ! -f "${_bindir}/cat" ]; then
  33. # coreutils:
  34. echo "!!! Error: cat not found !!!" && exit 1
  35. elif [ ! -f "${_bindir}/dd" ]; then
  36. # coreutils:
  37. echo "!!! Error: dd not found !!!" && exit 1
  38. elif [ ! -f "${_bindir}/install" ]; then
  39. # coreutils:
  40. echo "!!! Error: install not found !!!" && exit 1
  41. elif [ ! -f "${_bindir}/grub-install" ]; then
  42. # grub:
  43. echo "!!! Error: grub-install not found !!!" && exit 1
  44. elif [ ! -f "${_bindir}/mkimage" ]; then
  45. # uboot-tools:
  46. echo "!!! Error: mkimage not found !!!" && exit 1
  47. elif [ ! -f "${_bindir}/vbutil_kernel" ]; then
  48. # vboot-utils:
  49. echo "!!! Error: vbutil_kernel not found !!!" && exit 1
  50. fi
  51. # Set printed variables
  52. _kernel="${1}"
  53. _board="${2}"
  54. # Set default address
  55. _address='0x00008000'
  56. # Set '_arch' variable
  57. if [ "$(uname -m)" = armv7l ]; then
  58. _arch='arm'
  59. else
  60. _arch="$(uname -m)"
  61. fi
  62. # Set '_kernelname' and '_kerneltype' variables
  63. if [ ${_kernel/linux-libre*/linux-libre} = linux-libre ]; then
  64. _kernelname="${_kernel/linux/vmlinuz}"
  65. _kerneltype="${_kernel/linux*/linux}"
  66. else
  67. _kernelname="${_kernel}"
  68. _kerneltype="${_kernel}"
  69. fi
  70. _mkuimage() {
  71. cat "${_bootdir}/${_kernelname}" "${_bootdir}/${_dtbdir}/${_kernel}/${_dtb}.dtb" "${_pimgfile}.img"
  72. mkimage -A "${_arch}" -O "${_kerneltype}" -T kernel -C none -a "${_loadaddress}" -e "${_entrypoint}" -n "${_board}" -d "${_pimgfile}.img" "${_bootdir}/${_uimgfile}-${_kernel}"
  73. _mkuimage-rmtmp
  74. }
  75. _mkuimage-gnu+linux-chromebook() {
  76. mkimage -D "-I dts -O dtb -p 2048" -f "${_uboot_litsfile}" "${_uboot_luimgfile}"
  77. dd if='/dev/zero' of="${_empty_blfile}" bs=512 count=1
  78. cat 'console=tty0 init=/usr/bin/init root=PARTUUID=%U/PARTNROFF=1 rootwait rw noinitrd' > "${_cmdlinefile}"
  79. # Note: "${_vboot_keyblk}" and "${_vboot_signprv}" is generated by vboot-utils
  80. vbutil_kernel --pack "${_bootdir}/${_lcuimgfile}" --version 1 --vmlinuz "${_uboot_luimgfile}" --arch "${_arch}" --keyblock "${_vboot_keyblk}" --signprivate "${_vboot_signprv}" --config "${_cmdlinefile}" --bootloader "${_empty_blfile}"
  81. _mkuimage-rmtmp
  82. }
  83. _mkuimage-grub() {
  84. grub-install
  85. install -vDm 0644 "${_bootdir}/grub/arm-uboot/core.img" "${_bootdir}/${_uimgfile}-${_kernel}"
  86. exit 0
  87. }
  88. _mkuimage-grub-chromebook() {
  89. grub-install
  90. dd if='/dev/zero' of="${_empty_blfile}" bs=512 count=1
  91. cat 'console=tty0 init=/usr/bin/init root=PARTUUID=%U/PARTNROFF=1 rootwait rw noinitrd' > "${_cmdlinefile}"
  92. # Note: "${_vboot_keyblk}" and "${_vboot_signprv}" is generated by vboot-utils
  93. vbutil_kernel --pack "${_bootdir}/${_lcuimgfile}" --version 1 --vmlinuz "${_uboot_luimgfile}" --arch "${_arch}" --keyblock "${_vboot_keyblk}" --signprivate "${_vboot_signprv}" --config "${_cmdlinefile}" --bootloader "${_empty_blfile}"
  94. _mkuimage-rmtmp
  95. }
  96. _mkuimage-rmtmp() {
  97. if [ -f "${_pimgfile}.img" ]; then
  98. rm -v "${_pimgfile}.img"
  99. fi
  100. if [ -f "${_uboot_litsfile}" ]; then
  101. rm -v "${_uboot_litsfile}"
  102. fi
  103. if [ -f "${_uboot_luimgfile}" ]; then
  104. rm -v "${_uboot_luimgfile}"
  105. fi
  106. if [ -f "${_cmdlinefile}" ]; then
  107. rm -v "${_cmdlinefile}"
  108. fi
  109. if [ -f "${_empty_blfile}" ]; then
  110. rm -v "${_empty_blfile}"
  111. fi
  112. exit 0
  113. }
  114. _mkuimage-custom() {
  115. _dtb="${_board}"
  116. echo "Set load address with a hex number (default: ${_address}):"
  117. read _loadaddress_tiped
  118. if [ -n "${_loadaddress_tiped}" ]; then
  119. _loadaddress="${_loadaddress_tiped}"
  120. else
  121. _loadaddress="${_address}"
  122. fi
  123. echo "Set entry point with a hex number (default: ${_address}):"
  124. read _entrypoint_tiped
  125. if [ -n "${_entrypoint_tiped}" ]; then
  126. _entrypoint="${_entrypoint_tiped}"
  127. else
  128. _entrypoint="${_address}"
  129. fi
  130. }
  131. if [ "${_arch}" = 'arm' ]; then
  132. if [ "${_kerneltype}" = 'linux' ]; then
  133. case ${_board} in
  134. ax3)
  135. _dtb='armada-xp-openblocks-ax3-4'
  136. _entrypoint="${_address}"
  137. _loadaddress="${_address}"
  138. ;;
  139. cubox)
  140. _dtb='dove-cubox'
  141. _entrypoint="${_address}"
  142. _loadaddress="${_address}"
  143. # ;;
  144. # chromebook)
  145. # _mkuimage-gnu+linux-chromebook
  146. ;;
  147. d3plug)
  148. _dtb='dove-d3plug'
  149. _entrypoint="${_address}"
  150. _loadaddress="${_address}"
  151. ;;
  152. grub)
  153. _mkuimage-grub
  154. # ;;
  155. # grub-chromebook|chromebook-grub)
  156. # _mkuimage-grub-chromebook
  157. ;;
  158. mirabox)
  159. _dtb='armada-370-mirabox'
  160. _entrypoint="${_address}"
  161. _loadaddress="${_address}"
  162. ;;
  163. smileplug)
  164. _dtb='armada-370-smileplug'
  165. _entrypoint="${_address}"
  166. _loadaddress="${_address}"
  167. ;;
  168. *)
  169. _mkuimage-custom
  170. ;;
  171. esac
  172. else
  173. case ${_board} in
  174. grub)
  175. _mkuimage-grub
  176. # ;;
  177. # grub-chromebook|chromebook-grub)
  178. # _mkuimage-grub-chromebook
  179. ;;
  180. *)
  181. _mkuimage-custom
  182. ;;
  183. esac
  184. fi
  185. else
  186. _mkuimage-custom
  187. fi
  188. _mkuimage