install-cubox.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/usr/bin/env bash
  2. # This file is part of the OpenADK project. OpenADK is copyrighted
  3. # material, please see the LICENCE file in the top-level directory.
  4. if [ $(id -u) -ne 0 ];then
  5. echo "Installation is only possible as root"
  6. exit 1
  7. fi
  8. f=0
  9. for tool in parted sfdisk mkfs.ext4;do
  10. if ! which $tool >/dev/null; then
  11. echo "Checking if $tool is installed... failed"
  12. f=1
  13. fi
  14. done
  15. if [ $f -eq 1 ];then exit 1;fi
  16. datadir=0
  17. keep=0
  18. while getopts "dk" ch; do
  19. case $ch in
  20. d)
  21. datadir=1
  22. ;;
  23. k)
  24. keep=1
  25. ;;
  26. esac
  27. done
  28. shift $((OPTIND - 1))
  29. if [ -z $1 ];then
  30. echo "Please give your SD card device as first parameter"
  31. exit 1
  32. else
  33. if [ -z $2 ];then
  34. echo "Please give your install tar archive as second parameter"
  35. exit 1
  36. fi
  37. if [ -f $2 ];then
  38. echo "Installing $2 on $1"
  39. else
  40. echo "$2 is not a file, exiting"
  41. exit 1
  42. fi
  43. if [ -z $3 ];then
  44. echo "Please give your firmware directory as third parameter"
  45. exit 1
  46. fi
  47. if [ ! -d $3 ];then
  48. echo "$3 is not a directory, exiting"
  49. exit 1
  50. fi
  51. if [ -b $1 ];then
  52. echo "Using $1 as SD card disk for installation"
  53. echo "WARNING: This will destroy all data on $1 - type Yes to continue!"
  54. read y
  55. if [ "$y" = "Yes" ];then
  56. env LC_ALL=C sfdisk -l $1 2>&1 |grep 'No medium'
  57. if [ $? -eq 0 ];then
  58. echo "No medium found"
  59. exit 1
  60. else
  61. echo "Starting with installation"
  62. fi
  63. else
  64. echo "Exiting."
  65. exit 1
  66. fi
  67. else
  68. echo "Sorry $1 is not a block device"
  69. exit 1
  70. fi
  71. fi
  72. if [ $(mount | grep $1| wc -l) -ne 0 ];then
  73. echo "Block device $1 is in use, please umount first"
  74. exit 1
  75. fi
  76. maxsize=$(env LC_ALL=C parted $1 -s unit s print |awk '/^Disk/ { print $3 }'|sed -e 's/s//')
  77. rootsize=$(($maxsize-32768))
  78. echo "Install bootloader for cubox-i"
  79. parted -s $1 mklabel msdos
  80. dd if=${3}/SPL of=${1} bs=1K seek=1
  81. dd if=${3}/u-boot.img of=${1} bs=1K seek=42
  82. parted -s $1 unit s mkpart primary ext2 -- 2048 $rootsize
  83. parted -s $1 unit s mkpart primary fat32 $rootsize $maxsize
  84. sfdisk --change-id $1 2 88
  85. echo "Creating filesystem"
  86. mkfs.ext4 -q -O ^huge_file ${1}1
  87. sync
  88. tmp=$(mktemp -d)
  89. mount -t ext4 ${1}1 $tmp
  90. #echo "rootdev=/dev/mmcblk0p1" > $tmp/uEnv.txt
  91. #echo "kernel=/boot/kernel" >> $tmp/uEnv.txt
  92. #echo "dtb=/boot/imx6q-cubox-i.dtb" >> $tmp/uEnv.txt
  93. #echo 'kernelargs=rootwait console=ttymxc0 console=tty0 video=mxcfb0:dev=hdmi consoleblank=0' >> $tmp/uEnv.txt
  94. #echo 'sdargs=setenv bootargs root=${rootdev} ${kernelargs}' >> $tmp/uEnv.txt
  95. #echo 'sdloadk=load mmc 0:1 0x10800000 ${kernel}' >> $tmp/uEnv.txt
  96. #echo 'sdloadd=load mmc 0:1 0x18000000 ${dtb}' >> $tmp/uEnv.txt
  97. #echo 'sdboot=bootz 0x10800000 - 0x18000000' >> $tmp/uEnv.txt
  98. #echo 'bootit=echo Booting OpenADK' > $tmp/uEnv.txt
  99. echo "Extracting install archive"
  100. tar -C $tmp -xzpf $2
  101. echo "Fixing permissions"
  102. chmod 1777 $tmp/tmp
  103. chmod 4755 $tmp/bin/busybox
  104. cp ${3}/*.dtb $tmp/boot/
  105. umount $tmp
  106. echo "Successfully installed."
  107. exit 0