#!/usr/bin/env bash ############################################################################### # # Copyright (C) 2009-2014 Nintendo. All rights reserved. # # These coded instructions, statements, and computer programs contain # proprietary information of Nintendo of America Inc. and/or Nintendo # Company Ltd., and are protected by Federal copyright law. They may # not be disclosed to third parties or copied or duplicated in any form, # in whole or in part, without the prior written consent of Nintendo.:::: # ############################################################################### ################################################################################ # cafe_utils ################################################################################ source cafe_utils ################################################################################ # internal helper functions ################################################################################ check_mlc_sys_update_mixed() { NAND_SRC_DIR=$CAFE_MLC_DIR/sys/update/nand MIXED_DEST_DIR=$CAFE_MLC_DIR/sys/update/mixed BL_DEST_DIR=$CAFE_MLC_DIR/sys/update/bootloader if [ ! -e "$MIXED_DEST_DIR" ] then mkdir "$MIXED_DEST_DIR" fi if [ ! -e "$BL_DEST_DIR" ] then mkdir "$BL_DEST_DIR" fi # Copy the DUAL bootloader to it own directory if [ ! -e "$BL_DEST_DIR/aaa-boot1-dual" ]; then cp -r "$MIXED_DEST_DIR/aaa-boot1-dual" "$BL_DEST_DIR" fi # Copy the nand content(not hte bootloader) to mixed for entry in "$NAND_SRC_DIR"/* do if [ -f "$entry" ] then if [ ! -e "$MIXED_DEST_DIR/$(basename "$entry")" ] then cp "$entry" "$MIXED_DEST_DIR/$(basename "$entry")" fi elif [ -d "$entry" ] then if [ ! -e "$MIXED_DEST_DIR/$(basename "$entry")" ] then if [ $(expr "$entry" : ".*zzz-boot1-.*") -eq 0 ] then cp -R "$entry" "$MIXED_DEST_DIR/$(basename "$entry")" fi fi fi done } ################################################################################ # caferecover # This script attemps to recover a CAT_DEV to boot from PCFS. # It must not be ran from the bash command prompt. # Instead, invoke this using: # source caferecover ################################################################################ if [ "$USE_CAFEX" == "1" ] then # Set IFS to something that will not be in the args, so that BASH will pass the entire un-parsed string to CafeX saveIFS="$IFS" IFS=$'\n' echo "Using CafeControl" cafex.exe recover $@ rval=$? IFS="$saveIFS" exit $rval fi #------------------------------------------------------------------------------ #---- initialization #------------------------------------------------------------------------------ SCRIPT_EXE_TIMESTAMP=`date +%m_%d_%Y_%H%M%S` LOGDIR="$CAFE_TEMP/`basename "$0"`/${SCRIPT_EXE_TIMESTAMP}" echo `basename "$0"` echo log directory is $LOGDIR mkdir -p "$LOGDIR" OLDCONSOLE=$CAFE_CONSOLE CAFE_CONSOLE=toucan old_boot_mode=$CAFE_BOOT_MODE production_bootloader=0 bootloader_only=0 skip_update=0 #Initialize_serial_port_and_directory cafestop #------------------------------------------------------------------------------ #---- command line processing #------------------------------------------------------------------------------ if [ $# -gt 0 ] then CAFERECOVER_MORE_OPTIONS=1 while [ $CAFERECOVER_MORE_OPTIONS -eq 1 ] do if [ "$1" = "-production" ] then production_bootloader=1 shift elif [ "$1" = "-bootloader" ] then bootloader_only=1 shift else CAFERECOVER_MORE_OPTIONS=0 fi done fi if [ $bootloader_only -eq 1 -a $production_bootloader -eq 1 ]; then echo `basename "$0"`": Invalid arguments: Can't specify both -production and -bootloader options!" exit 1 fi #------------------------------------------------------------------------------ #---- boot mode detection #------------------------------------------------------------------------------ source hostcheckversion hb_ver_flat=$(compute_flat_version $CAFERUN_HOSTBRIDGE_VERSION) if [ $hb_ver_flat -lt $(compute_flat_version 3.2.4.8) ] then echo "Using BOOT mode $CAFE_BOOT_MODE" else cafestop -hard sleep 1 CAFE_BOOT_MODE=`FSEmul -ip $BRIDGE_CURRENT_IP_ADDRESS -modedetect` rval=$? if [ $rval -ne 0 ] then echo "Unable to determine boot mode! rval=$rval" exit $rval; fi echo "Detected BOOT Mode: $CAFE_BOOT_MODE" if [ "$CAFE_BOOT_MODE" != "NAND" ] then CAFE_BOOT_MODE=PCFS fi fi export CAFE_BOOT_MODE #------------------------------------------------------------------------------ #---- Boot the DEVKIT into recovery mode #------------------------------------------------------------------------------ if [ "$CAFE_BOOT_MODE" == "NAND" ] then #------------------------------------------------------------------------------ #---- cafeon #------------------------------------------------------------------------------ echo Executing cafeon"..." set -e if [ $hb_ver_flat -lt $(compute_flat_version 3.2.4.1) ] then cafeon 1> "$LOGDIR"/cafeon.txt 2>&1 else cafeon -e nomodecheck 1> "$LOGDIR"/cafeon.txt 2>&1 fi if [ -e "$TMP/${SESSION_PATH_PREFIX}cafestop_mion.log" ]; then mv "$TMP/${SESSION_PATH_PREFIX}cafestop_mion.log" "${LOGDIR}/cafeon_mion.log" fi set +e Monitor_For_Output -k "source -p -q /vol/content" $MONITOR_DEFAULT_TIMEOUT "$LOGDIR" if [ $? -ne 0 ]; then echo `basename $0`: monitor failed waiting for cafeon success message. exit 1 fi #------------------------------------------------------------------------------ #---- devkitmsg -recover (enter recovery mode) #------------------------------------------------------------------------------ echo Executing devkitmsg recover -v"..." set -e devkitmsg recover -v -p $SESSION_LAUNCH_CTRL_PORT set +e Monitor_For_Output -K "WUD_BCMFWCheck" $MONITOR_DEFAULT_TIMEOUT "$LOGDIR" #note: need -K here, not -k if [ $? -ne 0 ]; then echo `basename "$0"`: monitor failed waiting for devkitmsg recover success message. exit 1 fi # Check the $CAFE_ROOT/data/mlc/sys/update/mixed folder check_mlc_sys_update_mixed # Install the DUAL bootloader as fail-safe echo Executing devkitmsg \'update /vol/storage_hfiomlc01/sys/update/bootloader\' -v"..." set -e devkitmsg 'update /vol/storage_hfiomlc01/sys/update/bootloader' -v -p $SESSION_LAUNCH_CTRL_PORT set +e Monitor_For_Output -k "Update Done, err 0" $MONITOR_DEFAULT_TIMEOUT "$LOGDIR" if [ $? -ne 0 ]; then echo `basename "$0"`: monitor failed waiting for devkitmsg 1st update success message. CAFE_CONSOLE=$OLDCONSOLE exit 1 fi # Rest of the update from PCFS boot mode with the DUAL bootlaoder CAFE_BOOT_MODE="PCFS" if [ $bootloader_only -eq 1 ]; then # We have already updated the bootloader so suppress doing it again if it was # the only thing we are requested to do. skip_update=1 fi cafestop -hard # export CAFE_RUN_RUNNING=0 fi if [ $skip_update -eq 0 ] then #------------------------------------------------------------------------------ #---- cafeon (with recovery image) #------------------------------------------------------------------------------ echo Executing cafeon"..." set -e if [ $hb_ver_flat -lt $(compute_flat_version 3.2.4.1) ] then cafeon -recover 1> "$LOGDIR"/caferecover.txt 2>&1 else cafeon -recover -e nomodecheck 1> "$LOGDIR"/caferecover.txt 2>&1 fi if [ -e "$TMP/${SESSION_PATH_PREFIX}cafestop_mion.log" ]; then mv "$TMP/${SESSION_PATH_PREFIX}cafestop_mion.log" "${LOGDIR}/cafeon_mion.log" fi set +e Monitor_For_Output -K "WUD_BCMFWCheck" $MONITOR_DEFAULT_TIMEOUT "$LOGDIR" #note: need -K here, not -k if [ $? -ne 0 ]; then echo `basename "$0"`: monitor failed waiting for recovery boot success message. CAFE_CONSOLE=$OLDCONSOLE exit 1 fi #------------------------------------------------------------------------------ #---- Update/Reflash the DEVKIT #------------------------------------------------------------------------------ # Check the $CAFE_ROOT/data/mlc/sys/update/mixed folder check_mlc_sys_update_mixed if [ $bootloader_only -eq 1 ] then echo Executing devkitmsg \'update /vol/storage_hfiomlc01/sys/update/bootloader\' -v"..." set -e devkitmsg 'update /vol/storage_hfiomlc01/sys/update/bootloader' -v -p $SESSION_LAUNCH_CTRL_PORT set +e Monitor_For_Output -k "Update Done, err 0" $MONITOR_DEFAULT_TIMEOUT "$LOGDIR" if [ $? -ne 0 ]; then echo `basename "$0"`: monitor failed waiting for devkitmsg 1st update success message. CAFE_CONSOLE=$OLDCONSOLE exit 1 fi else if [ $production_bootloader -eq 1 ] then echo Executing devkitmsg \'reflash /vol/storage_hfiomlc01/sys/update/nand\' -v"..." set -e devkitmsg 'reflash /vol/storage_hfiomlc01/sys/update/nand' -v -p $SESSION_LAUNCH_CTRL_PORT set +e else echo Executing devkitmsg \'reflash /vol/storage_hfiomlc01/sys/update/mixed\' -v"..." set -e devkitmsg 'reflash /vol/storage_hfiomlc01/sys/update/mixed' -v -p $SESSION_LAUNCH_CTRL_PORT set +e fi Monitor_For_Output -k "System update was successful" $MONITOR_DEFAULT_TIMEOUT "$LOGDIR" if [ $? -ne 0 ]; then echo `basename "$0"`: monitor failed waiting for devkitmsg 1st update success message. CAFE_CONSOLE=$OLDCONSOLE exit 1 fi fi #------------------------------------------------------------------------------ #---- enable self refresh #------------------------------------------------------------------------------ if [ "$CAFE_TEST_SELF_REFRESH" == "1" ] then devkitmsg 'standby_en 1' -v -p $SESSION_LAUNCH_CTRL_PORT fi #------------------------------------------------------------------------------ #---- cafestop #------------------------------------------------------------------------------ echo Executing cafestop"..." source cafestop 1> "$LOGDIR"/cafestop1.txt 2>&1 if [ -e "$TMP/${SESSION_PATH_PREFIX}cafestop_mion.log" ]; then mv "$TMP/${SESSION_PATH_PREFIX}cafestop_mion.log" "${LOGDIR}/cafestop1_mion.log" fi if [ $CAFESTOP_STATUS -ne 0 ]; then echo `basename "$0"`: cafestop failure. CAFE_CONSOLE=$OLDCONSOLE exit 1 fi fi # Update the MION parameter space for the boot mode if [ $production_bootloader -eq 1 -o "$old_boot_mode" == "NAND" ] then # NAND boot mode "$CAFE_ROOT\system\bin\tool\mionps" $BRIDGE_CURRENT_IP_ADDRESS 2 -s 1 else # PCFS boot mode "$CAFE_ROOT\system\bin\tool\mionps" $BRIDGE_CURRENT_IP_ADDRESS 2 -s 2 fi #------------------------------------------------------------------------------ #---- success! #------------------------------------------------------------------------------ echo Removing log directory $LOGDIR"..." rm -rf "$LOGDIR" echo `basename "$0"` complete. Exiting with code 0. if [ $production_bootloader -eq 1 -a "$old_boot_mode" != "NAND" ] then echo echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "!! !!" echo "!! Boot Loader/Boot Mode mis-match detected! !!" echo "!! !!" echo "!! Please export CAFE_BOOT_MODE=NAND for proper operation! !!" echo "!! !!" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" fi CAFE_CONSOLE=$OLDCONSOLE exit $rval