Home | History | Annotate | Download | only in chromeos
      1 #!/bin/bash
      2 set -e -o pipefail
      3 
      4 # This script copies a locally built GLIBC to a remote device.
      5 #
      6 # Usage: push_glibc <target>...
      7 #
      8 # This script works with 64-bit (amd64 or arm64) ChromeOS targets.
      9 # It copies both 32-bit and 64-bit glibc loaders onto the device.
     10 # This allows loading and running both 32-bit and 64-bit binaries
     11 # on the same device.
     12 
     13 for target in "$@"
     14 do
     15 	echo -n "pushing glibc to ${target} ... "
     16 	case "$(ssh ${target} uname -m)" in
     17 		x86_64)
     18 			glibc="/usr/x86_64-cros-linux-gnu/lib64"
     19 			loader="ld-linux-x86-64.so.2"
     20 			glibc32="/usr/i686-pc-linux-gnu/lib"
     21 			loader32="ld-linux.so.2"
     22 			;;
     23 		aarch64)
     24 			glibc="/usr/aarch64-cros-linux-gnu/lib64"
     25 			loader="ld-linux-aarch64.so.1"
     26 			glibc32="/usr/armv7a-cros-linux-gnueabi/lib"
     27 			loader32="ld-linux-armhf.so.3"
     28 			;;
     29 		*)
     30 			echo "unknown arch"
     31 			continue
     32 			;;
     33 	esac
     34 
     35 	target_sh ${target} "rm -rf /tmp/glibc"
     36 	target_sh ${target} "mkdir -p /tmp/glibc"
     37 	target_cp "${glibc}" ${target}:/tmp/glibc
     38 
     39 	target_sh ${target} "rm -rf /tmp/glibc32"
     40 	target_sh ${target} "mkdir -p /tmp/glibc32"
     41 	target_cp "${glibc32}" ${target}:/tmp/glibc32
     42 
     43 	echo "#!/bin/bash" > /tmp/ld.so
     44 	echo "LD_LIBRARY_PATH=/tmp/glibc/${glibc##*/} exec /tmp/glibc/${glibc##*/}/${loader} \"\$@\"" >> /tmp/ld.so
     45 	chmod +x /tmp/ld.so
     46 	target_cp /tmp/ld.so ${target}:/tmp/glibc
     47 	rm /tmp/ld.so
     48 
     49 	echo "#!/bin/bash" > /tmp/ld.so
     50 	echo "LD_LIBRARY_PATH=/tmp/glibc32/${glibc32##*/} exec /tmp/glibc32/${glibc32##*/}/${loader32} \"\$@\"" >> /tmp/ld.so
     51 	chmod +x /tmp/ld.so
     52 	target_cp /tmp/ld.so ${target}:/tmp/glibc32
     53 	rm /tmp/ld.so
     54 
     55 	echo "done"
     56 done
     57