Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.76 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #### originally Written By Stifler6996 (Tang73)
  4. ## To get straight to the executed script part, CTRL-F 'KoalaFarts'
  5. ## To modify the dd image size CTRL-F 'seek='
  6. #===== last mod by raxy on 15aug =====
  7. # build leaner image (was 5GB) w/o mate; make prompt more explicit; rm jokes
  8. # replace git clone khadas kernel 4.9 by umidelb kernel 4.13-rc2 repo; j8 by j4, fully handle umiddelb's dtb
  9. # ..handles torvald's source tree (inc. config & dtb), linux-4.9 --> linux-kernel; rename kern compil fn
  10. # ..handle numbqq 412rc6 sources tree, remove unused SBC PC kernel choice, handle mainline special wifi and BT drivers/scripts
  11. # ..950MB rootfs, rm unneeded some comments, handle xenial or zesty
  12. # ..begin can run on aarch64, split in 2 functions to clone uboot and kernel, begin clean inter steps echos
  13. # add git clone raxy
  14. # split make kernel in 3, done all sed/ed changes to give building booting login system
  15. # handle drivers/Kconfig, create patch_mainline_kernel(), handle kernel 4.12.7 stable, double check and split handling of defconfig in multiple cmds
  16. # ethernet works on 4.12.7! clean more of defconfig : rm tegra,arch-non-meson,intel, reshape ed cmds
  17. # --TODO next -- clean more of defconfig : debug, qcom, drm non meson, bluetooth, make work, make fbset and work, port to 4.13 when stable
  18. # --TODO next -- make work : usb, ssh server, hdmi boot mesg: unremove add CONFIG_FRAMEBUFFER_CONSOLE=y & CONFIG_FB=y, add CONFIG_DRM_MESON_DW_HDMI=y
  19. # check if in Tang73's original script there was mention to khadas_init.sh which does not run here
  20.  
  21. ###### BASICS ######
  22. SCRIPT_ROOT="$(dirname "$(readlink -fm "$0")")"
  23. COMPONENT_ROOT="$(dirname "$(dirname "$(readlink -fm "$0")")")"
  24. APP_ROOT="$(dirname "$(dirname "$(dirname "$(readlink -fm "$0")")")")"
  25. MY_DTB="kvim.dtb"
  26. UBUN_TAR="undefined"
  27. #### Configure these
  28. OUTPUT_ROOT=${APP_ROOT}/SBC-Images #SBC= Single Board Computer!
  29. UBOOT_ROOT=${COMPONENT_ROOT}/u-boot
  30. KERNEL_ROOT=${COMPONENT_ROOT}/linux-kernel
  31.  
  32. runsOnArm64=0
  33. uname -a | grep aarch64
  34. if [ $? -eq 0 ]; then
  35. runsOnArm64=1
  36. fi
  37.  
  38. #clear
  39. cat <<EOF
  40. Runs on aarch64 : $runsOnArm64
  41. Using root directory : ${APP_ROOT}
  42. Using component folder: ${COMPONENT_ROOT}
  43. Using script folder : ${SCRIPT_ROOT}
  44. Using output folder : ${OUTPUT_ROOT}
  45.  
  46. EOF
  47.  
  48. install -d ${OUTPUT_ROOT}/{addtoimage,rootfs}
  49. install -d ${COMPONENT_ROOT}/{logo,ubuntu-base}
  50. ###### END BASICS ######
  51.  
  52. ###### FUNCTIONS ######
  53. system_setup_aptget () {
  54. echo
  55. echo -e "#####################"
  56. echo -e " system_setup_aptget : complement host system toolings"
  57. cd ${COMPONENT_ROOT}
  58. sudo apt-get update
  59. #sudo apt-get -y upgrade
  60. #OLD sudo apt-get -y install build-essential kernel-package fakeroot libncurses5-dev samba htop screen
  61. #OLD sudo apt-get -y install qemu qemu-user-static binfmt-support debootstrap lib32stdc++6 libstdc++6 sudo apt-get -y install build-essential kernel-package fakeroot libncurses5-dev htop
  62.  
  63. sudo apt-get -y install build-essential fakeroot libncurses5-dev libssl-dev ccache wget bzip2 git
  64. uname -a | grep x86
  65. if [ $? -eq 0 ]; then
  66. #IVN, x86 ! add these :
  67. sudo apt-get -y install gcc-arm-none-eabi gcc-aarch64-linux-gnu
  68. sudo apt-get -y install qemu qemu-user-static binfmt-support lib32stdc++6 libstdc++6
  69. # IVN this one specially for 16.10+ hosts!
  70. sudo apt-get install libnewlib-arm-none-eabi
  71. fi
  72.  
  73. echo
  74. echo -e "##########################"
  75. echo -e " END: host system_setup_aptget "
  76. echo
  77. }
  78.  
  79. system_setup_gitgetuboot () {
  80. cat <<EOF
  81.  
  82. ###############################
  83. system_setup_gitgetuboot : git clone uboot and kernel sources
  84.  
  85. EOF
  86. cd ${COMPONENT_ROOT}
  87. echo -e " (re)cloning u-boot, please wait.."
  88. git clone https://github.com/khadas/u-boot -b ubuntu u-boot
  89.  
  90. cat <<EOF
  91.  
  92. END: ssystem_setup_gitgetuboot
  93. ###############################
  94. EOF
  95. }
  96.  
  97. system_setup_gitgetkern () {
  98. cat <<EOF
  99.  
  100. ###############################
  101. system_setup_gitgetkern : git clone uboot and kernel sources
  102.  
  103. EOF
  104. cd ${COMPONENT_ROOT}
  105. GIT_OPT="--depth 1 --single-branch"
  106. SKIP1=0
  107.  
  108. while true; do
  109. read -n1 -p $'\nGit clone kernel source for (x)4.12.7 (r)axy/torvalds 4.12.0 (n)umbqq 4.12rc6 (k)hadas 4.9 (u)middelb mainline or (m)ainline latest torvalds [n/k/u/m/q]' yn
  110. echo
  111. case $yn in
  112. [m]* ) git clone $GIT_OPT -b master https://github.com/torvalds/linux.git linux-kernel; isMainline=1; touch linux-kernel/isTorvaldsLatest; break;;
  113. [k]* ) git clone $GIT_OPT -b ubuntu-4.9 https://github.com/khadas/linux linux-kernel; touch linux-kernel/isKhadas49; break;;
  114. [n]* ) git clone $GIT_OPT -b 4.12-rc6 https://github.com/numbqq/linux.git linux-kernel; touch linux-kernel/isNumbqq412rc6; break;;
  115. # [u]* ) git clone $GIT_OPT -b new-master https://github.com/ioft/linux.git linux-kernel; touch linux-kernel/isUmiddelb; break;;
  116. # [r]* ) git clone $GIT_OPT -b v4.12-rc6 https://github.com/dsir-minute/linux.git linux-kernel; break;;
  117. [r]* )
  118. git clone $GIT_OPT -b v4.12 https://github.com/torvalds/linux.git linux-kernel
  119. patch_mainline_kernel
  120. touch linux-kernel/is4.12.0-stable
  121. break;;
  122. [x]* )
  123. git clone $GIT_OPT -b linux-4.12.y https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git linux-kernel
  124. touch linux-kernel/is4.12.y-stable
  125. patch_mainline_kernel
  126. break;;
  127. [q]* ) echo "Adios then !!!"; exit;;
  128. * ) echo -e "\n(x)4.12.7 (r)axy/torvalds 4.12.0 (n)umbqq 4.12rc6 (k)hadas 4.9 (u)middelb mainline or (m)ainline latest torvalds or (q)uit";;
  129. esac
  130. done
  131. cat <<EOF
  132.  
  133. END: ssystem_setup_gitgetkern
  134. ###############################
  135.  
  136. EOF
  137. }
  138.  
  139. patch_mainline_kernel() {
  140. SKIP1=1
  141. isMainline=1
  142. KERNPATH=~/project/khadas-build-script/Khadas-Components/linux-kernel
  143. echo '===>> handle device tree ...'
  144. cd ${KERNPATH}/arch/arm64/boot/dts/amlogic
  145. mv meson-gxl-s905x-khadas-vim.dts meson-gxl-s905x-khadas-vim.dts.org
  146. \cp /home/raxy/project/khadas-build-script/mainlineKernAdditions/khadas-vim-raxy.dts ./meson-gxl-s905x-khadas-vim.dts
  147. #echo 'add file partitions.dtsi inlined in special meson-gxl-s905x-khadas-vim.dts before ..'
  148. #\cp -rf /home/raxy/project/khadas-build-script/mainlineKernAdditions/partitions.dtsi .
  149. echo 'no need to copy it to scripts/dtc/include-prefixes/arm64/amlogic/ because theyr are linked!'
  150. #\cp -rf ./meson-gxl-s905x-khadas-vim.dts ${KERNPATH}/scripts/dtc/include-prefixes/arm64/amlogic/
  151. echo '===>> handle defconfig ...'
  152. cd ${KERNPATH}/arch/arm64/configs
  153. cp defconfig defconfig.org
  154. ### EXTRA CAUTION! when string not found, ie "?" printed; delete proceeded anyway !!!
  155. ed -s defconfig << EOF
  156. /CONFIG_SERIAL_MSM=
  157. d
  158. /CONFIG_SERIAL_MSM_CONSOLE=
  159. d
  160. /CONFIG_SERIAL_MVEBU_UART=
  161. d
  162. /CONFIG_I2C_MUX=
  163. d
  164. /CONFIG_I2C_BCM2835=
  165. d
  166. /CONFIG_I2C_IMX=
  167. d
  168. /CONFIG_I2C_MV64XXX=
  169. d
  170. /CONFIG_I2C_PXA=
  171. d
  172. /CONFIG_I2C_QUP=
  173. d
  174. /CONFIG_I2C_SH_MOBILE=
  175. d
  176. /CONFIG_I2C_TEGRA=
  177. d
  178. /CONFIG_I2C_UNIPHIER_F=
  179. d
  180. /CONFIG_I2C_RCAR=
  181. d
  182. /CONFIG_SPI_BCM2835=
  183. d
  184. /CONFIG_SPI_BCM2835AUX=
  185. d
  186. /CONFIG_SPI_ORION=y
  187. d
  188. /CONFIG_SPI_QUP=
  189. d
  190. /CONFIG_SPI_S3C64XX=
  191. d
  192. /CONFIG_PINCTRL_MSM8916=
  193. d
  194. /CONFIG_PINCTRL_MSM8994=
  195. d
  196. /CONFIG_PINCTRL_MSM8996=
  197. d
  198. /CONFIG_PINCTRL_QDF2XXX=
  199. d
  200. /CONFIG_PINCTRL_QCOM_SPMI_PMIC=
  201. d
  202. /CONFIG_GPIO_RCAR=y
  203. d
  204. /CONFIG_GPIO_XGENE_SB=
  205. d
  206. /CONFIG_POWER_RESET_MSM=
  207. d
  208. /CONFIG_ROCKCHIP_THERMAL=
  209. d
  210. /CONFIG_EXYNOS_THERMAL=
  211. d
  212. /CONFIG_S3C2410_WATCHDOG=
  213. d
  214. /CONFIG_RENESAS_WDT=
  215. d
  216. /CONFIG_BCM2835_WDT=
  217. d
  218. /CONFIG_MFD_EXYNOS_LPASS=
  219. d
  220. /CONFIG_MFD_HI655X_PMIC=
  221. d
  222. /CONFIG_MFD_SPMI_PMIC=
  223. d
  224. /CONFIG_REGULATOR_HI655X=
  225. d
  226. /CONFIG_REGULATOR_QCOM_SMD_RPM=
  227. d
  228. /CONFIG_VIDEO_SAMSUNG_S5P_JPEG=
  229. d
  230. /CONFIG_VIDEO_SAMSUNG_S5P_MFC=
  231. d
  232. /CONFIG_VIDEO_SAMSUNG_EXYNOS_GSC=
  233. d
  234. /CONFIG_VIDEO_RENESAS_FCP=
  235. d
  236. /CONFIG_VIDEO_RENESAS_VSP1=
  237. d
  238. /CONFIG_DRM_NOUVEAU=
  239. d
  240. /CONFIG_DRM_EXYNOS=
  241. d
  242. /CONFIG_DRM_EXYNOS5433_DECON=
  243. d
  244. /CONFIG_DRM_EXYNOS7_DECON=
  245. d
  246. /CONFIG_DRM_EXYNOS_DSI=
  247. d
  248. /CONFIG_DRM_EXYNOS_HDMI=
  249. d
  250. /CONFIG_DRM_EXYNOS_MIC=
  251. d
  252. /CONFIG_DRM_RCAR_DU=
  253. d
  254. /CONFIG_DRM_RCAR_LVDS=
  255. d
  256. /CONFIG_DRM_RCAR_VSP=
  257. d
  258. /CONFIG_DRM_TEGRA=
  259. d
  260. /CONFIG_DRM_PANEL_SIMPLE=
  261. d
  262. /CONFIG_DRM_VC4=
  263. d
  264. /CONFIG_DRM_HISI_KIRIN=
  265. d
  266. /CONFIG_SND_BCM2835_SOC_I2S=
  267. d
  268. /CONFIG_SND_SOC_SAMSUNG=
  269. d
  270. /CONFIG_SND_SOC_RCAR=
  271. d
  272. /CONFIG_USB_XHCI_TEGRA=
  273. d
  274. /CONFIG_USB_EHCI_MSM=
  275. d
  276. /CONFIG_USB_EHCI_EXYNOS=
  277. d
  278. /CONFIG_USB_OHCI_EXYNOS=
  279. d
  280. /CONFIG_USB_RENESAS_USBHS=
  281. d
  282. /CONFIG_USB_MSM_OTG=
  283. d
  284. /CONFIG_USB_QCOM_8X16_PHY=
  285. d
  286. /CONFIG_USB_RENESAS_USBHS_UDC=
  287. d
  288. /CONFIG_MMC_SDHCI_OF_ESDHC=
  289. d
  290. /CONFIG_MMC_SDHCI_TEGRA=
  291. d
  292. /CONFIG_MMC_SDHCI_MSM=
  293. d
  294. /CONFIG_MMC_SDHI=
  295. d
  296. /CONFIG_MMC_DW_ROCKCHIP=
  297. d
  298. wq
  299. EOF
  300.  
  301. # end of delete block1
  302. ed -s defconfig << EOF
  303. /CONFIG_MMC_SUNXI=
  304. d
  305. /CONFIG_MMC_BCM2835=
  306. d
  307. /CONFIG_RTC_DRV_S3C=
  308. d
  309. /CONFIG_RTC_DRV_SUN6I=
  310. d
  311. /CONFIG_RTC_DRV_TEGRA=
  312. d
  313. /CONFIG_RTC_DRV_XGENE=
  314. d
  315. /CONFIG_DMA_BCM2835=
  316. d
  317. /CONFIG_TEGRA20_APB_DMA=
  318. d
  319. /CONFIG_QCOM_BAM_DMA=
  320. d
  321. /CONFIG_RCAR_DMAC=
  322. d
  323. /CONFIG_COMMON_CLK_QCOM=
  324. d
  325. /CONFIG_QCOM_CLK_SMD_RPM=
  326. d
  327. /CONFIG_MSM_GCC_8916=
  328. d
  329. /CONFIG_MSM_GCC_8994=
  330. d
  331. /CONFIG_MSM_MMCC_8996=
  332. d
  333. /CONFIG_HWSPINLOCK_QCOM=
  334. d
  335. /CONFIG_BCM2835_MBOX=
  336. d
  337. /CONFIG_HI6220_MBOX
  338. d
  339. /CONFIG_RPMSG_QCOM_SMD=
  340. d
  341. /CONFIG_RASPBERRYPI_POWER=
  342. d
  343. /CONFIG_QCOM_SMEM=
  344. d
  345. /CONFIG_QCOM_SMD_RPM=
  346. d
  347. /CONFIG_QCOM_SMP2P=
  348. d
  349. /CONFIG_QCOM_SMSM=
  350. d
  351. /CONFIG_ROCKCHIP_PM_DOMAINS=
  352. d
  353. /CONFIG_ARCH_TEGRA_132_SOC=
  354. d
  355. /CONFIG_ARCH_TEGRA_210_SOC=
  356. d
  357. /CONFIG_ARCH_TEGRA_186_SOC=
  358. d
  359. /CONFIG_EXYNOS_ADC=
  360. d
  361. /CONFIG_ROCKCHIP_SARADC=
  362. d
  363. /CONFIG_PWM_BCM2835=
  364. d
  365. /CONFIG_PWM_ROCKCHIP=
  366. d
  367. /CONFIG_PWM_SAMSUNG=
  368. d
  369. /CONFIG_PWM_TEGRA=
  370. d
  371. /CONFIG_PHY_RCAR_GEN3_USB2=
  372. d
  373. /CONFIG_PHY_HI6220_USB=
  374. d
  375. /CONFIG_PHY_SUN4I_USB=
  376. d
  377. /CONFIG_PHY_ROCKCHIP_INNO_USB2=
  378. d
  379. /CONFIG_PHY_ROCKCHIP_EMMC=
  380. d
  381. /CONFIG_PHY_ROCKCHIP_PCIE=
  382. d
  383. /CONFIG_PHY_TEGRA_XUSB=
  384. d
  385. /CONFIG_ARCH_R8A7796=
  386. d
  387. /CONFIG_ARCH_STRATIX10=
  388. d
  389. /CONFIG_ARCH_TEGRA=
  390. d
  391. /CONFIG_ARCH_SPRD=
  392. d
  393. /CONFIG_ARCH_THUNDER=
  394. d
  395. /CONFIG_ARCH_THUNDER2=
  396. d
  397. wq
  398. EOF
  399.  
  400. # end of delete block2
  401. ed -s defconfig << EOF
  402. /CONFIG_ARCH_UNIPHIER=
  403. d
  404. /CONFIG_ARCH_VEXPRESS=
  405. d
  406. /CONFIG_ARCH_VULCAN=
  407. d
  408. /CONFIG_ARCH_XGENE=
  409. d
  410. /CONFIG_ARCH_ZX=
  411. d
  412. /CONFIG_ARCH_ZYNQMP=
  413. d
  414. /CONFIG_IPV6=
  415. d
  416. /CONFIG_PCI_LAYERSCAPE=
  417. d
  418. /CONFIG_PCIE_QCOM=
  419. d
  420. /CONFIG_PCIE_ARMADA_8K=
  421. d
  422. /CONFIG_PCI_AARDVARK=
  423. d
  424. /CONFIG_PCIE_RCAR=
  425. d
  426. /CONFIG_PCIE_ROCKCHIP=
  427. d
  428. /CONFIG_RASPBERRYPI_FIRMWARE=
  429. d
  430. /CONFIG_AHCI_MVEBU=
  431. d
  432. /CONFIG_SATA_RCAR=
  433. d
  434. /CONFIG_NET_XGENE=
  435. d
  436. /CONFIG_MVNETA=
  437. d
  438. /CONFIG_MVPP2=
  439. d
  440. /CONFIG_RAVB=
  441. d
  442. /CONFIG_WL18XX=
  443. d
  444. /CONFIG_WLCORE_SDIO=
  445. d
  446. /CONFIG_INPUT_PM8941_PWRKEY=
  447. d
  448. /CONFIG_INPUT_HISI_POWERKEY=
  449. d
  450. /CONFIG_SERIAL_8250_BCM2835AUX=
  451. d
  452. /CONFIG_SERIAL_8250_MT6577=
  453. d
  454. /CONFIG_SERIAL_8250_UNIPHIER=
  455. d
  456. /CONFIG_SERIAL_SAMSUNG=
  457. d
  458. /CONFIG_SERIAL_SAMSUNG_CONSOLE=
  459. d
  460. /CONFIG_SERIAL_TEGRA=
  461. d
  462. /CONFIG_SERIAL_SH_SCI=
  463. d
  464. /CONFIG_SERIAL_SH_SCI_NR_UARTS=
  465. d
  466. /CONFIG_SERIAL_SH_SCI_CONSOLE=
  467. d
  468. wq
  469. EOF
  470. # end of delete block3
  471. ed -s defconfig << EOF
  472. /CONFIG_ARCH_SUNXI=
  473. d
  474. /CONFIG_ARCH_ALPINE=
  475. d
  476. /CONFIG_ARCH_BCM2835=
  477. d
  478. /CONFIG_ARCH_BCM_IPROC=
  479. d
  480. /CONFIG_ARCH_BERLIN=
  481. d
  482. /CONFIG_ARCH_EXYNOS=
  483. d
  484. /CONFIG_ARCH_LAYERSCAPE=
  485. d
  486. /CONFIG_ARCH_LG1K=
  487. d
  488. /CONFIG_ARCH_HISI=
  489. d
  490. /CONFIG_ARCH_MEDIATEK=
  491. d
  492. /CONFIG_ARCH_MVEBU=
  493. d
  494. /CONFIG_ARCH_QCOM=
  495. d
  496. /CONFIG_ARCH_ROCKCHIP=
  497. d
  498. /CONFIG_ARCH_SEATTLE=
  499. d
  500. /CONFIG_ARCH_RENESAS=
  501. d
  502. /CONFIG_ARCH_R8A7795=
  503. d
  504. /CONFIG_BACKLIGHT_GENERIC=
  505. d
  506. /CONFIG_BACKLIGHT_LP855X=
  507. d
  508. wq
  509. EOF
  510. # end of delete block4
  511. ed -s defconfig << EOF
  512. /CONFIG_BRCMFMAC=
  513. a
  514. CONFIG_BRCM_TRACING=y
  515. CONFIG_BRCMDBG=y
  516. CONFIG_ARCH_BRCMSTB=y
  517. CONFIG_AMLOGIC_DRIVER=y
  518. CONFIG_AMLOGIC_MODIFY=y
  519. CONFIG_AMLOGIC_IOMAP=y
  520. CONFIG_AMLOGIC_MMC=y
  521. CONFIG_AMLOGIC_BT_DEVICE=y
  522. CONFIG_REGULATOR=y
  523. CONFIG_SND_SIMPLE_CARD=y
  524. CONFIG_TMPFS=y
  525. CONFIG_PHY_BRCM_SATA=y
  526. CONFIG_PHY_SAMSUNG_USB2=y
  527. CONFIG_BRIDGE_NETFILTER=y
  528. CONFIG_VEXPRESS_CONFIG=y
  529. CONFIG_MVMDIO=y
  530. CONFIG_MDIO_BITBANG=y
  531. CONFIG_I2C_SLAVE=y
  532. CONFIG_SPI_BCM_QSPI=y
  533. CONFIG_POWER_RESET_VEXPRESS=y
  534. CONFIG_DRM_I2C_CH7006=m
  535. CONFIG_DRM_I2C_SIL164=m
  536. CONFIG_DRM_MESON_DW_HDMI=y
  537. CONFIG_COMMON_CLK_VERSATILE=y
  538. CONFIG_CLK_SP810=y
  539. CONFIG_CLK_VEXPRESS_OSC=y
  540. CONFIG_ARM_TIMER_SP804=y
  541. CONFIG_MAILBOX=y
  542. CONFIG_BCM_FLEXRM_MBOX=y
  543. CONFIG_CRYPTO_AES_ARM64_CE_BLK=y
  544. CONFIG_CRYPTO_AES_ARM64_CE_CCM=y
  545. CONFIG_CRYPTO_GHASH_ARM64_CE=y
  546. CONFIG_CRYPTO_SHA1_ARM64_CE=y
  547. CONFIG_CRYPTO_SHA2_ARM64_CE=y
  548. CONFIG_BT_RFCOMM_TTY=y
  549. CONFIG_BT_RFCOMM=y
  550. CONFIG_BT_HCIUART_H4=y
  551. CONFIG_BT_BNEP_MC_FILTER=y
  552. CONFIG_BT_BNEP_PROTO_FILTER=y
  553. CONFIG_BT_BNEP=y
  554. CONFIG_ARM64_CRYPTO=y
  555. .
  556. 1
  557. /CONFIG_RFKILL=m
  558. d
  559. a
  560. CONFIG_RFKILL=y
  561. .
  562. 1
  563. /CONFIG_PWM_MESON=m
  564. d
  565. a
  566. CONFIG_PWM_MESON=y
  567. .
  568. 1
  569. /CONFIG_MESON_GXL_PHY=m
  570. d
  571. a
  572. CONFIG_MESON_GXL_PHY=y
  573. .
  574. 1
  575. /CONFIG_REALTEK_PHY=m
  576. d
  577. a
  578. CONFIG_REALTEK_PHY=y
  579. .
  580. 1
  581. /CONFIG_STMMAC_ETH=m
  582. d
  583. a
  584. CONFIG_STMMAC_ETH=y
  585. .
  586. wq
  587. EOF
  588.  
  589. echo '===>> handle block/blk-mq-sched.c ...'
  590. if [ $SKIP1 -eq 1 ]; then
  591. echo '#not needed in 4.12.0'
  592. else
  593. cd $KERNPATH/block
  594. cp blk-mq-sched.c blk-mq-sched.c.org
  595. ed -s blk-mq-sched.c << EOF
  596. /if (set->flags & BLK_MQ_F_TAG_SHARED) {
  597. a
  598. if (!atomic_read(&queue->shared_hctx_restart))
  599. return;
  600. .
  601. wq
  602. EOF
  603. fi
  604.  
  605. echo '===>> handle block/blk-mq.c ...'
  606. if [ $SKIP1 -eq 1 ]; then
  607. echo '#not needed in 4.12.0'
  608. else
  609. cp blk-mq.c blk-mq.c.org
  610. ed -s blk-mq.c << EOF
  611. /if (shared)
  612. d
  613. d
  614. d
  615. d
  616. -1
  617. a
  618. REPLACE_ME
  619. .
  620. wq
  621. EOF
  622. ed -s blk-mq.c << EOF
  623. /REPLACE_ME
  624. d
  625. -1
  626. a
  627. if (shared) {
  628. if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
  629. atomic_inc(&q->shared_hctx_restart);
  630. hctx->flags |= BLK_MQ_F_TAG_SHARED;
  631. } else {
  632. if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
  633. atomic_dec(&q->shared_hctx_restart);
  634. hctx->flags &= ~BLK_MQ_F_TAG_SHARED;
  635. }
  636. .
  637. wq
  638. EOF
  639. fi
  640.  
  641. echo '===>> add drivers/amlogic/* ...'
  642. \cp -rf /home/raxy/project/khadas-build-script/mainlineKernAdditions/amlogic $KERNPATH/drivers/
  643.  
  644. echo '===>> handle block.c and inclusion of emmc_partitions.h...'
  645. cd $KERNPATH/drivers/mmc/core
  646. cp block.c block.c.org
  647. ed -s block.c << EOF
  648. /#include "sd_ops.h"
  649. a
  650.  
  651. #ifdef CONFIG_AMLOGIC_MMC
  652. #include <linux/mmc/emmc_partitions.h>
  653. #endif
  654. .
  655. /if (mmc_add_disk(md))
  656. +1a
  657.  
  658. #ifdef CONFIG_AMLOGIC_MMC
  659. /* amlogic add emmc partitions ops */
  660. aml_emmc_partition_ops(card, md->disk);
  661. #endif
  662.  
  663. .
  664. wq
  665. EOF
  666. # echo '===>> invoke emmc_partitions.h from block.c..'
  667. # none of these work
  668. # sed -i "/if \(mmc_add_disk\(md\)\)/a aml_emmc_partition_ops" block.c
  669. # sed -i "/if \(mmc_add_disk\(md\)\)\n\t*goto out;/a aml_emmc_partition_ops;" block.c
  670. # sed -E -i 's/if \(mmc_add_disk\(md\)\)\n.*goto out;/\naml_emmc_partition_ops;/g' block.c
  671. # printf 's/if \(mmc_add_disk\(md\)\)\n.*goto out;/&\naml_emmc_partition_ops;/g' | ed block.c
  672.  
  673. echo '===>> handle drivers/Makefile ...'
  674. cd ${KERNPATH}/drivers
  675. ed -s Makefile << EOF
  676. /CONFIG_TEE
  677. a
  678. obj-\$(CONFIG_AMLOGIC_DRIVER) += amlogic/
  679. .
  680. wq
  681. EOF
  682. echo '===>> upgrade drivers/Kconfig ...'
  683. #cd ${KERNPATH}/drivers
  684. cp Kconfig Kconfig.org
  685. ed -s Kconfig << EOF
  686. /"Device Drivers"
  687. a
  688.  
  689. source "drivers/amlogic/Kconfig"
  690. .
  691. wq
  692. EOF
  693. echo '===>> handle include/linux/mmc/card.h ...'
  694. cd ${KERNPATH}/include/linux/mmc/
  695. ed -s card.h << EOF
  696. /#define MMC_TYPE_SD_COMBO
  697. a
  698. #define MMC_STATE_PRESENT (1<<0) /* present in sysfs */
  699. #define MMC_STATE_READONLY (1<<1) /* card is read-only */
  700. #define MMC_STATE_BLOCKADDR (1<<2) /* card uses block-addressing */
  701. #define MMC_CARD_SDXC (1<<3) /* card is SDXC */
  702. #define MMC_CARD_REMOVED (1<<4) /* card has been removed */
  703. #define MMC_STATE_DOING_BKOPS (1<<5) /* card is doing BKOPS */
  704. #define MMC_STATE_SUSPENDED (1<<6) /* card is suspended */
  705. .
  706. /#define mmc_card_sdio(c)
  707. a
  708.  
  709. #define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT)
  710. #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
  711. #define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR)
  712. #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
  713. #define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED))
  714. #define mmc_card_doing_bkops(c) ((c)->state & MMC_STATE_DOING_BKOPS)
  715. #define mmc_card_suspended(c) ((c)->state & MMC_STATE_SUSPENDED)
  716. #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
  717. #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
  718. #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR)
  719. #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC)
  720. #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED)
  721. #define mmc_card_set_doing_bkops(c) ((c)->state |= MMC_STATE_DOING_BKOPS)
  722. #define mmc_card_clr_doing_bkops(c) ((c)->state &= ~MMC_STATE_DOING_BKOPS)
  723. #define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED)
  724. #define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED)
  725. .
  726. wq
  727. EOF
  728. echo '===>> handle include/linux/mmc/host.h ...'
  729. sed -i "/unsigned int *\t*f_init;/a #ifdef CONFIG_AMLOGIC_MMC\n\tu8 first_init_flag;\n#endif" host.h
  730. #sed -i "/#define MMC_CAP2_FULL_PWR_CYCLE/a #define MMC_CAP2_NO_MULTI_READ (1 << 3) /* Multiblock reads don't work */" host.h
  731. ed -s host.h << EOF
  732. /#define MMC_CAP2_FULL_PWR_CYCLE
  733. a
  734. #ifdef CONFIG_AMLOGIC_MMC
  735. #define MMC_CAP2_NO_MULTI_READ (1 << 3) /* Multiblock reads don't work */
  736. #endif
  737. .
  738. wq
  739. EOF
  740. echo '===>> add file include/linux/mmc/emmc_partitions.h ..'
  741. \cp -rf /home/raxy/project/khadas-build-script/mainlineKernAdditions/mmc/emmc_partitions.h ${KERNPATH}/include/linux/mmc
  742.  
  743. echo '===>> add include/linux/amlogic/*.h ...'
  744. \cp -rf /home/raxy/project/khadas-build-script/mainlineKernAdditions/include/linux/amlogic $KERNPATH/include/linux
  745.  
  746. echo '===>> handle include/linux/blkdev.h ...'
  747. if [ $SKIP1 -eq 1 ]; then
  748. echo '#not needed in 4.12.0'
  749. else
  750. cd ${KERNPATH}/include/linux
  751. cp blkdev.h blkdev.h.org
  752. sed -i "/int *\t*nr_rqs_elvpriv;/a atomic_t\tshared_hctx_restart;" blkdev.h
  753. fi
  754.  
  755. echo '===>> handle mm/mmap.c ...'
  756. if [ $SKIP1 -eq 1 ]; then
  757. echo '#not needed in 4.12.0'
  758. else
  759. cd ${KERNPATH}/mm
  760. cp mmap.c mmap.c.org
  761. ed -s mmap.c << EOF
  762. /gap_end >= low_limit && gap_end - gap_start >= length
  763. d
  764. -1a
  765. if (gap_end >= low_limit && gap_end > gap_start && gap_end - gap_start >= length)
  766. .
  767. /gap_start <= high_limit && gap_end - gap_start >= length
  768. d
  769. -1a
  770. if (gap_start <= high_limit && gap_end > gap_start && gap_end - gap_start >= length)
  771. .
  772. /Guard against wrapping around to address 0
  773. d
  774. d
  775. d
  776. d
  777. d
  778. -1a
  779. /* Guard against exceeding limits of the address space. */
  780. address &= PAGE_MASK;
  781. if (address >= TASK_SIZE)
  782. return -ENOMEM;
  783. address += PAGE_SIZE;
  784. .
  785. /if (gap_addr < address)
  786. d
  787. d
  788. -1a
  789.  
  790. /* Guard against overflow */
  791. if (gap_addr < address || gap_addr > TASK_SIZE)
  792. gap_addr = TASK_SIZE;
  793.  
  794. .
  795. wq
  796. EOF
  797. fi
  798.  
  799. echo '===>> handle drivers/clk/meson/Kconfig ...'
  800. if [ $SKIP1 -eq 1 ]; then
  801. echo '#not needed in 4.12.0'
  802. else
  803. cd ${KERNPATH}/drivers/clk/meson
  804. cp Kconfig Kconfig.org
  805. ed -s Kconfig << EOF
  806. /depends on COMMON_CLK_AMLOGIC
  807. /depends on COMMON_CLK_AMLOGIC
  808. n
  809. a
  810. select RESET_CONTROLLER
  811. .
  812. wq
  813. EOF
  814. fi
  815. echo '===>> mainline source tree now fully patched!'
  816. }
  817.  
  818. system_setup_ubuntu-base () {
  819. echo
  820. echo -e "##########################"
  821. echo -e " system_setup_ubuntu-base : get prebuilt ubuntu tar file"
  822. echo
  823. cd ${COMPONENT_ROOT}/ubuntu-base
  824.  
  825. while true; do
  826. read -n1 -p $'\nwget (x)enial 16.04.3 or (z)esty 17.04 ? [x/z]' res
  827. case $res in
  828. [x]* ) UBUN_TAR=ubuntu-base-16.04.3-base-arm64.tar.gz;
  829. wget http://cdimage.ubuntu.com/ubuntu-base/releases/16.04.3/release/$UBUN_TAR; break;;
  830. [z]* ) UBUN_TAR=ubuntu-base-17.04-base-arm64.tar.gz;
  831. wget http://cdimage.ubuntu.com/ubuntu-base/releases/zesty/release/$UBUN_TAR; break;;
  832. * ) echo -e "\n(x)enial 16.04.3 or (z)esty 17.04 ? ";;
  833. esac
  834. done
  835.  
  836. echo
  837. echo -e " END: system_setup_ubuntu-base "
  838. echo -e "###############################"
  839. echo
  840. }
  841.  
  842. system_setup_logo-bmp () {
  843. echo
  844. echo -e "#######################"
  845. echo -e " system_setup_logo-bmp : get logo image"
  846. echo
  847. cd ${COMPONENT_ROOT}/logo
  848. echo -e " You don't need to do this! I already included some images, they were only small in size!"
  849. echo -e " If you want to change them, they must be a 16/24bit bmp file and should be 1080p or less apparently."
  850. echo -e " This option use to download some images - look at the script if you want to change it."
  851. #wget https://s-media-cache-ak0.pinimg.com/originals/40/51/01/405101b2b3ccd9aef92d79322eaceb59.jpg skull.jpg
  852. #wget https://meyer.io/dl/khadasvim/debian-bootup.bmp
  853. echo
  854. echo -e " END: system_setup_logo-bmp "
  855. echo -e "############################"
  856. echo
  857. }
  858.  
  859. general_question_hdmi () {
  860. echo
  861. echo -e "*** NOTICE! ***"
  862. echo -e "***************\n"
  863. cd ${COMPONENT_ROOT}/u-boot
  864. echo -e "HAVE YOU CHECKED: /u-boot/board/khadas/configs/kvim.h ?"
  865. echo -e "If not, you will probably want to fix it and put 'hdmimode' BACK IN..!"
  866. echo
  867. echo -e "I dont know why I have to do it - but if I do not do this I get a blank screen"
  868. echo -e "during the boot and forever. Everything works, just no HDMI screen."
  869. echo -e "Add this back in and everything is good again?!?! WHY?! WHY!!"
  870. echo
  871. echo -e "Basically add 'hdmimode=1080p60hz' to the bootargs line, like this (it will be all one line in kvim.h):"
  872. echo
  873. cat <<EOF
  874. #### copy/paste the whole line below just under (for non mainline kernels): "bootargs==\" \\
  875. "root=LABEL=ROOTFS rootflags=data=writeback rw logo=osd1,loaded,0x3d800000,1080p60hz,full hdmimode=1080p60hz m_bpp=32 dmfc=3 vout=hdmi cvbsmode=576cvbs console=ttyS0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.repair=yes net.ifnames=0\0" \\
  876.  
  877. EOF
  878. }
  879.  
  880. general_question_macaddr () {
  881. echo
  882. echo -e "*** ANOTHER NOTICE! ***"
  883. echo -e "***********************\n"
  884. cd ${COMPONENT_ROOT}/u-boot
  885. echo -e "HAVE YOU SET YOUR specific ethernet MAC addr ?: (Also in /u-boot/board/khadas/configs/kvim.h)"
  886. echo -e "#define CONFIG_ETHADDR F0:CA:CC:1A:F0:0D"
  887. echo
  888. }
  889.  
  890. compile_firmware_u-boot () {
  891. echo
  892. echo -e "#########################"
  893. echo -e " compile_firmware_u-boot "
  894. echo
  895. cd ${COMPONENT_ROOT}/u-boot
  896. echo -e " Cleaning up - please wait.. "
  897. make clean
  898. make mrproper
  899. make distclean
  900. touch .scmversion
  901. make kvim_defconfig
  902. if [ $runsOnArm64 -eq 1 ]; then
  903. make -j4
  904. else
  905. make -j4 CROSS_COMPILE=aarch64-linux-gnu-
  906. fi
  907. echo
  908. echo -e "##############################"
  909. echo -e " END: compile_firmware_u-boot "
  910. echo
  911. }
  912.  
  913. compile_software_kernel () {
  914. echo
  915. echo -e "#############################"
  916. echo -e " compile_software_kernel "
  917.  
  918. echo
  919. cd ${COMPONENT_ROOT}/linux-kernel
  920. echo -e " Cleaning up - please wait.. "
  921. # 10aug :removed sudos
  922. #make clean
  923. #make mrproper
  924. #make distclean
  925. touch .scmversion
  926. isMainline=0
  927. while true; do
  928. read -n1 -p $'\nCompile (k)hadas (u)middelb mainline (m)torvalds/raxy mainline (n)umbqq 412rc6? [k/u/m/n]' yn
  929. echo
  930. case $yn in
  931. [k]* ) make ARCH=arm64 kvim_defconfig; break;;
  932. [n]* ) make ARCH=arm64 kvim_defconfig; isMainline=1; break;;
  933. [u]* ) make ARCH=arm64 gx_defconfig; isMainline=1; break;;
  934. [m]* ) make ARCH=arm64 defconfig; isMainline=1; break;;
  935. [q]* ) echo -e "Adios then !!!"; exit;;
  936. * ) echo -e "\n(k)hadas (u)middelb mainline (m)torvalds/raxy mainline (n)umbqq 412rc6 or (q)uit";;
  937. esac
  938. done
  939. if [ $isMainline -eq 1 ]; then
  940. SPECIAL_DTB="amlogic/meson-gxl-s905x-khadas-vim.dtb"
  941. echo SPECIAL_DTB:$SPECIAL_DTB
  942. make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- $SPECIAL_DTB
  943. make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules
  944. make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image
  945. #make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- $SPECIAL_DTB
  946. cp ${KERNEL_ROOT}/arch/arm64/boot/dts/$SPECIAL_DTB ${KERNEL_ROOT}/arch/arm64/boot/dts/amlogic/$MY_DTB
  947. else
  948. make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image $MY_DTB modules
  949. fi
  950.  
  951. echo
  952. echo -e " END: compile_software_kernel "
  953. echo -e "##################################"
  954. echo
  955. }
  956.  
  957. build_chroot_filesystem () {
  958. echo
  959. echo -e "#########################"
  960. echo -e " build_chroot_filesystem "
  961. echo
  962.  
  963. cd ${APP_ROOT}
  964.  
  965. #### NOTE: Bare in mind this size need to be a workable size = in your Chroot Jail workable size...
  966. #### So 5GB for desktop is a usable operating space for apt-get to be able to do all its shit within the jail.
  967. #### Once it is done, apt-get clean will get you back some of the space.
  968. #### I worked on adding 1GB to size. So if you know everything you want to install here will ultimately take 4GB, go for 5GB (seek=5120).
  969. #### Also, a good size for a non-GUI image for TESTING is 768MB (you will need to edit a lot of install shit out to fit, but it will be fast!)
  970. #### This isn't a scripted question because I assume you would ALWAYS normally want to make a GUI!
  971. dd if=/dev/zero of=${OUTPUT_ROOT}/rootfs.img bs=1M count=0 seek=950
  972.  
  973. #### Delete and recreate our mount folder (just making sure its empty)
  974. rm -rf ${OUTPUT_ROOT}/rootfs && install -d ${OUTPUT_ROOT}/rootfs
  975. #### Create linux filesystem on the newly created image
  976. sudo mkfs.ext4 -F -L ROOTFS ${OUTPUT_ROOT}/rootfs.img
  977. #### Mount image
  978. echo -e " Slipping a quick mount in.. "
  979. sudo mount -o loop ${OUTPUT_ROOT}/rootfs.img ${OUTPUT_ROOT}/rootfs
  980. #### Remove the unnecessary files
  981. sudo rm -rf ${OUTPUT_ROOT}/rootfs/lost+found
  982.  
  983. #### Do One or the other (second is more internet intensive. Both result in the same though since later we will apt-get upgrade anyway!)
  984. #### Extract the ubuntu-base tarball into the mounted folder
  985.  
  986. if [ $UBUN_TAR = "undefined" ] ;then
  987. while true; do
  988. read -n1 -p $'\nexpand (x)enial 16.04.3 or (z)esty 17.04 ? [x/z]' res
  989. case $res in
  990. [x]* ) UBUN_TAR=ubuntu-base-16.04.3-base-arm64.tar.gz; break;;
  991. [z]* ) UBUN_TAR=ubuntu-base-17.04-base-arm64.tar.gz; break;;
  992. * ) echo -e "\n(x)enial 16.04 or (z)esty 17.04 ? ";;
  993. esac
  994. done
  995. fi
  996.  
  997. echo -e "Ubuntu base going in.. "
  998. sudo tar -xzf ${COMPONENT_ROOT}/ubuntu-base/$UBUN_TAR -C ${OUTPUT_ROOT}/rootfs/
  999.  
  1000. #### Install Kernel Modules
  1001. echo -e " Kernel modules going in.. "
  1002. #### NOTE: "INSTALL_MOD_STRIP=1" and watch the module size drop by 10X!
  1003. sudo make -C ${COMPONENT_ROOT}/linux-kernel -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules_install INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=${OUTPUT_ROOT}/rootfs/
  1004.  
  1005. #### Mirrors for de ubuntu-ports
  1006. sudo cp -a ${OUTPUT_ROOT}/rootfs/etc/apt/sources.list ${OUTPUT_ROOT}/rootfs/etc/apt/sources.list.orig
  1007. #### http://ftp.tu-chemnitz.de/pub/linux/ubuntu-ports/
  1008. sudo sed -i "s/http:\/\/ports.ubuntu.com\/ubuntu-ports\//http:\/\/ftp.tu-chemnitz.de\/pub\/linux\/ubuntu-ports\//g" ${OUTPUT_ROOT}/rootfs/etc/apt/sources.list
  1009.  
  1010. #### http://mirror.veracruz.co/ubuntu/
  1011. #### http://mirror.vorboss.net/ubuntu-archive/
  1012. #### http://ubuntu-archive.adsolux.com/ubuntu/
  1013. #### http://mirrors.pol.hostinja.com/ubuntu/
  1014.  
  1015. #### Enable the rest of the source locations (so you can install htop, nano etc)
  1016. sudo sed -i "s/\#\ deb/deb/g" ${OUTPUT_ROOT}/rootfs/etc/apt/sources.list
  1017.  
  1018. #### Grab and file linux version (although we know - this might be useful later when we add
  1019. #### kernel-x.y as a new option to this building script
  1020. grep "Linux/arm64" ${COMPONENT_ROOT}/linux-kernel/.config | awk '{print $3}' > ${OUTPUT_ROOT}/linux-version
  1021. sudo cp -r ${OUTPUT_ROOT}/linux-version ${OUTPUT_ROOT}/rootfs/
  1022. echo
  1023.  
  1024. #### copy over initramfs scripts
  1025. echo -e " initramfs scripts going in.. "
  1026. sudo mkdir -p ${OUTPUT_ROOT}/rootfs/etc/initramfs-tools/scripts/local-top/
  1027. sudo cp -r ${SCRIPT_ROOT}/etc/initramfs-tools/scripts/local-top/khadas_init.sh ${OUTPUT_ROOT}/rootfs/etc/initramfs-tools/scripts/local-top/khadas_init.sh
  1028.  
  1029. sudo chmod +x ${OUTPUT_ROOT}/rootfs/etc/initramfs-tools/scripts/local-top/khadas_init.sh
  1030.  
  1031. #### copy over rc.local scripts
  1032. echo -e " rc.local scripts going in.. "
  1033. sudo cp -r ${SCRIPT_ROOT}/etc/rc.local ${OUTPUT_ROOT}/rootfs/etc/
  1034.  
  1035. #### firstboot initialization: for 'ROOTFS' partition resize
  1036. sudo touch ${OUTPUT_ROOT}/rootfs/etc/default/FIRSTBOOT
  1037.  
  1038. isMainline=0
  1039. while true; do
  1040. read -n1 -p $'\nwhich is your kernel, (k)hadas (u)middelb mainline (m)torvalds mainline (n)umbqq 412rc6? [k/u/m/m]' yn
  1041. case $yn in
  1042. [k]* ) break;;
  1043. [n]* ) isMainline=1; break;;
  1044. [u]* ) isMainline=1; break;;
  1045. [m]* ) isMainline=1; break;;
  1046. [q]* ) echo "go Fukkkkkk!!!"; exit;;
  1047. * ) echo -e "\n(k)hadas (u)middelb mainline (m)torvalds mainline (n)umbqq 412rc6 or (q)uit";;
  1048. esac
  1049. done
  1050.  
  1051. #### Move in FIRMWARE files for WiFi
  1052. sudo mkdir ${OUTPUT_ROOT}/rootfs/lib/firmware
  1053. sudo cp -r ${COMPONENT_ROOT}/hwpacks/wlan-firmware/brcm/ ${OUTPUT_ROOT}/rootfs/lib/firmware/
  1054. ### adjust country code ininsall.txt for wifi
  1055. sudo sed -i -e 's/ccode=AU/ccode=FR/g' ${OUTPUT_ROOT}/rootfs/lib/firmware/brcm/config.txt
  1056.  
  1057. #### Move in patch files for bluetooth
  1058. sudo cp -r ${COMPONENT_ROOT}/hwpacks/bluez/brcm_patchram_plus ${OUTPUT_ROOT}/rootfs/usr/local/bin/
  1059. sudo cp -r ${COMPONENT_ROOT}/hwpacks/bluez/bluetooth-khadas.service ${OUTPUT_ROOT}/rootfs/lib/systemd/system/
  1060.  
  1061. if [ $isMainline -eq 1 ]; then
  1062. sudo cp -r ${COMPONENT_ROOT}/hwpacks/bluez/bluetooth-khadas-mainline.sh ${OUTPUT_ROOT}/rootfs/usr/local/bin/bluetooth-khadas.sh
  1063. cd ${OUTPUT_ROOT}/rootfs/lib/firmware/brcm
  1064. echo "== mainline kernel needs renamed wifi drivers! =="
  1065. sudo cp fw_bcm43438a1.bin brcmfmac43430-sdio.bin
  1066. sudo cp nvram_ap6212a.txt brcmfmac43430-sdio.txt
  1067. sudo cp fw_bcm43455c0_ag.bin brcmfmac43455-sdio.bin
  1068. sudo cp nvram_ap6255.txt brcmfmac43455-sdio.txt
  1069. cd -
  1070. else
  1071. sudo cp -r ${COMPONENT_ROOT}/hwpacks/bluez/bluetooth-khadas.sh ${OUTPUT_ROOT}/rootfs/usr/local/bin/
  1072. fi
  1073.  
  1074. #### script for executing in chroot
  1075. sudo cp -r ${SCRIPT_ROOT}/99.ChrootScript.sh ${OUTPUT_ROOT}/rootfs/
  1076.  
  1077. #### Setup the Chroot environment
  1078. sudo cp -a /usr/bin/qemu-aarch64-static ${OUTPUT_ROOT}/rootfs/usr/bin/
  1079.  
  1080. #### unmounting
  1081. echo -e " Syncing rootfs."
  1082. sudo sync
  1083. echo -e " unmounting rootfs."
  1084. sudo umount ${OUTPUT_ROOT}/rootfs
  1085.  
  1086. echo
  1087. echo -e " END: build_chroot_filesystem "
  1088. echo -e "##############################"
  1089. echo
  1090. }
  1091.  
  1092. chroot_jail_run () {
  1093. echo
  1094. echo -e "#################"
  1095. echo -e " chroot_jail_run "
  1096. echo
  1097. cd ${APP_ROOT}
  1098. echo -e " Getting my full mount on.. "
  1099. sudo mount -o loop ${OUTPUT_ROOT}/rootfs.img ${OUTPUT_ROOT}/rootfs
  1100. sudo mount -o bind /proc ${OUTPUT_ROOT}/rootfs/proc
  1101. sudo mount -o bind /sys ${OUTPUT_ROOT}/rootfs/sys
  1102. sudo mount -o bind /dev ${OUTPUT_ROOT}/rootfs/dev
  1103. sudo mount -o bind /dev/pts ${OUTPUT_ROOT}/rootfs/dev/pts
  1104. while true; do
  1105. read -n1 -p $'\nchroot (A)utorun script, (M)anual mode or (B)ack out? [a/m/b]' yn
  1106. case $yn in
  1107. [Aa]* ) echo -e "\n ch'rooting in full auto! "; sudo chroot ${OUTPUT_ROOT}/rootfs/ bash -c "./99.ChrootScript.sh"; break;;
  1108. [Mm]* ) echo -e "\n manual ch'root. Type 'exit' to quit "; sudo chroot ${OUTPUT_ROOT}/rootfs/; break;;
  1109. [Bb]* ) echo -e "\n\n** Shiittt!! *unmounting everything* - you'll probably want to quit on next question! **\n"; break;;
  1110. * ) echo -e "\n(Aa)utorun, (Mm)anual or (Bb)ack out";;
  1111. esac
  1112. done
  1113. echo -e " Syncing rootfs."
  1114. sudo sync
  1115. echo -e " unmount; Climbing off, and flushing the evidence.."
  1116. sudo umount ${OUTPUT_ROOT}/rootfs/dev/pts
  1117. sudo umount ${OUTPUT_ROOT}/rootfs/dev
  1118. sudo umount ${OUTPUT_ROOT}/rootfs/proc
  1119. sudo umount ${OUTPUT_ROOT}/rootfs/sys
  1120. sudo umount ${OUTPUT_ROOT}/rootfs
  1121. echo
  1122. echo -e " END: chroot_jail_run "
  1123. echo -e "######################"
  1124. echo
  1125. }
  1126.  
  1127. chroot_jail_mkinitrfs () {
  1128. echo
  1129. echo -e "#######################"
  1130. echo -e " chroot_jail_mkinitrfs "
  1131. echo
  1132. cd ${APP_ROOT}
  1133. echo -e " Getting my full mount on.. "
  1134. echo
  1135. sudo mount -o loop ${OUTPUT_ROOT}/rootfs.img ${OUTPUT_ROOT}/rootfs
  1136. sudo mount -o bind /proc ${OUTPUT_ROOT}/rootfs/proc
  1137. sudo mount -o bind /sys ${OUTPUT_ROOT}/rootfs/sys
  1138. sudo mount -o bind /dev ${OUTPUT_ROOT}/rootfs/dev
  1139. sudo mount -o bind /dev/pts ${OUTPUT_ROOT}/rootfs/dev/pts
  1140.  
  1141. sudo cp -a /usr/bin/qemu-aarch64-static ${OUTPUT_ROOT}/rootfs/usr/bin/
  1142. sudo chroot ${OUTPUT_ROOT}/rootfs/ mkinitramfs -o /boot/initrd.img $(cat ${OUTPUT_ROOT}/linux-version)
  1143. cp ${OUTPUT_ROOT}/rootfs/boot/initrd.img ${OUTPUT_ROOT}/initrd.img
  1144. sudo rm -f ${OUTPUT_ROOT}/rootfs/boot/initrd.img
  1145. sudo rm -f ${OUTPUT_ROOT}/rootfs/usr/bin/qemu-aarch64-static
  1146.  
  1147. echo -e " Syncing rootfs."
  1148. sudo sync
  1149. echo -e " unmount; Climbing off, and flushing the evidence.."
  1150. sudo umount ${OUTPUT_ROOT}/rootfs/dev/pts
  1151. sudo umount ${OUTPUT_ROOT}/rootfs/dev
  1152. sudo umount ${OUTPUT_ROOT}/rootfs/proc
  1153. sudo umount ${OUTPUT_ROOT}/rootfs/sys
  1154. sudo umount ${OUTPUT_ROOT}/rootfs
  1155. echo
  1156. echo -e " END: chroot_jail_mkinitrfs "
  1157. echo -e "############################"
  1158. echo
  1159. }
  1160.  
  1161. build_firmware_image () {
  1162. echo
  1163. echo -e "######################"
  1164. echo -e " build_firmware_image "
  1165. echo
  1166. cd ${APP_ROOT}
  1167. echo -e " Copying over DTB, kernel Image, U-Boot bins and config files"
  1168. echo
  1169. cp ${COMPONENT_ROOT}/linux-kernel/arch/arm64/boot/dts/amlogic/$MY_DTB ${OUTPUT_ROOT}
  1170. cp ${COMPONENT_ROOT}/linux-kernel/arch/arm64/boot/Image ${OUTPUT_ROOT}/Image
  1171. cp ${COMPONENT_ROOT}/u-boot/fip/u-boot.bin ${OUTPUT_ROOT}/u-boot.bin
  1172. cp ${COMPONENT_ROOT}/u-boot/fip/u-boot.bin.sd.bin ${OUTPUT_ROOT}/u-boot.bin.sd.bin
  1173. cp ${COMPONENT_ROOT}/u-boot/fip/u-boot.bin.usb.bl2 ${OUTPUT_ROOT}/u-boot.bin.usb.bl2
  1174. cp ${COMPONENT_ROOT}/u-boot/fip/u-boot.bin.usb.tpl ${OUTPUT_ROOT}/u-boot.bin.usb.tpl
  1175. cp ${SCRIPT_ROOT}/img-pack-cfg/aml_sdc_burn.ini ${OUTPUT_ROOT}/aml_sdc_burn.ini
  1176. cp ${SCRIPT_ROOT}/img-pack-cfg/platform.conf ${OUTPUT_ROOT}/platform.conf
  1177.  
  1178. #### Make the images image!
  1179. echo -e " Making the images/logo package"
  1180. echo
  1181. #### first copy all the images we want to the correct label they need.
  1182. cp ${COMPONENT_ROOT}/logo/skull720.bmp ${OUTPUT_ROOT}/addtoimage/bootup.bmp
  1183. cp ${COMPONENT_ROOT}/logo/upgrade_error.bmp ${OUTPUT_ROOT}/addtoimage/upgrade_error.bmp
  1184. cp ${COMPONENT_ROOT}/logo/upgrade_logo.bmp ${OUTPUT_ROOT}/addtoimage/upgrade_logo.bmp
  1185. cp ${COMPONENT_ROOT}/logo/upgrade_unfocus.bmp ${OUTPUT_ROOT}/addtoimage/upgrade_unfocus.bmp
  1186. cp ${COMPONENT_ROOT}/logo/upgrade_bar.bmp ${OUTPUT_ROOT}/addtoimage/upgrade_bar.bmp
  1187. cp ${COMPONENT_ROOT}/logo/upgrade_fail.bmp ${OUTPUT_ROOT}/addtoimage/upgrade_fail.bmp
  1188. cp ${COMPONENT_ROOT}/logo/upgrade_success.bmp ${OUTPUT_ROOT}/addtoimage/upgrade_success.bmp
  1189. cp ${COMPONENT_ROOT}/logo/upgrade_upgrading.bmp ${OUTPUT_ROOT}/addtoimage/upgrade_upgrading.bmp
  1190. #### Now image all those files to the logo.img packaged file.
  1191. ${COMPONENT_ROOT}/utils/logo_img_packer -r ${OUTPUT_ROOT}/addtoimage ${OUTPUT_ROOT}/logo.img
  1192.  
  1193. echo
  1194. echo -e " Making the ramdisk image "
  1195. FINAL_IMG_FOLDER="/media/raxy/ext3part/SBC-Images"
  1196.  
  1197. ${COMPONENT_ROOT}/utils/mkbootimg --kernel ${OUTPUT_ROOT}/Image --ramdisk ${OUTPUT_ROOT}/initrd.img -o ${OUTPUT_ROOT}/ramdisk.img
  1198. echo
  1199.  
  1200. ${COMPONENT_ROOT}/utils/aml_image_v2_packer -r ${SCRIPT_ROOT}/img-pack-cfg/package.conf ${OUTPUT_ROOT}/ ${FINAL_IMG_FOLDER}/update.img
  1201. mv ${FINAL_IMG_FOLDER}/update.img ${FINAL_IMG_FOLDER}/kVimEmmc-`cat ${OUTPUT_ROOT}/linux-version`-`date +"%Y%m%d%H%M"`.img
  1202.  
  1203. echo
  1204. echo -e " END: build_firmware_image "
  1205. echo -e "###########################"
  1206. echo
  1207. }
  1208.  
  1209. ###### SUPPORT FUNCTIONS! ######
  1210. anykey (){
  1211. $1
  1212. echo -e "I'll just wait here while you go and check shall I?"
  1213. read -n1 -rsp $'Press any key to continue ...\n'
  1214. }
  1215.  
  1216. question () {
  1217. while true; do
  1218. read -n1 -p $'\nDo you need to run '$1'? [y/n/q]' yn
  1219. case $yn in
  1220. [Yy]* ) $1; return;;
  1221. [Nn]* ) return;;
  1222. [Qq]* ) echo -e "\n(X) Good Bye."; exit;;
  1223. * ) echo -e "\n(Yy)es, (Nn)o or (Qq)uit";;
  1224. esac
  1225. done
  1226. }
  1227. ###### END SUPPORT FUNCTIONS! ######
  1228.  
  1229. ###### HERE WE GO - KoalaFarts! ######
  1230. question system_setup_aptget
  1231. question system_setup_gitgetuboot
  1232. question system_setup_gitgetkern
  1233. question system_setup_ubuntu-base
  1234. question system_setup_logo-bmp
  1235. anykey general_question_hdmi
  1236. anykey general_question_macaddr
  1237. question compile_firmware_u-boot
  1238. question compile_software_kernel
  1239. question build_chroot_filesystem
  1240. question chroot_jail_run
  1241. question chroot_jail_mkinitrfs
  1242. question build_firmware_image
  1243. echo -e "\nthis is the END!\n"
  1244. cd ${SCRIPT_ROOT}
  1245. ###### the end! ######
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement