--- /dev/null
-flash_initrd() {
- echo "Flash initrd..."
+ #!/bin/bash
+ source /etc/tizen-platform.conf
+ FOTA_DIR="$TZ_SYS_GLOBALUSER_DATA/fota/save"
+ STATUS_DIR="/opt/data/recovery"
+ VERSION_FILE="/opt/etc/version"
+
- INITRD_INFO=("ramdisk.img" "ramdisk1" "1024")
- INITRD_RECOVERY_INFO=("ramdisk-recovery.img" "ramdisk2" "1024")
-
-# Flash initrd
- /bin/tar xvfp $1 -C $FOTA_DIR ${INITRD_INFO[0]}
- if [ ! -e "$FOTA_DIR/${INITRD_INFO[0]}" ]; then
- echo "There is no ${INITRD_INFO[0]}"
- return 1
- fi
- PART_NUM=$(partx -s $DEVICE | grep ${INITRD_INFO[1]} | awk '{print $1}')
- echo "Flashing initrd..."
- dd if="$FOTA_DIR/${INITRD_INFO[0]}" of="$DEVICE"p"$PART_NUM" bs="${INITRD_INFO[2]}"
- rm -f $FOTA_DIR/${INITRD_INFO[0]}
-
-# Flash initrd-recovery
- /bin/tar xvfp $1 -C $FOTA_DIR ${INITRD_RECOVERY_INFO[0]}
- if [ ! -e "$FOTA_DIR/${INITRD_RECOVERY_INFO[0]}" ]; then
- echo "There is no ${INITRD_RECOVERY_INFO[0]}"
- return 1
++flash_pre_image() {
++ echo "Flash images for update..."
+ DEVICE="/dev/mmcblk0"
- PART_NUM=$(partx -s $DEVICE | grep ${INITRD_RECOVERY_INFO[1]} | awk '{print $1}')
- echo "Flashing initrd-recovery..."
- dd if="$FOTA_DIR/${INITRD_RECOVERY_INFO[0]}" of="$DEVICE"p"$PART_NUM" bs="${INITRD_RECOVERY_INFO[2]}"
- rm -f $FOTA_DIR/${INITRD_RECOVERY_INFO[0]}
++ CONFIG_FILE="update.cfg"
++
++ /bin/tar xvfp $1 -C "$FOTA_DIR" $CONFIG_FILE
++ if [ ! -e "$FOTA_DIR/$CONFIG_FILE" ]; then
++ echo "There is no $CONFIG_FILE"
++ return
+ fi
-# Record version info in target if it doesn't exist
-# (in case of Tizen 3.0)
++
++ while read PART_NAME DELTA_NAME TYPE DEV OFFSET SIZE HASH1 HASH2
++ do
++ if [ "$TYPE" = "PRE_UA" ]; then
++ /bin/tar xvfp $1 -C $FOTA_DIR $DELTA_NAME
++ if [ ! -e "$FOTA_DIR/$DELTA_NAME" ]; then
++ echo "There is no delta for $PART_NAME"
++ continue
++ fi
++
++ EMMC_DEVICE="/dev/mmcblk0"
++ PART_NAME_L=$(echo $PART_NAME | /bin/tr '[:upper:]' '[:lower:]')
++ DEV_NUM=$(/sbin/partx -s $EMMC_DEVICE | grep $PART_NAME_L | \
++ { read NUM REST; echo $NUM; })
++ if [ -z "$DEV_NUM" ]; then
++ DEV_NUM=$(/sbin/blkid -L $PART_NAME_L -o device | \
++ sed 's/\/dev\/mmcblk0p//')
++ fi
++ if [ -z "$DEV_NUM" ]; then
++ echo "There is no partition for $PART_NAME"
++ continue
++ fi
++ DEV="${EMMC_DEVICE}p${DEV_NUM}"
++
++ echo "Flashing $DELTA_NAME..."
++ dd if="$FOTA_DIR/$DELTA_NAME" of="$DEV" bs=1024
++ rm -f $FOTA_DIR/$DELTA_NAME
++
++ # Remove updated partition from cfg
++ /bin/cat "$FOTA_DIR/$CONFIG_FILE" | /bin/sed /^$PART_NAME/d \
++ > "$FOTA_DIR/${CONFIG_FILE}_tmp"
++ /bin/mv "$FOTA_DIR/${CONFIG_FILE}_tmp" "$FOTA_DIR/$CONFIG_FILE"
++
++ /bin/tar --delete --file=$1 $CONFIG_FILE
++ /bin/tar rvf $1 -C $FOTA_DIR $CONFIG_FILE
++ fi
++ done < "$FOTA_DIR/$CONFIG_FILE"
+ }
+
+ write_version_info() {
+ OLD_VER=$(cat /etc/config/model-config.xml | grep platform.version \
+ | sed -e 's/.*>\(.*\)<.*/\1/')
+ OLD_REL=$(cat /etc/info.ini | grep Date | sed -e 's/Date=//' -e 's/\_.*//')
+ echo "OLD_VER=$OLD_VER" > $VERSION_FILE
+ echo "OLD_REL=$OLD_REL" >> $VERSION_FILE
+ }
+
+ # Check fota directory
+ if [ ! -d "$FOTA_DIR" ]; then
+ echo "Create fota dir..."
+ /bin/mkdir -p "$FOTA_DIR"
+ fi
+
+ if [ ! -d "$STATUS_DIR" ]; then
+ echo "Create status dir..."
+ /bin/mkdir -p "$STATUS_DIR"
+ fi
+
-# Flash initrd images
-# - in case of Tizen 3.0
-flash_initrd $1
++# Record version info in target if it doesn't exist
+ ls "$VERSION_FILE"
+ if [ $? -ne 0 ]; then
+ write_version_info
+ fi
+
++# Flash images
++# - in case of some image was newly included
++# - in case of some image should be flashed before update
++flash_pre_image $1
+
+ # Extract delta.ua
+ echo "Extract delta.ua..."
+ /bin/tar xvfp $1 -C "$FOTA_DIR" delta.ua
+ sync
+ sleep 1
+
+ echo "Move delta.tar..."
+ mv $1 $FOTA_DIR/delta.tar
+ sync
+
+ # FOTA: /usr/bin/rw-update-prepare.sh
+
+ # Write delta saved path
+ echo "Write DELTA.PATH..."
+ echo "$FOTA_DIR" > "$STATUS_DIR/DELTA.PATH"
+ sync
+
+ # go to fota mode
+ echo "Go TOTA update..."
+ /sbin/reboot fota