#!/bin/sh
#
# This is a production script to switch between the Android and the Linux
# system in this DevicePackage. It is to be configured as 'SwitchPlatformScript'
# in /opt/gira/etc/devicestack/device.config for usage by the devicestack.
#

# Fail if not exactly one parameter is given
if [ "$#" -ne 1 ]
then
  echo "Usage: $0 <platform>" >&2
  exit 1
fi
NEW_PLATFORM="$1"

# Set platform in U-Boot variable
# We could do more sanity checks here, but the devicestack already does that.
CURRENT_PLATFORM=$(fw_printenv -n platform)
fw_setenv platform "${NEW_PLATFORM}"
if [ $? -ne 0 ]
then
  echo "Error setting platform, aborting." >&2
  exit 1
else
  echo "Platform set to ${NEW_PLATFORM} (was: ${CURRENT_PLATFORM})"
fi

# The devicestack will trigger a factory reset
exit 0
