| Index: src/platform/memento_softwareupdate/memento_updater.sh
 | 
| diff --git a/src/platform/memento_softwareupdate/memento_updater.sh b/src/platform/memento_softwareupdate/memento_updater.sh
 | 
| index a24477c8a9a430932f05505373522e3e77605961..3ce2fa375a1b91ba70e7f8b8ea2d568bdea6e033 100755
 | 
| --- a/src/platform/memento_softwareupdate/memento_updater.sh
 | 
| +++ b/src/platform/memento_softwareupdate/memento_updater.sh
 | 
| @@ -105,31 +105,28 @@ fi
 | 
|  # fast.
 | 
|  log Update Found: $IMG_URL checksum: $CHECKSUM
 | 
|  
 | 
| -# figure out which device i'm on, and which to download to.
 | 
| -ROOT_ARG=$(cat /proc/cmdline | tr ' ' '\n' | grep ^root= | cut -d = -f 2-)
 | 
| -LOCAL_DEV="$ROOT_ARG"
 | 
| -# do some device sanity checks
 | 
| -if expr match "$ROOT_ARG" '^UUID=' > /dev/null
 | 
| -then
 | 
| -  LOCAL_DEV=$(readlink -f /dev/disk/by-uuid/${ROOT_ARG#UUID=})
 | 
| -elif expr match "$ROOT_ARG" '^LABEL=' > /dev/null
 | 
| -then
 | 
| -  LOCAL_DEV=$(readlink -f /dev/disk/by-label/${ROOT_ARG#LABEL=})
 | 
| -fi
 | 
| +# Figure out which partition I'm on, and which to download to.
 | 
| +LOCAL_DEV=$(rootdev)
 | 
|  
 | 
| -# we install onto the other dev. so if we end in 1, other ends in 2, and
 | 
| +# We install onto the other partition so if we end in 3, other ends in 5, and
 | 
|  # vice versa
 | 
| -INSTALL_DEV=$(echo $LOCAL_DEV | tr '1234' '2143')
 | 
| -
 | 
| -ROOT_DEV=$(echo $LOCAL_DEV | tr -d '1234')  # strip trailing number
 | 
| -
 | 
| -# do some device sanity checks
 | 
| -if ! expr match "$LOCAL_DEV" '^/dev/[a-z][a-z]*[1234]$' > /dev/null
 | 
| +INSTALL_DEV=$(echo $LOCAL_DEV | tr '35' '53')
 | 
| +NEW_PART_NUM=${INSTALL_DEV##*/*[a-z]}
 | 
| +# The kernel needs to be installed to its own partition. We'll handle that in
 | 
| +# the postinst script (from the new rootfs). partitions 2&3 are image A,
 | 
| +# partitions 4&5 are image B.
 | 
| +KINSTALL_DEV=$(echo $INSTALL_DEV | tr '35' '24')
 | 
| +
 | 
| +# Find whole disk device.
 | 
| +ROOT_DEV=${LOCAL_DEV%%[0-9]*}
 | 
| +
 | 
| +# Do some device sanity checks.
 | 
| +if ! expr match "$LOCAL_DEV" '^/dev/[a-z][a-z]*[12345]$' > /dev/null
 | 
|  then
 | 
|    log "didnt find good local device. local: $LOCAL_DEV install: $INSTALL_DEV"
 | 
|    exit 1
 | 
|  fi
 | 
| -if ! expr match "$INSTALL_DEV" '^/dev/[a-z][a-z]*[1234]$' > /dev/null
 | 
| +if ! expr match "$INSTALL_DEV" '^/dev/[a-z][a-z]*[12345]$' > /dev/null
 | 
|  then
 | 
|    log "didnt find good install device. local: $LOCAL_DEV install: $INSTALL_DEV"
 | 
|    exit 1
 | 
| @@ -142,14 +139,14 @@ fi
 | 
|  
 | 
|  log Booted from "$LOCAL_DEV" and installing onto "$INSTALL_DEV"
 | 
|  
 | 
| -# make sure installation device is unmounted
 | 
| +# Make sure installation device is unmounted.
 | 
|  if [ "$INSTALL_DEV" == ""$(grep "^$INSTALL_DEV " /proc/mounts | \
 | 
|                             cut -d ' ' -f 1 | uniq) ]
 | 
|  then
 | 
| -  # drive is mounted. must unmount
 | 
| +  # Drive is mounted, must unmount.
 | 
|    log unmounting "$INSTALL_DEV"
 | 
|    umount "$INSTALL_DEV"
 | 
| -  # check if it's still mounted for some strange reason
 | 
| +  # Check if it's still mounted for some strange reason.
 | 
|    if [ "$INSTALL_DEV" == ""$(grep "^$INSTALL_DEV " /proc/mounts | \
 | 
|                               cut -d ' ' -f 1 | uniq) ]
 | 
|    then
 | 
| @@ -158,7 +155,7 @@ then
 | 
|    fi
 | 
|  fi
 | 
|  
 | 
| -# download file to the device
 | 
| +# Download file to the device.
 | 
|  log downloading image. this may take a while
 | 
|  
 | 
|  # wget - fetch file, send to stdout
 | 
| @@ -236,8 +233,9 @@ else
 | 
|    fi
 | 
|  fi
 | 
|  
 | 
| -"$MOUNTPOINT"/postinst "$INSTALL_DEV" 2>&1 | cat >> "$MEMENTO_AU_LOG"; \
 | 
| -  [ "${PIPESTATUS[*]}" = "0 0" ]
 | 
| +"$MOUNTPOINT"/postinst "$INSTALL_DEV" "$KINSTALL_DEV" 2>&1 | \
 | 
| +  cat >> "$MEMENTO_AU_LOG"
 | 
| +[ "${PIPESTATUS[*]}" = "0 0" ]
 | 
|  POSTINST_RETURN_CODE=$?
 | 
|  umount "$MOUNTPOINT"
 | 
|  rmdir "$MOUNTPOINT"
 | 
| @@ -255,8 +253,8 @@ function abort_update_if_cmd_failed {
 | 
|    abort_update_if_cmd_failed_long "$?" "!!"
 | 
|  }
 | 
|  
 | 
| -# if it failed, don't update MBR but just to be safe, zero out a page of
 | 
| -# install device
 | 
| +# If it failed, don't update MBR but just to be safe, zero out a page of
 | 
| +# install device.
 | 
|  abort_update_if_cmd_failed_long "$POSTINST_RETURN_CODE" "$MOUNTPOINT"/postinst
 | 
|  
 | 
|  # postinstall on new partition succeeded.
 | 
| @@ -269,12 +267,19 @@ log updating MBR of usb device
 | 
|  # flush linux caches; seems to be necessary
 | 
|  sync
 | 
|  echo 3 > /proc/sys/vm/drop_caches
 | 
| -
 | 
| -LAYOUT_FILE=/tmp/new_partition_layout
 | 
| -sfdisk -d $ROOT_DEV | sed -e "s/${INSTALL_DEV//\//\\/} .*[^e]$/&, bootable/" \
 | 
| -                          -e "s/\(${LOCAL_DEV//\//\\/} .*\), bootable/\1/" \
 | 
| -  > "$LAYOUT_FILE"
 | 
| -sfdisk --force $ROOT_DEV < "$LAYOUT_FILE" 2>&1 | cat >> "$MEMENTO_AU_LOG"
 | 
| +# Configure the PMBR to boot the new image.
 | 
| +# TODO: ChromeOS EFI BIOS will need a different command to set the GPT
 | 
| +# partition attributes bits to mark the new image as bootable.
 | 
| +# NOTE: This won't work for ARM, because we'll need to regenerate the U-Boot
 | 
| +# script when the kernel size and location are changed. Luckily it won't
 | 
| +# matter because we'll ship with the GPT-based selection process. The U-Boot
 | 
| +# script is just a temporary hack for bringup.
 | 
| +# FIX: The current gpt tool requires a -b arg to specify the PMBR bootcode. We
 | 
| +# don't want to change the code, so we have to extract it, then put it back.
 | 
| +# We'll fix this RSN.
 | 
| +dd if=${ROOT_DEV} bs=512 count=1 of=/tmp/oldpmbr.bin
 | 
| +gpt -S boot -i $NEW_PART_NUM -b /tmp/oldpmbr.bin ${ROOT_DEV} 2>&1 | \
 | 
| +  cat >> "$MEMENTO_AU_LOG"
 | 
|  abort_update_if_cmd_failed
 | 
|  
 | 
|  # mark update as complete so we don't try to update again
 | 
| 
 |