Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/system/busybox/sh
- #
- # runme_android_template.sh - template for updating android scripts
- #
- # Description:
- # ============
- # This is the foundation for the android part of an OTA update. It
- # needs to do a few things: Check that the file transfer happened
- # correctly, set up the device for a reboot into linux, and kick
- # off that reboot.
- #
- # This file contains a template for that script. Some parts are
- # replaced by code generated by the make_android_ota_package script.
- # Text marked by ***TEXT*** gets replaced.
- #
- # Modification History
- # ====================
- # 01a, 20150427, mfj Created
- # 01b, 20150916, mfj Updated to do most of the work from Android
- SCRIPTNAME=`basename $0`
- MD5SUM=***MD5SUM***
- LINUX_UPDATE_FILE=***LINUX_UPDATE_FILE***
- UPDATE_NAME=update_1.10.220_release.zip
- CREATION_DATE=2016-11-29
- UPDATE_NOTES="Version 1.10.220 release Build"
- VERSION_NUMBER=1.10.220
- MODEL_NAME="Olio Model One"
- OLIO_FOLDER="/data/media/0/olio/"
- TARGET_FOLDER="$OLIO_FOLDER/firmware_updates_apply"
- UPDATE_LINUX=false
- UPDATE_LINUX_PATH="firmware_updates_apply/$LINUX_UPDATE_FILE"
- FIRMWARE_MD5=""
- LINUX_BOOT="run ramfdtboot"
- # ---------------------------------------------------------------------------
- # FILES TO UPDATE
- BLUETOOTH_CLIENT="$TARGET_FOLDER/BluetoothClient-debug.apk"
- LOOKS="$TARGET_FOLDER/looks.zip"
- UIMAGE="$TARGET_FOLDER/uImage"
- UIMAGE_PARTITION="kernel"
- RAMFS="$TARGET_FOLDER/rootfs.cpio.uboot"
- RAMFS_PARTITION="initramfs"
- DTB="$TARGET_FOLDER/omap3_h1.dtb"
- DTB_PARTITION="devicetree"
- UBOOT="$TARGET_FOLDER/u-boot.img"
- UBOOT_PARTITION="U-Boot"
- DRV2605="$TARGET_FOLDER/drv2605.ko"
- ATMEL_CFG="$TARGET_FOLDER/atmel_cfg.raw"
- CHARGER_FW="$TARGET_FOLDER/charger_fw.bin" # TRICKY, how to do on Android?
- INITRC="$TARGET_FOLDER/init.h1.rc"
- FLASH_IMAGE="$TARGET_FOLDER/flash_image"
- POWER_HAL="$TARGET_FOLDER/power.h1.so"
- SERVICES_JAR="$TARGET_FOLDER/services.jar"
- OLIO_FB="$TARGET_FOLDER/olio_fb_setup.sh"
- # ===========================================================================
- # Result reporting
- # ===========================================================================
- report_fail ()
- {
- local testcase=$1
- local exectime=$2
- local date=`date +%Y-%m-%d_%H:%M`
- echo -e "==> RESULT | $testcase | FAIL | $exectime | $date"
- }
- report_success ()
- {
- local testcase=$1
- local exectime=$2
- local date=`date +%Y-%m-%d_%H:%M`
- echo -e "==> RESULT | $testcase | PASS | $exectime | $date"
- }
- # ---------------------------------------------------------------------------
- # update_bootlines
- #
- # Set the environment variables that are needed before reboot
- update_bootlines ()
- {
- echo "$0: Setting bootlines."
- fw_setenv bootcmd "$LINUX_BOOT"
- fw_setenv reboot_reason "SYS_UPDATE"
- fw_setenv update_file "$LINUX_UPDATE_FILE"
- report_success "bootlines updated." "1.0"
- }
- # ---------------------------------------------------------------------------
- # linux_update_prep
- #
- # In preparation for running the update on Linux, make the linux script
- # executable and place it in the right location
- linux_update_prep ()
- {
- mkdir -p $OLIO_FOLDER/update
- mv $TARGET_FOLDER/runme_linux.sh $OLIO_FOLDER/update/
- mv $TARGET_FOLDER/$LINUX_UPDATE_FILE $OLIO_FOLDER/
- chmod +x $OLIO_FOLDER/update/runme_linux.sh
- report_success "Prepared for low-level updates." "1.0"
- }
- # ---------------------------------------------------------------------------
- # check_md5_sum
- #
- # Check that file was properly transferred. This checks the linux update
- # portion only, since that hasn't been checked by the backend.
- check_md5_sum ()
- {
- local zipfile_md5=`/system/busybox/md5sum $TARGET_FOLDER/$LINUX_UPDATE_FILE | cut -f 1 -d " "`
- echo -n "$0: Verifying integrity of bundle ..."
- if [ "$zipfile_md5" != "$MD5SUM" ]
- then
- echo ""
- echo "$0: ERROR! Incorrect md5sum. Exiting."
- echo "$0: (Expected $MD5SUM, found $zipfile_md5)"
- echo "$0: Can't install update, "
- report_fail "md5 sum of included bundle is WRONG." "1.0"
- exit 0
- fi
- report_success "md5 sum of included bundle OK." "1.0"
- }
- # ---------------------------------------------------------------------------
- # get_md5_log
- #
- # This function finds the md5 for the full zip-file, used for recording this
- # update in the log file. TODO: What if an update fails to apply? Probably
- # the olio_fb_setup script should be smarter ... or maybe the update script
- # should be.
- calc_md5_sum ()
- {
- # Look for the first entry in firmware_next
- local firmware_bundle="$TARGET_FOLDER/../firmware_next/olio-firmware.zip"
- if [ -e $firmware_bundle ]
- then
- FIRMWARE_MD5=`/system/busybox/md5sum $firmware_bundle | cut -f 1 -d " "`
- else
- firmware_bundle="$TARGET_FOLDER/../temp/olio-firmware.zip"
- if [ -e $firmware_bundle ]
- then
- FIRMWARE_MD5=`/system/busybox/md5sum $firmware_bundle | cut -f 1 -d " "`
- else
- FIRMWARE_MD5="n/a"
- fi
- fi
- echo "firmware md5 sum is $firmware_md5"
- return
- }
- # ---------------------------------------------------------------------------
- # create_version_log
- #
- # We'll create a log entry which goes into two places - appended to a list of
- # changes that logs each software update, and a file that only contains the
- # latest entry.
- create_version_log ()
- {
- calc_md5_sum
- local hash=$FIRMWARE_MD5
- local current_date=`date +%Y-%m-%d`
- local log_string="$VERSION_NUMBER, $MODEL_NAME, $CREATION_DATE, $current_date, $hash, $UPDATE_NAME, \"$UPDATE_NOTES\""
- echo $log_string > $TARGET_FOLDER/../firmware_update_latest.txt
- echo $log_string >> $TARGET_FOLDER/../firmware_updates_applied.csv
- chmod 666 $TARGET_FOLDER/../firmware_update_latest.txt
- chmod 666 $TARGET_FOLDER/../firmware_update_latest.txt
- chown 1000:1000 $TARGET_FOLDER/../firmware_updates_applied.csv
- chown 1000:1000 $TARGET_FOLDER/../firmware_updates_applied.csv
- }
- # ---------------------------------------------------------------------------
- # set_path_permissions
- #
- # We've had issues sometimes when a path couldn't be accessed because the
- # permissions were wrong.
- #
- set_path_permissions ()
- {
- echo "$0: Setting permissions for all steps in $TARGET_FOLDER"
- chmod 771 /data
- chmod 770 /data/media
- chmod 770 /data/media/0
- chmod 775 /data/media/0/olio
- chmod 775 $TARGET_FOLDER
- chown 1023:1023 $TARGET_FOLDER
- }
- # ---------------------------------------------------------------------------
- # run_android_updates
- #
- # RUN FROM ANDROID!
- #
- # Install the Olio app. This can't be done until the system is done booting,
- # but we have no way of knowing when this is done. Hence we simply try again
- # until it works.
- # ---------------------------------------------------------------------------
- # install_apk_updates - install regular android packages
- # arg 1: apk with full path
- # arg 2: installed package name, e.g. com.olio.experiments
- install_apk_update ()
- {
- echo "$0: Installing $1"
- local install_package="$1"
- local uninstall_package="$2"
- # Make sure device stays awake during the update. This will get cleared out after a reboot
- echo m > /sys/power/wake_lock
- if [ -e $install_package ]
- then
- # Wait until the pm system is up and running
- RESULT=`/system/bin/pm list packages 2>&1 | /system/bin/grep "Error"`
- while [ "$RESULT" != "" ]
- do
- sleep 2
- RESULT=`/system/bin/pm list packages 2>&1 | /system/bin/grep "Error"`
- done
- # PM is running. Go ahead and do what we need to do.
- # Check whether it's installed in the first place.
- fi
- RESULT=`/system/bin/pm list packages | grep "$uninstall_package"`
- if [ "$RESULT" == "" ]
- then
- echo "$0: $uninstall_package not installed"
- else
- RESULT=`/system/bin/pm uninstall $uninstall_package 2>&1`
- RESULT=`echo $RESULT | /system/bin/grep "Error"`
- while [ "$RESULT" != "" ]
- do
- echo "Uninstall failed. Retrying\n" >> /system/vendor/fb_error.txt
- RESULT=`/system/bin/pm uninstall "$uninstall_package" 2>&1`
- echo -e "$RESULT \n" >> /system/vendor/fb_error.txt
- RESULT=`echo $RESULT | /system/bin/grep "Error"`
- sleep 1
- done
- fi
- echo "$0: $uninstall_package no longer on system, now installing $install_package"
- chmod 664 $install_package
- chown 1000:1000 $install_package
- RESULT=`/system/bin/pm install $install_package 2>&1`
- RESULT=`echo $RESULT | /system/bin/grep "Error"`
- while [ "$RESULT" != "" ]
- do
- echo "Install failed. Retrying\n" >> /system/vendor/fb_error.txt
- RESULT=`/system/bin/pm install $install_package 2>&1`
- echo -e "$RESULT \n" >> /system/vendor/fb_error.txt
- RESULT=`echo $RESULT | /system/bin/grep "Error"`
- sleep 1
- done
- }
- # ---------------------------------------------------------------------------
- # hwlib_update - update any hardware library.
- #
- # Argument: the library (with full path).
- hw_lib_update ()
- {
- local hwlib=$1
- chown 1000:1000 $hwlib
- chmod 775 $hwlib
- cp -p $hwlib /system/lib/hw/
- report_success "Installed $hwlib" "1.0"
- }
- # ---------------------------------------------------------------------------
- # android_apks_remove
- #
- # Remove apks that a) are included by Android default, and b) Olio doesn't
- # need. To keep things reversible, we're not actually removing them, just
- # copying them over to a safe location.
- android_apks_remove ()
- {
- privapp_to_remove="BackupRestoreConfirmation.apk BackupRestoreConfirmation.odex DefaultContainerService.apk DefaultContainerService.odex DownloadProvider.apk DownloadProvider.odex ExternalStorageProvider.apk ExternalStorageProvider.odex FusedLocation.apk FusedLocation.odex InputDevices.apk InputDevices.odex Keyguard.apk Keyguard.odex Launcher2.odex MediaProvider.apk MediaProvider.odex MusicFX.apk MusicFX.odex OneTimeInitializer.apk OneTimeInitializer.odex ProxyHandler.apk ProxyHandler.odex SharedStorageBackup.apk SharedStorageBackup.odex Shell.apk Shell.odex SystemUI.apk SystemUI.odex VpnDialogs.apk VpnDialogs.odex WallpaperCropper.apk WallpaperCropper.odex"
- app_to_remove="AvrcpMediaPlayer.odex DeskClock.apk DeskClock.odex Development.apk Development.odex DocumentsUI.apk DocumentsUI.odex DownloadProviderUi.apk DownloadProviderUi.odex HIDDeviceApp.odex LatinIME.apk LatinIME.odex MapclientTestApp.odex Music.apk Music.odex PacProcessor.apk PacProcessor.odex PackageInstaller.apk PackageInstaller.odex PbapClientTestApp.odex PicoTts.apk PicoTts.odex PrintSpooler.apk PrintSpooler.odex Provision.apk Provision.odex BrcmHfDeviceTestApp.odex"
- mkdir -p /system/priv-app-old
- mkdir -p /system/app-old
- echo "OLIO: Moving applications out of priv-app folder."
- for app in $privapp_to_remove
- do
- mv /system/priv-app/$app /system/priv-app-old/
- done
- echo "OLIO: Moving applications out of app folder."
- for app in $app_to_remove
- do
- mv /system/app/$app /system/app-old/
- done
- echo "OLIO: android_apks_remove done."
- }
- # ---------------------------------------------------------------------------
- # install_software - master function for installing software.
- install_software_android ()
- {
- if [ -e $TARGET_FOLDER/olio_fix.sh ]
- then
- chown 1000:1000 $TARGET_FOLDER/olio_fix.sh
- chmod 775 $TARGET_FOLDER/olio_fix.sh
- source $TARGET_FOLDER/olio_fix.sh
- report_success "ALS calibration fixed" "1.0"
- fi
- if [ -e $TARGET_FOLDER/power-log.awk ]
- then
- cp $TARGET_FOLDER/power-log.awk /system/vendor/bin/
- chown 1000:1000 /system/vendor/bin/power-log.awk
- chmod 775 /system/vendor/bin/power-log.awk
- report_success "Power log installed" "1.0"
- fi
- if [ -e $TARGET_FOLDER/power-log.sh ]
- then
- cp $TARGET_FOLDER/power-log.sh /system/vendor/bin/
- chown 1000:1000 /system/vendor/bin/power-log.sh
- chmod 775 /system/vendor/bin/power-log.sh
- report_success "Power log installed" "1.0"
- fi
- if [ -e $LOOKS ]
- then
- rm -rf /data/media/0/olio/looks
- mkdir -p /data/media/0/olio/
- unzip -o $LOOKS -d /data/media/0/olio/
- chown -R 1023:1023 /data/media/0/olio/looks
- chmod -R 775 /data/media/0/olio/looks
- fi
- if [ -e $TARGET_FOLDER/vold ]
- then
- cp $TARGET_FOLDER/vold /system/bin/vold
- chown 1000:1000 /system/bin/vold
- chmod 775 /system/bin/vold
- report_success "Vold installed" "1.0"
- fi
- if [ -e $TARGET_FOLDER/libJsonSuperPack.so ]
- then
- cp $TARGET_FOLDER/libJsonSuperPack.so /system/lib/libJsonSuperPack.so
- chown 1000:1000 /system/lib/libJsonSuperPack.so
- chmod 775 /system/lib/libJsonSuperPack.so
- fi
- if [ -e $TARGET_FOLDER/Experiments-debug.apk ]
- then
- rm /system/app/Experiments-debug.apk
- cp $TARGET_FOLDER/Experiments-debug.apk /system/priv-app/Experiments-debug.apk
- chown 1000:1000 /system/priv-app/Experiments-debug.apk
- chmod 664 /system/priv-app/Experiments-debug.apk
- report_success "Experiments installed" "1.0"
- fi
- if [ -e $TARGET_FOLDER/app-debug.apk ]
- then
- cp $TARGET_FOLDER/app-debug.apk /system/priv-app/app-debug.apk
- chown 1000:1000 /system/priv-app/app-debug.apk
- chmod 664 /system/priv-app/app-debug.apk
- report_success "Wake detector installed" "1.0"
- fi
- if [ -e $TARGET_FOLDER/bplus.default.so ]
- then
- hw_lib_update $TARGET_FOLDER/bplus.default.so
- fi
- if [ -e $TARGET_FOLDER/audio.primary.omap3.so ]
- then
- hw_lib_update $TARGET_FOLDER/audio.primary.omap3.so
- fi
- if [ -e $TARGET_FOLDER/libtinyalsa.so ]
- then
- cp $TARGET_FOLDER/libtinyalsa.so /system/lib/libtinyalsa.so
- chown 1000:1000 /system/lib/libtinyalsa.so
- chmod 775 /system/lib/libtinyalsa.so
- fi
- if [ -e $TARGET_FOLDER/libbluetooth_jni.so ]
- then
- cp $TARGET_FOLDER/libbluetooth_jni.so /system/lib/libbluetooth_jni.so
- chown 1000:1000 /system/lib/libbluetooth_jni.so
- chmod 775 /system/lib/libbluetooth_jni.so
- fi
- if [ -e $TARGET_FOLDER/bt_vendor.conf ]
- then
- cp $TARGET_FOLDER/bt_vendor.conf /system/etc/bluetooth/bt_vendor.conf
- chmod 664 /system/etc/bluetooth/bt_vendor.conf
- chown 1000:1000 /system/etc/bluetooth/bt_vendor.conf
- fi
- if [ -e $TARGET_FOLDER/audio_policy.conf ]
- then
- cp $TARGET_FOLDER/audio_policy.conf /system/etc/audio_policy.conf
- chmod 664 /system/etc/audio_policy.conf
- chown 1000:1000 /system/etc/audio_policy.conf
- fi
- if [ -e $TARGET_FOLDER/Bluetooth.apk ]
- then
- mkdir -p /system/app-old/
- mv /system/app/Bluetooth.odex /system/app-old/
- cp $TARGET_FOLDER/Bluetooth.apk /system/app/Bluetooth.apk
- chown 1000:1000 /system/app/Bluetooth.apk
- chmod 664 /system/app/Bluetooth.apk
- report_success "Bluetooth apk installed" "1.0"
- fi
- if [ -e $BLUETOOTH_CLIENT ]
- then
- rm /system/priv-app/BluetoothClient-debug.apk
- cp $BLUETOOTH_CLIENT /system/priv-app/BluetoothClient-debug.apk
- chown 1000:1000 /system/priv-app/BluetoothClient-debug.apk
- chmod 664 /system/priv-app/BluetoothClient-debug.apk
- report_success "Bluetooth client installed" "1.0"
- fi
- if [ -e $POWER_HAL ]
- then
- cp $POWER_HAL /system/lib/hw/power.h1.so
- chown 1000:1000 /system/lib/hw/power.h1.so
- chmod 775 /system/lib/hw/power.h1.so
- report_success "Power HAL installed" "1.0"
- fi
- if [ -e $OLIO_FB ]
- then
- cp $OLIO_FB /system/vendor/bin/olio_fb_setup.sh
- chown 1000:1000 /system/vendor/bin/olio_fb_setup.sh
- chmod 775 /system/vendor/bin/olio_fb_setup.sh
- # If Olio fb setup is included, assume we want a factory reset
- rm /data/data/com.olio.bluetoothancs/databases/*
- rm /data/media/0/olio/bt_client_fb_stamp
- # This can get leftover from a reflash, so make sure it's removed
- rm /system/priv-app/btdebug.apk
- # This needs to be removed so that olio_fb_setup runs again
- rm /system/vendor/olio
- report_success "New Olio boot script installed" "1.0"
- fi
- if [ -e $TARGET_FOLDER/framework.jar ]
- then
- mkdir -p /system/framework-old
- mv /system/framework/framework.odex /system/framework-old/
- cp $TARGET_FOLDER/framework.jar /system/framework/framework.jar
- chown 1000:1000 /system/framework/framework.jar
- chmod 664 /system/framework/framework.jar
- report_success "Services jar installed" "1.0"
- fi
- if [ -e $SERVICES_JAR ]
- then
- mkdir -p /system/framework-old
- mv /system/framework/services.odex /system/framework-old/
- cp $SERVICES_JAR /system/framework/services.jar
- chown 1000:1000 /system/framework/services.jar
- chmod 664 /system/framework/services.jar
- report_success "Services jar installed" "1.0"
- fi
- # Doing the flash tool before the things that depend on it.
- if [ -e $FLASH_IMAGE ]
- then
- echo "OLIO: Installing new flash_image tool."
- mv $FLASH_IMAGE /system/bin/flash_image
- chmod 777 /system/bin/flash_image
- report_success "Installed new flash_image tool" "1.0"
- fi
- if [ -e $UIMAGE ]
- then
- flash_image $UIMAGE_PARTITION $UIMAGE
- report_success "$UIMAGE installed" "1.0"
- fi
- if [ -e $RAMFS ]
- then
- flash_image $RAMFS_PARTITION $RAMFS
- report_success "$RAMFS installed" "1.0"
- fi
- if [ -e $DTB ]
- then
- flash_image $DTB_PARTITION $DTB
- report_success "$DTB installed" "1.0"
- fi
- if [ -e $UBOOT ]
- then
- flash_image $UBOOT_PARTITION $UBOOT
- report_success "$UBOOT installed" "1.0"
- fi
- if [ -e $DRV2605 ]
- then
- echo "OLIO: Installing new driver for the drv2605."
- mv $DRV2605 /system/vendor/modules/drv2605.ko
- chmod 644 /system/vendor/modules/drv2605.ko
- chown 1000:1000 /system/vendor/modules/drv2605.ko
- report_success "$DRV2605 installed" "1.0"
- fi
- if [ -e $ATMEL_CFG ]
- then
- echo "OLIO: Installing new touch firmware."
- mv $ATMEL_CFG /system/vendor/firmware/atmel_cfg.raw
- chmod 644 /system/vendor/firmware/atmel_cfg.raw
- chown 1000:1000 /system/vendor/firmware/atmel_cfg.raw
- # For now steel and sapphire use the same tuning
- cp /system/vendor/firmware/atmel_cfg.raw /system/vendor/firmware/atmel_cfg-2.raw
- chmod 644 /system/vendor/firmware/atmel_cfg-2.raw
- chown 1000:1000 /system/vendor/firmware/atmel_cfg-2.raw
- fi
- if [ -e $CHARGER_FW ]
- then
- echo "Can't (yet) install $CHARGER_FW from Android"
- fi
- if [ -e $INITRC ]
- then
- echo "OLIO: Installing new init.h1.rc file."
- mv $INITRC /init.h1.rc
- chmod 644 /init.h1.rc
- chown 1000:1000 /init.h1.rc
- fi
- if [ -e $TARGET_FOLDER/init.rc ]
- then
- echo "OLIO: Installing new init.h1.rc file."
- mv $TARGET_FOLDER/init.rc /init.rc
- chmod 644 /init.rc
- chown 1000:1000 /init.rc
- fi
- echo "$0: Applications Installed, now doing firmware"
- }
- # ---------------------------------------------------------------------------
- # Main stuff
- #
- # Android packages: Experiments-debug.apk == com.olio.experiments
- # app-debug.apk == com.olio.wakedetector
- # Just in case...
- # Make sure device stays awake during the update. This will get cleared out after a reboot
- echo m > /sys/power/wake_lock
- set_path_permissions
- install_software_android # Add Olio stuff
- android_apks_remove # Remove cruft
- # ONLY IF THERE'S LINUX STUFF:
- if [ "$UPDATE_LINUX" == "true" ]
- then
- check_md5_sum
- linux_update_prep
- update_bootlines
- fi
- create_version_log
- # Remove this script from FS
- echo "$0: Cleaning up"
- echo "$0: Turning on Dalvik"
- stop
- setprop persist.sys.dalvik.vm.lib libart.so
- setprop persist.sys.strictmode.visual 0
- setprop persist.sys.strictmode.disable 1
- echo "$0: Done, now rebooting"
- if [ -e $RAMFS ]
- then
- fw_setenv bootcmd run ramfdtboot
- rm $TARGET_FOLDER/*
- else
- mv $TARGET_FOLDER/update_2.sh $TARGET_FOLDER/../update.sh
- rm $TARGET_FOLDER/*
- mv $TARGET_FOLDER/../update.sh $TARGET_FOLDER/update.sh
- fi
- sync
- sleep 20
- /system/bin/reboot
Add Comment
Please, Sign In to add comment