#!/usr/bin/env bash ############################################################################### # # Copyright (C) 2009-2013 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. # ############################################################################### ################################################################################ # setbootmode # This script enables a CAT_DEV to boot from PCFS or NAND. It must not be # executed directly from the bash command prompt. Instead, invoke this using: # source setbootmode PCFS|NAND ################################################################################ reflash=0 reflash_arg= mixed=1 production_arg= quick=0 if [ $# -gt 0 ] then _MORE_OPTIONS=1 while [ $_MORE_OPTIONS -eq 1 ] do if [ "$1" = "-noreflash" ] then reflash=0; reflash_arg="$1" shift elif [ "$1" = "-reflash" ] then reflash=1; reflash_arg="$1" shift elif [ "$1" = "-production" -o "$1" = "-P" ] then mixed=0; production_arg="$1" shift elif [ "$1" = "-quick" -o "$1" = "-Q" ] then quick=1; shift else _MORE_OPTIONS=0 fi done fi target=$1 status_str="FAIL" source cafe_utils if [ "${SDK_MAJ_VER}.${SDK_MIN_VER}.${SDK_MIC_VER}" != "${SDK_VER//0/}" ]; then "$CAFE_ROOT\system\bin\tool\mionps" $BRIDGE_CURRENT_IP_ADDRESS 3 -s ${SDK_VER:0:1} "$CAFE_ROOT\system\bin\tool\mionps" $BRIDGE_CURRENT_IP_ADDRESS 4 -s ${SDK_VER:2:2} "$CAFE_ROOT\system\bin\tool\mionps" $BRIDGE_CURRENT_IP_ADDRESS 5 -s ${SDK_VER:5:2} fi Bash_sourced_check 1 `basename "$0"` "`basename "$0"` PCFS|NAND" rval=$? if [ $rval -eq 0 ]; then if [ $quick -eq 1 ] then if [ "$USE_CAFEX" = "1" ]; then cafex.exe setbootmode -quick $target rval=$? else if [ "$target" != "PCFS" -a "$target" != "NAND" ]; then echo "Error: $target is not a valid boot mode! Please use NAND or PCFS." return 1 fi if [ ! -z "$production_arg" ]; then echo "Error: Can't specify both -quick and -production options! Please choose one or the other." return 1 fi 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 "Error: This version of the Host Bridge doesn't support boot mode detection!" echo " Please upgrade it to at least version 3.2.4.8 and try again." return 1 else # See if the DUAL bootloader is installed cafestop -hard sleep 1 CAFE_BOOT_MODE=`FSEmul -ip $BRIDGE_CURRENT_IP_ADDRESS -modedetect` rval=$? if [ $rval -ne 0 ] then echo "Error: Unable to determine boot mode! rval=$rval" return 1; fi cafestop -hard echo "Detected BOOT Mode: $CAFE_BOOT_MODE" if [ "${CAFE_BOOT_MODE:0:4}" != "DUAL" ] then echo "Error: DUAL bootloader is not installed!. Please re-run ${0} not using the quick option." return 1 fi # Call mionps if [ "$target" = "NAND" ]; then "$CAFE_ROOT\system\bin\tool\mionps" $BRIDGE_CURRENT_IP_ADDRESS 2 -s 1 else "$CAFE_ROOT\system\bin\tool\mionps" $BRIDGE_CURRENT_IP_ADDRESS 2 -s 2 fi rval=0 fi fi if [ $rval -eq 0 ]; then export CAFE_BOOT_MODE=$target status_str="PASS" fi else case "$target" in "PCFS") if [ "$USE_CAFEX" == "1" ]; then cafex.exe setbootmode $reflash_arg PCFS else if [ $mixed -eq 1 ]; then echo Executing caferecover for mixed PCFS"..." caferecover $reflash_arg else echo "Executing cafe_nand2pcfs ..." cafe_nand2pcfs 0 fi fi rval=$? if [ $rval == 0 ]; then "$CAFE_ROOT\system\bin\tool\mionps" $BRIDGE_CURRENT_IP_ADDRESS 2 -s 2 export CAFE_BOOT_MODE=PCFS echo CAFE_BOOT_MODE=$CAFE_BOOT_MODE status_str="PASS" fi ;; "NAND") if [ "$USE_CAFEX" = "1" ]; then cafex.exe setbootmode $reflash_arg $production_arg NAND else if [ $mixed -eq 1 ]; then echo Executing caferecover for mixed NAND"..." caferecover $reflash_arg else echo Executing cafe_pcfs2nand"..." cafe_pcfs2nand $reflash 0 fi fi rval=$? if [ $rval == 0 ]; then "$CAFE_ROOT\system\bin\tool\mionps" $BRIDGE_CURRENT_IP_ADDRESS 2 -s 1 export CAFE_BOOT_MODE=NAND echo CAFE_BOOT_MODE=$CAFE_BOOT_MODE status_str="PASS" fi ;; *) rval=1 echo `basename "$BASH_SOURCE"` error: must be executed using \"source `basename "$BASH_SOURCE"` PCFS\" or \"source `basename "$BASH_SOURCE"` [-production] NAND\". >/dev/stderr ;; esac fi else echo `basename "$BASH_SOURCE"` error: must be executed using \"source `basename "$BASH_SOURCE"` PCFS\" or \"source `basename "$BASH_SOURCE"` [-production] NAND\". >/dev/stderr fi echo `basename "$BASH_SOURCE"`: $status_str. unset SCRIPT_IS_SOURCED return $rval