Advertisement
Guest User

Chromebook2.ARM.Samsung.sh

a guest
Jan 20th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 13.75 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [[ $# -eq 0 ]] ; then
  4.     echo "Please pass version number, e.g. $0 1.0.1"
  5.     exit 0
  6. fi
  7.  
  8. basedir=`pwd`/chromebook2-$1
  9.  
  10. # Make sure that the cross compiler can be found in the path before we do
  11. # anything else, that way the builds don't fail half way through.
  12. export CROSS_COMPILE=arm-linux-gnueabihf-
  13. if [ $(compgen -c $CROSS_COMPILE | wc -l) -eq 0 ] ; then
  14.     echo "Missing cross compiler. Set up PATH according to the README"
  15.     exit 1
  16. fi
  17. # Unset CROSS_COMPILE so that if there is any native compiling needed it doesn't
  18. # get cross compiled.
  19. unset CROSS_COMPILE
  20.  
  21. # Package installations for various sections.
  22. # This will build a minimal Gnome Kali system with the top 10 tools.
  23. # This is the section to edit if you would like to add more packages.
  24. # See http://www.kali.org/new/kali-linux-metapackages/ for meta packages you can
  25. # use.  You can also install packages, using just the package name, but keep in
  26. # mind that not all packages work on ARM! If you specify one of those, the
  27. # script will throw an error, but will still continue on, and create an unusable
  28. # image, keep that in mind.
  29.  
  30. arm="abootimg cgpt fake-hwclock ntpdate vboot-utils vboot-kernel-utils uboot-mkimage"
  31. base="kali-menu kali-defaults initramfs-tools usbutils"
  32. desktop="gdm3 gnome-core gnome-brave-icon-theme gnome-orca gnome-shell-extensions kali-root-login xserver-xorg-video-fbdev"
  33. tools="passing-the-hash winexe aircrack-ng hydra john sqlmap wireshark libnfc-bin mfoc"
  34. services="openssh-server apache2"
  35. extras="iceweasel wpasupplicant"
  36.  
  37. export packages="${arm} ${base} ${desktop} ${tools} ${services} ${extras}"
  38. export architecture="armhf"
  39. # If you have your own preferred mirrors, set them here.
  40. # You may want to leave security.kali.org alone, but if you trust your local
  41. # mirror, feel free to change this as well.
  42. # After generating the rootfs, we set the sources.list to the default settings.
  43. export mirror=http.kali.org
  44. export security=security.kali.org
  45.  
  46. # Set this to use an http proxy, like apt-cacher-ng, and uncomment further down
  47. # to unset it.
  48. #export http_proxy="http://localhost:3142/"
  49.  
  50. mkdir -p ${basedir}
  51. cd ${basedir}
  52.  
  53. # create the rootfs - not much to modify here, except maybe the hostname.
  54. debootstrap --foreign --arch $architecture kali kali-$architecture http://$mirror/kali
  55.  
  56. cp /usr/bin/qemu-arm-static kali-$architecture/usr/bin/
  57.  
  58. LANG=C chroot kali-$architecture /debootstrap/debootstrap --second-stage
  59.  
  60. # Create sources.list
  61. cat << EOF > kali-$architecture/etc/apt/sources.list
  62. deb http://$mirror/kali kali main contrib non-free
  63. deb http://$security/kali-security kali/updates main contrib non-free
  64. EOF
  65.  
  66. # Set hostname
  67. echo "kali" > kali-$architecture/etc/hostname
  68.  
  69. # So X doesn't complain, we add kali to hosts
  70. cat << EOF > kali-$architecture/etc/hosts
  71. 127.0.0.1       kali    localhost
  72. ::1             localhost ip6-localhost ip6-loopback
  73. fe00::0         ip6-localnet
  74. ff00::0         ip6-mcastprefix
  75. ff02::1         ip6-allnodes
  76. ff02::2         ip6-allrouters
  77. EOF
  78.  
  79. cat << EOF > kali-$architecture/etc/network/interfaces
  80. auto lo
  81. iface lo inet loopback
  82. EOF
  83.  
  84. cat << EOF > kali-$architecture/etc/resolv.conf
  85. nameserver 8.8.8.8
  86. EOF
  87.  
  88. export MALLOC_CHECK_=0 # workaround for LP: #520465
  89. export LC_ALL=C
  90. export DEBIAN_FRONTEND=noninteractive
  91.  
  92. mount -t proc proc kali-$architecture/proc
  93. mount -o bind /dev/ kali-$architecture/dev/
  94. mount -o bind /dev/pts kali-$architecture/dev/pts
  95.  
  96. cat << EOF > kali-$architecture/debconf.set
  97. console-common console-data/keymap/policy select Select keymap from full list
  98. console-common console-data/keymap/full select en-latin1-nodeadkeys
  99. EOF
  100.  
  101. cat << EOF > kali-$architecture/third-stage
  102. #!/bin/bash
  103. dpkg-divert --add --local --divert /usr/sbin/invoke-rc.d.chroot --rename /usr/sbin/invoke-rc.d
  104. cp /bin/true /usr/sbin/invoke-rc.d
  105. echo -e "#!/bin/sh\nexit 101" > /usr/sbin/policy-rc.d
  106. chmod +x /usr/sbin/policy-rc.d
  107.  
  108. apt-get update
  109. apt-get install locales-all
  110.  
  111. debconf-set-selections /debconf.set
  112. rm -f /debconf.set
  113. apt-get update
  114. apt-get -y install git-core binutils ca-certificates initramfs-tools uboot-mkimage
  115. apt-get -y install locales console-common less nano git
  116. echo "root:toor" | chpasswd
  117. sed -i -e 's/KERNEL\!=\"eth\*|/KERNEL\!=\"/' /lib/udev/rules.d/75-persistent-net-generator.rules
  118. rm -f /etc/udev/rules.d/70-persistent-net.rules
  119. apt-get --yes --force-yes install $packages
  120.  
  121. rm -f /usr/sbin/policy-rc.d
  122. rm -f /usr/sbin/invoke-rc.d
  123. dpkg-divert --remove --rename /usr/sbin/invoke-rc.d
  124.  
  125. rm -f /third-stage
  126. EOF
  127.  
  128. chmod +x kali-$architecture/third-stage
  129. LANG=C chroot kali-$architecture /third-stage
  130.  
  131. cat << EOF > kali-$architecture/cleanup
  132. #!/bin/bash
  133. rm -rf /root/.bash_history
  134. apt-get update
  135. apt-get clean
  136. rm -f /0
  137. rm -f /hs_err*
  138. rm -f cleanup
  139. rm -f /usr/bin/qemu*
  140. EOF
  141.  
  142. chmod +x kali-$architecture/cleanup
  143. LANG=C chroot kali-$architecture /cleanup
  144.  
  145. umount kali-$architecture/proc/sys/fs/binfmt_misc
  146. umount kali-$architecture/dev/pts
  147. umount kali-$architecture/dev/
  148. umount kali-$architecture/proc
  149.  
  150. echo "Creating image file for Chromebook2"
  151. dd if=/dev/zero of=${basedir}/kali-$1-chromebook2.img bs=1M count=7000
  152. parted kali-$1-chromebook2.img --script -- mklabel gpt
  153. cgpt create -z kali-$1-chromebook2.img
  154. cgpt create kali-$1-chromebook2.img
  155.  
  156. cgpt add -i 1 -t kernel -b 8192 -s 32768 -l U-Boot -S 1 -T 5 -P 10 kali-$1-chromebook2.img
  157. cgpt add -i 2 -t data -b 40960 -s 32768 -l Kernel kali-$1-chromebook2.img
  158. cgpt add -i 12 -t data -b 73728 -s 32768 -l Script kali-$1-chromebook2.img
  159. cgpt add -i 3 -t data -b 106496 -s `expr $(cgpt show kali-$1-chromebook2.img | grep 'Sec GPT table' | awk '{ print \$1 }')  - 106496` -l Root kali-$1-chromebook2.img
  160.  
  161. loopdevice=`losetup -f --show ${basedir}/kali-$1-chromebook2.img`
  162. device=`kpartx -va $loopdevice| sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
  163. device="/dev/mapper/${device}"
  164. bootp=${device}p2
  165. rootp=${device}p3
  166. scriptp=${device}p12
  167. ubootp=${device}p1
  168.  
  169. mkfs.ext2 $bootp
  170. mkfs.ext4 $rootp
  171. mkfs.vfat -F 16 $scriptp
  172.  
  173. mkdir -p ${basedir}/bootp ${basedir}/root ${basedir}/script
  174. mount $bootp ${basedir}/bootp
  175. mount $rootp ${basedir}/root
  176. mount $scriptp ${basedir}/script
  177.  
  178. echo "Rsyncing rootfs into image file"
  179. rsync -HPavz -q ${basedir}/kali-$architecture/ ${basedir}/root/
  180.  
  181. cat << EOF > ${basedir}/root/etc/apt/sources.list
  182. deb http://http.kali.org/kali kali main non-free contrib
  183. deb http://security.kali.org/kali-security kali/updates main contrib non-free
  184.  
  185. deb-src http://http.kali.org/kali kali main non-free contrib
  186. deb-src http://security.kali.org/kali-security kali/updates main contrib non-free
  187. EOF
  188.  
  189. # Uncomment this if you use apt-cacher-ng otherwise git clones will fail.
  190. #unset http_proxy
  191.  
  192. # Kernel section.  If you want to use a custom kernel, or configuration, replace
  193. # them in this section. Currently we're using 3.4, but there will be a switch to
  194. # 3.8.
  195. #git clone --depth 1 http://chromium.googlesource.com/chromiumos/third_party/kernel.git -b chromeos-3.4 ${basedir}/kernel
  196. #git clone --depth 1 http://chromium.googlesource.com/chromiumos/third_party/kernel.git -b chromeos-3.8 ${basedir}/kernel
  197. #Official ChromeOS Kernel for Peach Pi
  198. git clone --deptch 1 https://chromium.googlesource.com/chromiumos/third_party/kernel.git -b release-R40-6457.B-chromeos-3.8 ${basedir}/kernel
  199. cd ${basedir}/kernel
  200. cp ${basedir}/../kernel-configs/chromebook2-3.8.config .config
  201. export ARCH=arm
  202. # Edit the CROSS_COMPILE variable as needed.
  203. export CROSS_COMPILE=arm-linux-gnueabihf-
  204. mkdir -p ../patches
  205. #wget https://raw.github.com/offensive-security/kali-arm-build-scripts/master/patches/kali-wifi-injection-3.12.patch -O ../patches/mac80211.patch
  206. wget http://patches.aircrack-ng.org/mac80211.compat08082009.wl_frag+ack_v1.patch -O ../patches/mac80211.patch
  207. patch -p1 --no-backup-if-mismatch < ../patches/mac80211.patch
  208. # sed -i 's/CONFIG_ERROR_ON_WARNING=y/# CONFIG_ERROR_ON_WARNING is not set/g' .config
  209. make -j $(grep -c processor /proc/cpuinfo)
  210. make dtbs
  211. make modules_install INSTALL_MOD_PATH=${basedir}/root
  212. #Modified for Peach Pi
  213. cat << __EOF__ > ${basedir}/kernel/arch/arm/boot/kernel-peach-pi.its
  214. /dts-v1/;
  215.  
  216. / {
  217.     description = "Chrome OS kernel image with one or more FDT blobs";
  218.     #address-cells = <1>;
  219.     images {
  220.         kernel@1{
  221.             description = "kernel";
  222.             data = /incbin/("zImage");
  223.             type = "kernel_noload";
  224.             arch = "arm";
  225.             os = "linux";
  226.             compression = "none";
  227.             load = <0>;
  228.             entry = <0>;
  229.         };
  230. fdt@1{
  231.             description = "exynos5422-peach-pi.dtb";
  232.             data = /incbin/("dts/exynos5422-peach-pi.dtb");
  233.             type = "flat_dt";
  234.             arch = "arm";
  235.             compression = "none";
  236.             hash@1{
  237.                 algo = "sha1";
  238.             };
  239.         };
  240.     };
  241.     configurations {
  242.         default = "conf@1";
  243. conf@1{
  244.             description = "exynos5422-peach-pi.dtb";
  245.             kernel = "kernel@1";
  246.             fdt = "fdt@1";
  247.         };
  248.     };
  249. };
  250. __EOF__
  251. cd ${basedir}/kernel/arch/arm/boot
  252. #Modified for Peach Pi
  253. mkimage -f kernel-peach-pi.its ${basedir}/bootp/vmlinux.uimg
  254. cd ${basedir}
  255.  
  256. # Create boot.txt file
  257. mkdir ${basedir}/script/u-boot/
  258. cat << EOF > ${basedir}/script/u-boot/boot.txt
  259. setenv bootpart 3
  260. setenv rootpart 2
  261. setenv regen_ext2_bootargs 'setenv bootdev_bootargs root=/dev/\${devname}\${bootpart} quiet rootfstype=ext4 rootwait rw lsm.module_locking=0; run regen_all'
  262. setenv cros_bootfile /vmlinux.uimg
  263. setenv extra_bootargs console=tty1
  264. setenv mmc0_boot echo ERROR: Could not boot from USB or SD
  265. EOF
  266.  
  267. # Create u-boot boot script image
  268. mkimage -A arm -T script -C none -d ${basedir}/script/u-boot/boot.txt ${basedir}/script/u-boot/boot.scr.uimg
  269.  
  270. # Touchpad configuration
  271. mkdir -p ${basedir}/root/etc/X11/xorg.conf.d
  272. cat << EOF > ${basedir}/root/etc/X11/xorg.conf.d/10-synaptics-chromebook.conf
  273. Section "InputClass"
  274.     Identifier  "touchpad"
  275.     MatchIsTouchpad "on"
  276.     Driver  "synaptics"
  277.     Option  "TapButton1"    "1"
  278.     Option  "TapButton2"    "3"
  279.     Option  "TapButton3"    "2"
  280.     Option  "FingerLow" "15"
  281.     Option  "FingerHigh"    "20"
  282.     Option  "FingerPress"   "256"
  283. EndSection
  284. EOF
  285. # Turn off DPMS, this is supposed to help with fbdev/armsoc blanking.
  286. # Doesn't really seem to affect fbdev, but marked improvement with armsoc.
  287. cat << EOF > ${basedir}/root/etc/X11/xorg.conf
  288. Section "ServerFlags"
  289.     Option     "NoTrapSignals" "true"
  290.     Option     "DontZap" "false"
  291.  
  292.     # Disable DPMS timeouts.
  293.     Option     "StandbyTime" "0"
  294.     Option     "SuspendTime" "0"
  295.     Option     "OffTime" "0"
  296.  
  297.     # Disable screen saver timeout.
  298.     Option     "BlankTime" "0"
  299. EndSection
  300.  
  301. Section "Monitor"
  302.     Identifier "DefaultMonitor"
  303. EndSection
  304.  
  305. Section "Device"
  306.     Identifier "DefaultDevice"
  307.     Option     "monitor-LVDS1" "DefaultMonitor"
  308. EndSection
  309.  
  310. Section "Screen"
  311.     Identifier "DefaultScreen"
  312.     Monitor    "DefaultMonitor"
  313.     Device     "DefaultDevice"
  314. EndSection
  315.  
  316. Section "ServerLayout"
  317.     Identifier "DefaultLayout"
  318.     Screen     "DefaultScreen"
  319. EndSection
  320. EOF
  321.  
  322. # At the moment we use fbdev, but in the future, we will switch to the armsoc
  323. # driver provided by ChromiumOS.
  324. cat << EOF > ${basedir}/root/etc/X11/xorg.conf.d/20-armsoc.conf
  325. Section "Device"
  326.         Identifier      "Mali FBDEV"
  327. #       Driver          "armsoc"
  328.     Driver  "fbdev"
  329.         Option          "fbdev"                 "/dev/fb0"
  330.         Option          "Fimg2DExa"             "false"
  331.         Option          "DRI2"                  "true"
  332.         Option          "DRI2_PAGE_FLIP"        "false"
  333.         Option          "DRI2_WAIT_VSYNC"       "true"
  334. #       Option          "Fimg2DExaSolid"        "false"
  335. #       Option          "Fimg2DExaCopy"         "false"
  336. #       Option          "Fimg2DExaComposite"    "false"
  337.         Option          "SWcursorLCD"           "false"
  338. EndSection
  339.  
  340. Section "Screen"
  341.         Identifier      "DefaultScreen"
  342.         Device          "Mali FBDEV"
  343.         DefaultDepth    24
  344. EndSection
  345. EOF
  346.  
  347. rm -rf ${basedir}/root/lib/firmware
  348. cd ${basedir}/root/lib
  349. git clone https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git firmware
  350. rm -rf ${basedir}/root/lib/firmware/.git
  351. cd ${basedir}
  352.  
  353. # Unmount partitions
  354. umount $bootp
  355. umount $rootp
  356. umount $scriptp
  357.  
  358. # This is the u-boot bootloader that gets written to the first partition. When
  359. # you hit CTRL+U, this is what gets read first.  If you want to customize your
  360. # u-boot in some way, you will need to read the ChromiumOS dev wiki.
  361. # http://www.chromium.org/chromium-os/developer-guide
  362. # Modified for Peach Pi
  363. wget -O - http://linux-exynos.org/dist/chromebook/nv_uboot/nv_uboot-peach-pi.kpart > nv_uboot-peach-pi.kpart
  364. dd if=nv_uboot-peach-pi.kpart of=$ubootp
  365.  
  366. kpartx -dv $loopdevice
  367. losetup -d $loopdevice
  368.  
  369. # Clean up all the temporary build stuff and remove the directories.
  370. # Comment this out to keep things around if you want to see what may have gone
  371. # wrong.
  372. echo "Removing temporary build files"
  373. rm -rf ${basedir}/kernel ${basedir}/bootp ${basedir}/root ${basedir}/kali-$architecture ${basedir}/patches ${basedir}/nv_uboot-peach-pi.kpart ${basedir}/script
  374.  
  375. # If you're building an image for yourself, comment all of this out, as you
  376. # don't need the sha1sum or to compress the image, since you will be testing it
  377. # soon.
  378. echo "Generating sha1sum for kali-$1-chromebook2.img"
  379. sha1sum kali-$1-chromebook2.img > ${basedir}/kali-$1-chromebook2.img.sha1sum
  380. # Don't pixz on 32bit, there isn't enough memory to compress the images.
  381. MACHINE_TYPE=`uname -m`
  382. if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  383. echo "Compressing kali-$1-chromebook2.img"
  384. pixz ${basedir}/kali-$1-chromebook2.img ${basedir}/kali-$1-chromebook2.img.xz
  385. rm ${basedir}/kali-$1-chromebook2.img
  386. echo "Generating sha1sum for kali-$1-chromebook2.img.xz"
  387. sha1sum kali-$1-chromebook2.img.xz > ${basedir}/kali-$1-chromebook2.img.xz.sha1sum
  388. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement