adt_installer 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. #!/bin/bash
  2. # Yocto ADT Installer
  3. #
  4. # Copyright 2010-2011 by Intel Corp.
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the "Software"), to deal
  8. # in the Software without restriction, including without limitation the rights
  9. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. # copies of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. usage ()
  22. {
  23. INST_ARCH=`uname -m`
  24. INST_OS=`uname -o| tr '[A-Z]' '[a-z]'`
  25. INST_KR=`uname -r| tr '[A-Z]' '[a-z]'`
  26. echo_info "#########################################################################"
  27. echo_info "# Welcome to Yocto Application Developement Tools (ADT) Installer"
  28. echo_info "# "
  29. echo_info "# Host Machine:\t\t\t\t"$INST_ARCH
  30. echo_info "# OS info:\t\t\t\t$INST_KR"
  31. echo_info "# Yocto ADT version to be installed:\t$YOCTOADT_VERSION"
  32. echo_info "# supported target architectures:\t$YOCTOADT_SUPPORTED_TARGETS"
  33. echo_info "# supported target root_fs images:\t$YOCTOADT_SUPPORTED_ROOTFS"
  34. echo_info "#########################################################################\n"
  35. echo_info "Systemwide installation. Installation will occur under $INSTALL_FOLDER\n"
  36. echo_info "############################################################################"
  37. echo_info "# Your system installation configurations from adt_installer.conf"
  38. echo_info "############################################################################"
  39. echo_info "# Cross toolchains:\t\t$YOCTOADT_TARGETS"
  40. echo_info "# Install Qemu:\t\t\t$YOCTOADT_QEMU"
  41. echo_info "# Install NFS utilities:\t$YOCTOADT_NFS_UTIL"
  42. #echo_info "# Install bitbake + UI:\t\t$YOCTOADT_BITBAKE"
  43. #echo_info "# Install metadata:\t$YOCTOADT_METADATA"
  44. #echo_info "############################################################################\n"
  45. echo_info "\n##############################################################################"
  46. echo_info "# Your rootfs image(s) and target sysroot selections from adt_installer.conf"
  47. echo_info "##############################################################################"
  48. prompt=1
  49. for arch_type in $YOCTOADT_TARGETS; do
  50. download_images $arch_type $prompt
  51. done
  52. echo_info "############################################################################\n"
  53. select_install_type
  54. }
  55. validate_config()
  56. {
  57. for selected_arch_type in $YOCTOADT_TARGETS; do
  58. found=0
  59. select_machine_var="\$YOCTOADT_TARGET_MACHINE_$selected_arch_type"
  60. select_machine=`eval echo $select_machine_var`
  61. show_error_banner=0
  62. for supported_arch_type in $YOCTOADT_SUPPORTED_TARGETS; do
  63. if [ "$selected_arch_type" == "$supported_arch_type" ]; then
  64. found=1
  65. break
  66. fi
  67. done
  68. if [ $found == 0 ]; then
  69. echo_info "[ADT_INST] Error: YOCTADT_TARGETS in adt_installer.conf contains invalid entries: $YOCTOADT_TARGETS. Valid values are: $YOCTOADT_SUPPORTED_TARGETS"
  70. show_error_banner=1
  71. elif [ -z "$select_machine" ]; then
  72. echo_info "[ADT_INST] Error: No MACHINE was defined for $selected_arch_type architecture! This is needed to install the toolchain and the correct environment settings."
  73. echo_info "[ADT_INST] To do that, in adt-installer.conf, set the following variable: YOCTOADT_TARGET_MACHINE_$selected_arch_type"
  74. show_error_banner=1
  75. fi
  76. if [ $show_error_banner == 1 ]; then
  77. echo -e "\n#############################################################################"
  78. echo -e "# Meet error(s) when installing Yocto ADT! Please check log file for details. "
  79. echo -e "#############################################################################\n"
  80. exit -1
  81. fi
  82. done
  83. for arch_type in $YOCTOADT_SUPPORTED_TARGETS; do
  84. #select_target_var="\$YOCTOADT_TARGET_$arch_type"
  85. #select_target=`eval echo $select_target_var`
  86. #if [ "$select_target" != "Y" ] || [ "$selected_target" != "y" ]; then
  87. # continue;
  88. #fi
  89. target_sysroot_image_var="\$YOCTOADT_TARGET_SYSROOT_IMAGE_$arch_type"
  90. target_sysroot_image=`eval echo $target_sysroot_image_var`
  91. select_rootfs_var="\$YOCTOADT_ROOTFS_$arch_type"
  92. select_rootfs=`eval echo $select_rootfs_var`
  93. if [ "$select_rootfs" == "" ] && [ "$target_sysroot_image" == "" ]; then
  94. continue;
  95. fi
  96. for image_type in $select_rootfs; do
  97. #validate rootfs type defined in YOCTOADT_ROOTFS_{ARCH} is valid and in YOCTOADT_SUPPORTED_ROOTFS
  98. found=0
  99. for supported_rootfs_type in $YOCTOADT_SUPPORTED_ROOTFS; do
  100. if [ "$image_type" == "$supported_rootfs_type" ]; then
  101. found=1
  102. break
  103. fi
  104. done
  105. if [ $found == 0 ]; then
  106. #the rootfs type listed for downloading is not valid
  107. echo_info "[ADT_INST] Error: Selected YOCTOADT_ROOTFS_$arch_type value: $image_type, is not valid! Valid values are: $YOCTOADT_SUPPORTED_ROOTFS "
  108. echo -e "\n#############################################################################"
  109. echo -e "# Meet error(s) when installing Yocto ADT! Please check log file for details. "
  110. echo -e "#############################################################################\n"
  111. exit -1
  112. fi
  113. done
  114. found=0
  115. for image_type in $select_rootfs; do
  116. #validate that rootfs to be extracted must be in the item: YOCTOADT_ROOTFS_${ARCH}
  117. if [ "$target_sysroot_image" == "$image_type" ]; then
  118. found=1
  119. break
  120. fi
  121. done
  122. # the rootfs image to be extracted is not selected
  123. if [ $found == 0 ]; then
  124. echo_info "[ADT_INST] Error: YOCTOADT_TARGET_SYSROOT_IMAGE_$arch_type selection: $target_sysroot_image is not included in YOCTOADT_ROOTFS_$arch_type selections: $select_rootfs"
  125. echo -e "\n#############################################################################"
  126. echo -e "# Meet error(s) when installing Yocto ADT! Please check log file for details. "
  127. echo -e "#############################################################################\n"
  128. exit -1
  129. fi
  130. done
  131. }
  132. #detect opkg installed or not, for installing sdk, we will use
  133. #this installed local opkg
  134. install_opkg()
  135. {
  136. if [ ! -x "$LOCAL_OPKG_LOC/bin/opkg" ]; then
  137. echo_info "OPKG is not setup, setting up opkg in local, which is required for installing yocto ADT...\n"
  138. if [ -d $LOCAL_OPKG_LOC ]; then
  139. echo_info "Deleting old OPKG folder, which doesn't contain executables... "
  140. rm -rf $LOCAL_OPKG_LOC
  141. fi
  142. parent_folder=`pwd`
  143. cd $LOCAL_OPKG_FOLDER
  144. check_result
  145. opkg_source_dir=`ls -d opkg-*`
  146. if [ $opkg_source_dir == "" ]; then
  147. echo_info "[ADT_INST] Error: OPKG source directory is not found!"
  148. echo -e "\n#############################################################################"
  149. echo -e "# Meet error(s) when installing Yocto ADT! Please check log file for details. "
  150. echo -e "#############################################################################\n"
  151. exit -1
  152. fi
  153. cd $opkg_source_dir
  154. check_result
  155. echo_info "Configure opkg ...\n"
  156. autoreconf -i
  157. ./configure --prefix=$parent_folder/$LOCAL_OPKG_LOC --enable-shared=no --disable-curl --disable-ssl-curl --disable-gpg >> $parent_folder/$YOCTOADT_INSTALL_LOG_FILE
  158. check_result
  159. echo_info "Make opkg ...\n"
  160. make &>> $parent_folder/$YOCTOADT_INSTALL_LOG_FILE
  161. check_result
  162. echo_info "Make Install opkg ...\n"
  163. make install &>> $parent_folder/$YOCTOADT_INSTALL_LOG_FILE
  164. #if meet error when installing opkg, cancel the installation
  165. check_result
  166. cd $parent_folder
  167. echo_info "Successfully installed OPKG.\n"
  168. fi
  169. }
  170. confirm_download()
  171. {
  172. #avoid repeated reminding
  173. if [ "$override_oldfile" == 1 ]; then
  174. return $pre_result
  175. else
  176. override_oldfile=1
  177. fi
  178. while true; do
  179. #echo_info "[ADT_INST] Files [$1] already exists. If you continue downloading, old files will be overrided."
  180. #echo_info "[ADT_INST] Further prompts will not be given if there're more existing files to be downloaded."
  181. #echo_info "[ADT_INST] Do you want to continue downloading? Please enter Y/N:"
  182. echo_info "\nFile [$1] already exists, which means you've downloaded the qemu kernel and rootfs file(s) before. If you choose continue downloading, old files will be overridden."
  183. echo_info "[ADT_INST] Do you want to continue downloading? Please enter Y/N:"
  184. read YOCTOADT_INSTALL
  185. YOCTOADT_INSTALL=`tr '[a-z]' '[A-Z]'<<<"$YOCTOADT_INSTALL"`
  186. if [ "$YOCTOADT_INSTALL" == "Y" ]; then
  187. pre_result=0
  188. return 0
  189. elif [ "$YOCTOADT_INSTALL" == "N" ]; then
  190. pre_result=1
  191. return 1
  192. fi
  193. done
  194. }
  195. download_file()
  196. {
  197. local filename=`echo ${1##*/}`
  198. if [ -f "$LOCAL_DOWNLOAD/$filename" ]; then
  199. confirm_download $filename
  200. result="$?"
  201. if [ ! "$result" == "0" ]; then
  202. return
  203. else
  204. echo "Removing old file [$1]"
  205. rm -rf "$LOCAL_DOWNLOAD/$filename"
  206. fi
  207. fi
  208. echo_info "Downloading file: $filename..."
  209. wget "$YOCTOADT_REPO/rootfs/$1" -P $LOCAL_DOWNLOAD --progress=bar:force 2>&1 | tee -a "$YOCTOADT_INSTALL_LOG_FILE"
  210. }
  211. #Need three input params:
  212. # $1 arch_type(arm powerpc x86 mips)
  213. # $2 machine(qemuarm beagleboard)
  214. # $3 rootfs_image_type (a list of sdk sato minimal lsb)
  215. get_image()
  216. {
  217. local machine=$2
  218. if [ "$1" == "x86" ] || [ "$1" == "x86_64" ]; then
  219. kernel="bzImage-$machine.bin"
  220. elif [ "$1" == "ppc" ] || [ "$1" == "mips" ]; then
  221. kernel="vmlinux-$machine.bin"
  222. else
  223. kernel="zImage-$machine.bin"
  224. fi
  225. #echo_info "[ADT_INST] Downloading qemu kernel binary: $qemu_kernel"
  226. download_file $machine/$kernel
  227. check_result
  228. for image_type in $select_rootfs; do
  229. #echo_info "[ADT_INST] Downloading rootfs file: core-image-$image_type-$machine.tar.bz2"
  230. filename="core-image-$image_type-$machine.tar.bz2"
  231. download_file $machine/$filename
  232. check_result
  233. done
  234. }
  235. download_images()
  236. {
  237. select_rootfs_var="\$YOCTOADT_ROOTFS_$1"
  238. select_sysroot_image_var="\$YOCTOADT_TARGET_SYSROOT_IMAGE_$1"
  239. select_sysroot_var="\$YOCTOADT_TARGET_SYSROOT_LOC_$1"
  240. select_machine_var="\$YOCTOADT_TARGET_MACHINE_$1"
  241. select_rootfs=`eval echo $select_rootfs_var`
  242. select_sysroot_image=`eval echo $select_sysroot_image_var`
  243. select_sysroot=`eval echo $select_sysroot_var`
  244. select_machine=`eval echo $select_machine_var`
  245. if [ -n "$select_sysroot" ]; then
  246. select_sysroot=`readlink -m $select_sysroot`
  247. fi
  248. if [ "$select_rootfs" != "" ]; then
  249. if [ $2 ]; then
  250. #echo_info "\n############################################################################"
  251. #echo_info "# To be downloaded rootfs image details defined in adt_installer.conf"
  252. #echo_info "############################################################################"
  253. echo_info "# Target architecture:\t\t$1"
  254. echo_info "# Target machine:\t\t$select_machine"
  255. echo_info "# Root_fs images:\t\t$select_rootfs"
  256. echo_info "# Target sysroot image:\t\t$select_sysroot_image"
  257. echo_info "# Target sysroot loc:\t\t$select_sysroot"
  258. echo_info "\n"
  259. #echo_info "############################################################################\n"
  260. else
  261. get_image $1 $select_machine $select_rootfs
  262. fi
  263. fi
  264. }
  265. #Main body of installer
  266. clear
  267. run_path=`dirname $0`
  268. cd $run_path
  269. if [ ! -f "scripts/util" ]; then
  270. echo -e "[ADT_INST] Error: Script file: util, can't be found under: $run_path!"
  271. echo -e "\n#############################################################################"
  272. echo -e "# Meet error(s) when installing Yocto ADT! Please check log file for details. "
  273. echo -e "#############################################################################\n"
  274. exit -1
  275. fi
  276. if [ ! -f "scripts/adt_installer_internal" ]; then
  277. echo -e "[ADT_INST] Error: Script file: adt_installer_internal, can't be found under: $run_path!"
  278. echo -e "\n#############################################################################"
  279. echo -e "# Meet error(s) when installing Yocto ADT! Please check log file for details. "
  280. echo -e "#############################################################################\n"
  281. exit -1
  282. fi
  283. config_file="adt_installer.conf"
  284. if [ ! -f "$config_file" ]; then
  285. echo_info "[ADT_INST] Error: Installation configuration file: adt_installer.conf is not found!\n"
  286. echo_info "\n##################################################################################"
  287. echo_info "# Meet error(s) when installing Yocto ADT. Please check log file for details. "
  288. echo_info "##################################################################################\n"
  289. exit -1
  290. fi
  291. . scripts/data_define
  292. . scripts/util
  293. if [ -f "$YOCTOADT_INSTALL_LOG_FILE" ]; then
  294. rm $YOCTOADT_INSTALL_LOG_FILE
  295. fi
  296. echo -n "Please enter the install location (default: $DEFAULT_INSTALL_FOLDER): "
  297. read INSTALL_FOLDER
  298. if [ "$INSTALL_FOLDER" = "" ]; then
  299. INSTALL_FOLDER=$DEFAULT_INSTALL_FOLDER
  300. fi
  301. eval INSTALL_FOLDER=$(printf "%q" "$INSTALL_FOLDER")
  302. if [ -d "$INSTALL_FOLDER" ]; then
  303. export INSTALL_FOLDER=$(cd "$INSTALL_FOLDER"; pwd)
  304. else
  305. export INSTALL_FOLDER=$(readlink -m "$INSTALL_FOLDER")
  306. fi
  307. if [ -n "$(echo $INSTALL_FOLDER|grep ' ')" ]; then
  308. echo "The target directory path ($INSTALL_FOLDER) contains spaces. Abort!"
  309. exit 1
  310. fi
  311. clear
  312. usage
  313. user_inst_type="$?"
  314. validate_config
  315. check_result
  316. #check adt_repo exist
  317. wget --spider $YOCTOADT_REPO 2>&1 | tee -a "$YOCTOADT_INSTALL_LOG_FILE"
  318. if grep -q "404 Not Found" $YOCTOADT_INSTALL_LOG_FILE; then
  319. echo -e "[ADT_INST] Error: YOCTOADT_REPO does not exist: $YOCTOADT_REPO"
  320. echo -e "\n#############################################################################"
  321. echo -e "# Meet error(s) when installing Yocto ADT! Please check log file for details. "
  322. echo -e "#############################################################################\n"
  323. exit -1
  324. fi
  325. #firstly we need to install opkg host
  326. install_opkg
  327. #Create folders for holding rootfs/qemu images
  328. if [ ! -d "$LOCAL_DOWNLOAD" ]; then
  329. echo_info "Creating new images downloading folder: $LOCAL_DOWNLOAD ..."
  330. mkdir -p $LOCAL_DOWNLOAD
  331. fi
  332. #downloading required qemu images/rootfs
  333. if [ "$user_inst_type" == "0" ]; then
  334. override_oldfile=1
  335. else
  336. override_oldfile=0
  337. fi
  338. for arch_type in $YOCTOADT_TARGETS; do
  339. download_images $arch_type
  340. done
  341. scripts/adt_installer_internal $user_inst_type
  342. result="$?"
  343. #echo_info "\n############################################################"
  344. if [ "$result" == "0" ]; then
  345. echo_info "\n############################################################"
  346. echo_info "# Yocto ADT has been successfully installed."
  347. echo_info "############################################################\n"
  348. fi