#!/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. # ############################################################################### # use for debugging and remove this and lines above #!/bin/sh -vx 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 run $@ rval=$? IFS="$saveIFS" exit $rval fi export PLATFORM=cafe # DO NOT CHANGE CAFE_ROOT to a DOS path, if you need a DOS path use CAFE_ROOT_DOS # CAFE_ROOT_DOS=`cygpath -m "$CAFE_ROOT"` QUIET=-q CAFESTOP_ONLY_IF_FSEMUL=0 # by default, always call cafestop PPC_OS_FLAGS=0 PPC_APP_FLAGS=0 ALLOW_DISCRUN_IN_SOFTLAUNCH=0 BOOTRUN_ELF_OPT= BOOTRUN_ELF_VALUE= ELF_NEST_OPT= ELF_NEST_VALUE= SOFT_LAUNCH_CAFE_ELF= PCFS_SYNC_DATE= MCP_LAUNCH_HINT= MCP_INFO_OPTION= DEBUGGER=${DEBUGGER:-none} CONSOLE=${CAFE_CONSOLE:-cattoucan} CAFE_DEBUG_PORT=${CAFE_DEBUG_PORT:-toucan} DEBUG_ELF_FILE=${DEBUG_ELF_FILE:-} CAFERUN_OPTION_SOFT_RESTART=0 CAFERUN_OPTION_FAST_RELAUNCH=0 CAFERUN_OPTION_MLC_EMU_LAUNCH=0 CAFERUN_OPTION_MLC_EMU_TITLEID=0xFFFFFFFFFFFFFFFF CAFERUN_OS_MAJOR_VERSION_LO=`grep "00050010" "${CAFE_ROOT}/system/include/sdk_ver.h" | sed 's/.*00050010//'` CAFERUN_OS_MAJOR_VERSION=${CAFERUN_OS_MAJOR_VERSION_LO:6:2} CAFERUN_COLDBOOT_OS_VERSION=0x${CAFERUN_COLDBOOT_OS_VERSION:-00050010100040${CAFERUN_OS_MAJOR_VERSION}} export CAFERUN_COLDBOOT_OS_VERSION HEARTBEAT_DISABLE=0 PCFS_DIR_MAPPING=( ) MAPDIR_MLC= MAPDIR_SLC= MAPDIR_CODE= MAPDIR_META= MAPDIR_CONTENT= MAPDIR_SAVE= PCFS_LOG_TIMESTAMP= PCFS_SRV_LOG_OUTPUT= RUN_FROM_HDD_BANK= EJECT_STATE= BRIDGE_PARAMETERS= BRIDGE_PARAMETERS_WITH_E= PCFSSERVER_PARAMETERS= PCFS_OVER_SATA_PORT= PCFS_HEADLESS_EMUL=${PCFS_HEADLESS_EMUL:--pcfsenable} PREPHDD_STAT= DISC_EMU_TID= CAFE_WUMAD= WUMAD_WORK_DIR= SYSTEM_MODE="" # "dev", or "test" export RPL_DIRS export RPL_FILES USE_EXI_AS_DEBUG_CHANNEL=${USE_EXI_AS_DEBUG_CHANNEL:-0} export CAFERUN_INS=${CAFERUN_INS:-0} if [ -f "$MION_BRIDGE_TOOLS/PCFS/PCFSServer.exe" ] then PCFSSERVER_EXE="$MION_BRIDGE_TOOLS/PCFS/PCFSServer.exe" else PCFSSERVER_EXE="PCFSServer.exe" fi export CAFERUN_OPTION_NO_DATA_SYNC=${CAFERUN_OPTION_NO_DATA_SYNC:-0} if [ "$(basename "$0")" != "cafeon" -a "$CAFE_BOOT_MODE" == "NAND" ] then CAFERUN_OPTION_SOFT_LAUNCH=1 else CAFERUN_OPTION_SOFT_LAUNCH=0 fi # these two are set by hostcheckversion CAFERUN_HOSTBRIDGE_VERSION=unknown CAFERUN_FW_VERSION=unknown # tell debugger to not stop in init code (by default) CAFE_DEBUG_INIT=${CAFE_DEBUG_INIT:-0} CAFE_DEBUG_PREINIT=${CAFE_DEBUG_PREINIT:-0} CAFE_DEBUG_DONTSTOP=${CAFE_DEBUG_DONTSTOP:-0} CAFE_LAUNCH_DEBUG=${CAFE_LAUNCH_DEBUG:-1} CAFE_SYSLOG_LEVEL=${CAFE_SYSLOG_LEVEL:-1} # default to print warnings export CAFE_RUN_FORCERESTART=${CAFE_RUN_FORCERESTART:-0} DEBUG_PROC_ID=${DEBUG_PROC_ID:-15} DEBUG_FLAGS=0 if [ $CAFE_DEBUG_INIT != 0 ] then DEBUG_FLAGS=16 fi # no initial breakpoint if [ $CAFE_DEBUG_DONTSTOP != 0 ] then DEBUG_FLAGS=32 fi # debugger can only set one initial breakpoint if [ $CAFE_DEBUG_PREINIT != 0 ] then DEBUG_FLAGS=64 fi if [ $USE_EXI_AS_DEBUG_CHANNEL -eq 0 ] then DEBUG_FLAGS=$(($DEBUG_FLAGS | 256)) fi CATOUTPUT=0 CMDOUTPUT=0 case "$CONSOLE" in sdio) CONSOLE=toucan ;; cattoucan) CONSOLE=toucan DEBUGGER=cattoucan CATOUTPUT=1 ;; cmdtoucan) CONSOLE=toucan DEBUGGER=cattoucan CMDOUTPUT=1 ;; esac # when running autotest don't enable the "cat function" if [ "$CAFE_AUTOTEST" = "1" ] then DEBUGGER=none fi ############################################################################### # print usage help message ############################################################################### usage () { cat <.rpx "[arg1]" "[arg2]" ... "[argN]" options: -a a,b... : arguments (comma delimited) -b : use DEBUG OS version -u : use FDEBUG OS version -l : user RPL directory or file to gather for RPX -d multi : launch multi (GHS UI) on elf file -L : run legacy application independent of xml versions -i : stop debugger in the initialization code -j : stop debugger in the pre-initialization code -R : do not stop in debugger until OSDebug or OSDebugStr call -p : indicate process to debug (defaults to game process) -g : 32-bit flag to pass along to PPC COS -w : 32-bit flag to pass along to PPC COS. -k : path to elf file for debugger -x : Enable AHCI/SATA disk access. Deprecated - will soon become default. -r : restart last application -s : use soft launch to run -F : force restart (stop and then boot hw) -t : title launch from mlc emulation (tid is hex that starts with 0x) -e : pass op through to FSEmul or MCP (e.g.: -e sata -> FSEmul -sata) -v : set COS verbose level (0=off 7 == MAX) -q : do not display OS warning or informational messages. -z : suppress mirroring the data to the session data directory. -h : (help) display options EOF } ############################################################################### # launch to serial or debugger ############################################################################### connect_serial_or_debugger() { case ${DEBUGGER} in multi) ;; gdb|gdbtui) ;; cattoucan) set +e cattoucan $QUIET -p localhost:$SESSION_DEBUG_OUT_PORT exit $? ;; none) # if console is not toucan # set CAFE_DEBUG_PORT=toucan if [ ${CONSOLE} != "toucan" ] then CAFE_DEBUG_PORT=toucan fi return 0; ;; *) echo "$(basename "$0") failed: ${DEBUGGER} unsupported debugger." >&2 exit 20 ;; esac if [ "${CAFE_DEBUG_PORT}" = "toucan" ] then PORT=localhost:$SESSION_DEBUG_OUT_PORT else echo "$(basename "$0") failed: Unknown debugger port '${CAFE_DEBUG_PORT}'" exit 21 fi if [ ${DEBUGGER} = "multi" ] then MULTIELF="" if [ ! -z "$DEBUG_ELF_FILE" ] then MULTIELF=`cygpath -m "$DEBUG_ELF_FILE"` fi set +e cattoucan $QUIET -p $PORT CATTOUCAN_STATUS=$? set -e if [ $USE_EXI_AS_DEBUG_CHANNEL -eq 1 ] then MULTI_CONNECT=${MULTI_CONNECT:--connect=cafeserv -iphost $BRIDGE_CURRENT_IP_ADDRESS -ipport 7977 -console_iphost localhost -console_ipport $SESSION_DEBUG_OUT_PORT -auto_first} else MULTI_CONNECT=${MULTI_CONNECT:--connect=cafeserv -iphost localhost -ipport $SESSION_DEBUG_CONTROL_PORT -console_ipport $SESSION_DEBUG_OUT_PORT -auto_first} fi if [ $CATTOUCAN_STATUS = 42 ] then if [ $CAFE_LAUNCH_DEBUG = 1 ] then nohup ${GHS_ROOT}/multi.exe -cmd prepare_target "${MULTI_CONNECT}" ${CAFE_MULTI_INIT} "$MULTIELF" < /dev/null &> /dev/null & else echo "Ready to connect from multi" echo ${GHS_ROOT}/multi.exe -cmd prepare_target "${MULTI_CONNECT}" ${CAFE_MULTI_INIT} "$MULTIELF" fi if [ $CMDOUTPUT = 1 ] then cattoucan $QUIET -p $PORT fi fi else echo > .caferun_gdbcmds if [ ! -z "$DEBUG_ELF_FILE" ] then echo "file \"$DEBUG_ELF_FILE\"" >> .caferun_gdbcmds fi echo "set arch powerpc:broadway" >> .caferun_gdbcmds echo "target remote localhost:$SESSION_DEBUG_CONTROL_PORT" >> .caferun_gdbcmds set +e cattoucan $QUIET -p $PORT CATTOUCAN_STATUS=$? set -e if [ $CATTOUCAN_STATUS = 42 ] then if [ $CAFE_LAUNCH_DEBUG = 1 ] then powerpc-cos-eabi-${DEBUGGER} -x .caferun_gdbcmds else echo "Ready to connect from gdb" echo powerpc-cos-eabi-${DEBUGGER} -x .caferun_gdbcmds fi fi fi } ############################################################################### # args_to_bar_sep_list # # converts an argument list into bar separated one # spaces inside of quoted arguments are supported # e.g. 1 2 3 "a b c" 4 5 6 --> 1|2|3|a b c|4|5 # idea is to then convert the bars to either commas or something else # when needed using something like sed 's?|?,?' ############################################################################### args_to_bar_sep_list() { R=$1 shift while [ $# -gt 0 ] do R=$R'|'$1 shift done } ############################################################################### # check_title_id # # copy default xml if destination xml doesn't exist # otherwise, compare title id. exit or copy default if mismatch ############################################################################### check_title_id() { local FILE_DEST="$1" local FILE_DEFAULT="$2" local FILE_APP="$3" if [ ! -f "$FILE_DEST" ] then echo "$(basename "$0"): Copying default config file to $FILE_DEST" if [ ! -f "$FILE_DEFAULT" ] then echo "$(basename "$0") failed: Cannot find default config file $FILE_DEFAULT" exit 12 fi install -Dp "$FILE_DEFAULT" "$FILE_DEST" else # extract version number of xml element in file of the form: local TITLEID_DEST=`sed -n 's|.*\([[:xdigit:]]*\)|\1|p' "$FILE_DEST"` local TITLEID_APP=`sed -n 's|.*\([[:xdigit:]]*\)|\1|p' "$FILE_APP"` if [ -z "$TITLEID_DEST" -o -z "$TITLEID_APP" ] then echo "caferun failed: Cannot get title id" exit 12 fi if [ $TITLEID_DEST != $TITLEID_APP ] then echo "$(basename "$0"): Config file title id mismatch detected: $TITLEID_DEST vs. required $TITLEID_APP" echo " Copying default config file to $FILE_DEST" if [ ! -f "$FILE_DEFAULT" ] then echo "$(basename "$0") failed: Cannot find default config file $FILE_DEFAULT" exit 12 fi install -Dp "$FILE_DEFAULT" "$FILE_DEST" fi fi } ############################################################################### # check_xml_version # # copy default xml if destination xml doesn't exist # otherwise, compare version. exit or copy default if mismatch ############################################################################### check_xml_version() { local FILE_DEST="$1" local FILE_DEFAULT="$2" local FILE_OPTION="$3" if [ ! -f "$FILE_DEST" ] then echo "$(basename "$0"): Copying default config file to $FILE_DEST" if [ ! -f "$FILE_DEFAULT" ] then echo "$(basename "$0") failed: Cannot find default config file $FILE_DEFAULT" exit 12 fi install -Dp "$FILE_DEFAULT" "$FILE_DEST" else # extract version number of xml element in file of the form: local VER_DEFAULT=`sed -n 's|.*\([0-9]*\)|\1|p' "$FILE_DEFAULT"` local VER_DEST=`sed -n 's|.*\([0-9]*\)|\1|p' "$FILE_DEST"` if [ -z "$VER_DEST" -o -z "$VER_DEFAULT" ] then echo "caferun failed: Cannot get xml version numbers" exit 12 fi if [ "$IGNORE_VERSION" != "TRUE" ] then if [ $VER_DEST -ne $VER_DEFAULT ] then if [ "$FILE_OPTION" = "copy_default_if_mismatch" ] then echo "$(basename "$0"): Config file version mismatch detected: $VER_DEST vs. required $VER_DEFAULT" echo " Copying default config file to $FILE_DEST" if [ ! -f "$FILE_DEFAULT" ] then echo "$(basename "$0") failed: Cannot find default config file $FILE_DEFAULT" exit 12 fi install -Dp "$FILE_DEFAULT" "$FILE_DEST" else echo "$(basename "$0") failed: Please update or delete config file: $FILE_DEST" echo " Version number mismatch: $VER_DEST vs. required $VER_DEFAULT" exit 10 fi fi fi fi } ############################################################################### # exit_if_specials # # check for special characters in arglist # '?' : get used as spaces in connected words # '<' : used as xml delimiters, used to find arglist # '|' : used as spaces in connected words (in first part of cdoe) # - perhaps eventually we can auto-escape these. For now, simply punt ############################################################################### exit_if_specials() { if [ -n "`echo "$@" | egrep '[?|<>+]'`" ] then echo "$(basename "$0") failed: Unable to parse special character (?+<>|) in arg list." echo " arglist: \"$@\" " exit 11 fi } ############################################################################### # update_arglist # # Updates argument list in user .xml file with program name and extra arguments # arguments are bar-delimited ############################################################################### update_arglist() { local FILE_DEST="$1" # root directory local CAFE_ELF="$2" # program name of our program.elf shift 2 local ARGLIST="$@" # all the rest of the arguments # now don't abort script when any command returns an error (non-zero value). # (Legitimate Null strings being passed to sed/grep causing script to die # in unexpected locations) set +e # update the argc/argv string in user file with options passed in from user # with extra arguments from the end (the shift and $* calls below) # - this code is pretty ugly, I'm sure somone (using IFS?) could clean it up alot shift exit_if_specials "$@" # exit if special characters found args_to_bar_sep_list "$@" local ARGS_TRAILING_WITH_BARS=$R # arguments after the file name # convert commas in the -a command to vertical bars, and append trailing values from user if [ -z "${DASH_A_ARGS}" ] then ARGS_WITH_BARS="${ARGS_TRAILING_WITH_BARS}" else ARGS_WITH_BARS="`echo ${DASH_A_ARGS} | sed 's?,?|?g'`" if [ "${ARGS_WITH_BARS}" == "" ] then ARGS_WITH_BARS=$DASH_A_ARGS fi if [ -n "${ARGS_TRAILING_WITH_BARS}" ] then ARGS_WITH_BARS="${ARGS_WITH_BARS}|${ARGS_TRAILING_WITH_BARS}" fi fi # convert any remaining " to \" local ARGS_WITH_BARS_NO_QUOTES="`echo $ARGS_WITH_BARS | sed 's?\"?\\\"?g'`" if [ -z "$ARGS_WITH_BARS_NO_QUOTES" ] then ARGS_WITH_BARS_NO_QUOTES=$ARGS_WITH_BARS fi # third, construct the total argument list (prog_name <|input_args> ) local TOTAL_ARGLIST="${CAFE_ELF##/*/}" if [ -n "$ARGS_WITH_BARS_NO_QUOTES" ] then TOTAL_ARGLIST="$TOTAL_ARGLIST|$ARGS_WITH_BARS_NO_QUOTES" fi # (e.g. 'a b "1 2 3" c d' => "a b 1?2?3 c d" local TOTAL_ARGLIST_WITH_QS=`echo ${TOTAL_ARGLIST} | sed -e 's+ +?+g' -e 's+|+ +g'` #finally, push it back into the file # append extra args # * ==> app.elf default_args input_args sed -i -e "s|\(\)\(.*\)\(\)|\1$TOTAL_ARGLIST_WITH_QS\3|" "$FILE_DEST" set -e } ############################################################################### # update_system_xml ############################################################################### update_system_xml() { local FILE_DEST="$1" local CMD_FLAGS="$2" local SYSTEM_MODE="$3" local SYS_XML_MCP_LAUNCH_HINT="$4" local STRINGS_REPLACED=0 local SYS_DEFAULT_XML="$CAFE_ROOT/system/bin/ghs/cafe/boot/system_default.xml" check_xml_version "$FILE_DEST" "$SYS_DEFAULT_XML" "copy_default_if_mismatch" # Set system mode, updating system.xml in emulated slc local OLD_SYSTEM_MODE_NUM=`sed -n 's|.*\(.*\).*|\1|p' "$FILE_DEST"` local SYSTEM_MODE_NAME_TABLE[0]="PROD" local SYSTEM_MODE_NAME_TABLE[1]="DEV" local SYSTEM_MODE_NAME_TABLE[2]="TEST" local SYSTEM_MODE_NAME_TABLE[3]="Unknown" if [ ! "$OLD_SYSTEM_MODE_NUM" = "0" -a ! "$OLD_SYSTEM_MODE_NUM" = "1" -a ! "$OLD_SYSTEM_MODE_NUM" = "2" ] then OLD_SYSTEM_MODE_NUM=3 # Invalid value fi if [ "$SYSTEM_MODE" = "dev" ] then NEW_SYSTEM_MODE_NUM=1 elif [ "$SYSTEM_MODE" = "test" ] then NEW_SYSTEM_MODE_NUM=2 else if [ "$SYSTEM_MODE" = "prod" ] # PROD mode does not work in PCFS boot mode then echo "$(basename "$0") Warning: Changing to PROD mode is not supported." echo " Please specify '-M dev' or '-M test'." elif [ ! "$SYSTEM_MODE" = "" ] # User specified something invalid through the option then echo "$(basename "$0") Warning: Invalid system mode is specified." fi if [ $OLD_SYSTEM_MODE_NUM -ne 3 ] then NEW_SYSTEM_MODE_NUM=$OLD_SYSTEM_MODE_NUM else NEW_SYSTEM_MODE_NUM=1 echo "$(basename "$0"): System mode is broken. Fixing it to DEV" fi fi if [ "$CAFE_BOOT_MODE" == "PCFS" ] then if [ $NEW_SYSTEM_MODE_NUM -ne $OLD_SYSTEM_MODE_NUM ] then echo "$(basename "$0"): Changing system mode ${SYSTEM_MODE_NAME_TABLE[$OLD_SYSTEM_MODE_NUM]} to ${SYSTEM_MODE_NAME_TABLE[$NEW_SYSTEM_MODE_NUM]}" sed -i -e "s|\(\).*\(<.*>\)|\1${NEW_SYSTEM_MODE_NUM}\2|" "$FILE_DEST" else echo "$(basename "$0"): Current system mode is ${SYSTEM_MODE_NAME_TABLE[$NEW_SYSTEM_MODE_NUM]}" fi fi if [ $CAFERUN_OPTION_MLC_EMU_LAUNCH -eq 1 ] then local MLC_EMU_TID_HI=$(printf %08x $(($CAFERUN_OPTION_MLC_EMU_TITLEID >> 32 & 0xFFFFFFFF))) local MLC_EMU_TID_LO=$(printf %08x $(($CAFERUN_OPTION_MLC_EMU_TITLEID & 0xFFFFFFFF))) if [ "$MLC_EMU_TID_HI" = "00050010" ] then local MLC_EMU_TITLE_DIR=$CAFE_MLC_DIR/sys/title/$MLC_EMU_TID_HI/$MLC_EMU_TID_LO else local MLC_EMU_TITLE_DIR=$CAFE_MLC_DIR/usr/title/$MLC_EMU_TID_HI/$MLC_EMU_TID_LO fi if [ -f "$MLC_EMU_TITLE_DIR/code/app.xml" ] then local MLC_EMU_OS_VERSION=`sed -n 's|.*\(.*\)|\1|p' "$MLC_EMU_TITLE_DIR/code/app.xml"` CAFERUN_COLDBOOT_OS_VERSION=$(printf %016llx 0x$MLC_EMU_OS_VERSION) else # HDD mode does not require any app.xml if [ "$DISC_EMU_TYPE" != "hdd" -a "$ALLOW_DISCRUN_IN_SOFTLAUNCH" == 0 ] then echo "$(basename "$0") failed: Cannot find title 0x$MLC_EMU_TID_HI$MLC_EMU_TID_LO on MLC emulation" echo " Please cafeinstall before using -t option" exit 7 fi fi # insert system.default_title_id sed -i -e "s|\(\)\(.*\)\(\)|\1${MLC_EMU_TID_HI}${MLC_EMU_TID_LO}\3|" "$FILE_DEST" else if [ -n "$APP_XML_FILE" ] then # get titleId from disc emulation's app.xml DISC_EMU_TID=`sed -n 's|.*\(.*\)|\1|p' "$APP_XML_FILE"` # insert system.default_title_id sed -i -e "s|\(\)\(.*\)\(\)|\1${DISC_EMU_TID}\3|" "$FILE_DEST" else # Is it OK to not update default_title_id for HDD mode? if [ "$DISC_EMU_TYPE" == "hdd" -a -z "$CAFE_WUMAD" ] then echo "" echo "-------" echo "$(basename "$0") WARNING: Title ID is not specified." echo " Use -t option to specify Title ID of application on HDD." echo " Title ID of previously launched app will be used at this time," echo " but launch may fail if it was different from that of application on HDD." echo "-------" echo "" fi fi fi # get app_type from disc emulation's app.xml if [ -n "$APP_XML_FILE" ] then local DISC_EMU_APP_TYPE=`sed -n 's|.*\(.*\)|\1|p' "$APP_XML_FILE"` # insert system.default_app_type sed -i -e "s|\(\)\(.*\)\(\)|\1${DISC_EMU_APP_TYPE}\3|" "$FILE_DEST" fi if [ $CAFERUN_OPTION_SOFT_RESTART -eq 0 ] then # insert OSFlags between and xml tags sed -i -e "s|\(\).*\(<.*>\)|\1${CMD_FLAGS}\2|" "$FILE_DEST" fi # insert default os version, which must be same as os_version of cold boot application's app.xml sed -i -e "s|\(\).*\(<.*>\)|\1${CAFERUN_COLDBOOT_OS_VERSION}\2|" "$FILE_DEST" if [ ! -z "$SYS_XML_MCP_LAUNCH_HINT" ] then # first try to replace the launch hint that's already there set +e STRINGS_REPLACED=$(grep -c default_device_type "$FILE_DEST") set -e if [ $STRINGS_REPLACED -eq 0 ] then # insert launch hint right before the closing of the file sed -i -e "s|\(\)| \${SYS_XML_MCP_LAUNCH_HINT}\<\/default_device_type\>\n&|" "$FILE_DEST" else # replace launch string with new value sed -i -e "s|\(\).*\(<.*>\)|\1${SYS_XML_MCP_LAUNCH_HINT}\2|" "$FILE_DEST" fi else # no hint - remove any that may be there sed -i -e "s|\(\).*\(<.*>\)|\1\2|" "$FILE_DEST" fi } ############################################################################### # set_system_xml_cos_flags ############################################################################### set_system_xml_cos_flags() { # must be called with out errors causing exit # as part of the NAND reboot local ERROR=0 local CMD_FLAGS=$1 local FILE_DEST="$CAFE_SLC_DIR/sys/config/system.xml" # insert OSFlags between and xml tags sed -i -e "s|\(\).*\(<.*>\)|\1${CMD_FLAGS}\2|" "$FILE_DEST" ERROR=$? if [ $ERROR != 0 ] then echo "Setting OSFlags in system.xml - failed result = $ERROR" return $ERROR fi devkitmsg "cos_flags $1" -v -p $SESSION_LAUNCH_CTRL_PORT ERROR=$? if [ $ERROR != 0 ] then echo "devkitmsg \"cos_flags $1\" - failed result = $ERROR" fi return $ERROR } ############################################################################### # update_app_xml ############################################################################### update_app_xml() { local FILE_DEST="$1" local APP_DEFAULT_XML="$CAFE_ROOT/system/bin/ghs/cafe/boot/app_default.xml" check_xml_version "$FILE_DEST" "$APP_DEFAULT_XML" # insert os version sed -i -e "s|\(\).*\(<.*>\)|\1${CAFERUN_COLDBOOT_OS_VERSION}\2|" "$FILE_DEST" } ############################################################################### # update_cos_xml ############################################################################### update_cos_xml() { local FILE_DEST="$1" local CMD_FLAGS="$2" local COS_DEFAULT_XML="$CAFE_ROOT/system/bin/ghs/cafe/boot/cos_default.xml" check_xml_version "$FILE_DEST" "$COS_DEFAULT_XML" local ORIG_CMD_FLAGS="`sed -n -e "s/^.*>\([0-9A-Fa-f]*\)<\/cmdFlags>/\1/p" $COS_DEFAULT_XML`" CMD_FLAGS=$(($((ORIG_CMD_FLAGS & ~0xff)) | $CMD_FLAGS)) # insert OSFlags between and xml tags if different if [ $CMD_FLAGS -ne $ORIG_CMD_FLAGS ]; then sed -i -e "s|\(\).*\(<.*>\)|\1${CMD_FLAGS}\2|" "$FILE_DEST" fi } ############################################################################### # update_meta_xml ############################################################################### update_meta_xml() { local FILE_DEST="$1" local META_DEFAULT_XML="$CAFE_ROOT/system/bin/ghs/cafe/boot/meta_default.xml" local OWN_META_XML="$CAFE_CODE_DIR/../meta/meta.xml" if [ $CAFERUN_OPTION_MLC_EMU_LAUNCH -eq 0 ] then if [ -f "$OWN_META_XML" ]; then ABS_OWN_META_XML=$(cd $(dirname "$OWN_META_XML") && pwd)/$(basename "$OWN_META_XML") ABS_FILE_DEST=$(cd $(dirname "$FILE_DEST") && pwd)/$(basename "$FILE_DEST") if [ $ABS_OWN_META_XML != $ABS_FILE_DEST ] then echo Copy "$OWN_META_XML" to "$FILE_DEST" cp -f "$OWN_META_XML" "$FILE_DEST" fi else check_title_id "$FILE_DEST" "$META_DEFAULT_XML" "$APP_XML_FILE" fi check_xml_version "$FILE_DEST" "$META_DEFAULT_XML" # insert os version sed -i -e "s|\(\).*\(<.*>\)|\1${CAFERUN_COLDBOOT_OS_VERSION}\2|" "$FILE_DEST" echo Updating title id, group id, title version and app type in $FILE_DEST, based on $APP_XML_FILE... # get titleId from disc emulation's app.xml DISC_EMU_TID=`sed -n 's|.*\(.*\)|\1|p' "$APP_XML_FILE"` # insert system.default_title_id sed -i -e "s|\(\)\(.*\)\(\)|\1${DISC_EMU_TID}\3|" "$FILE_DEST" # get group Id from disc emulation's app.xml local DISC_EMU_GID=`sed -n 's|.*\(.*\)|\1|p' "$APP_XML_FILE"` # insert system.default_title_id sed -i -e "s|\(\)\(.*\)\(\)|\1${DISC_EMU_GID}\3|" "$FILE_DEST" # get title version from disc emulation's app.xml local DISC_EMU_TITLEVER_HEX=`sed -n 's|.*\(.*\)|\1|p' "$APP_XML_FILE"` local DISC_EMU_TITLEVER_DECIMAL=`printf "%05u" 0x$DISC_EMU_TITLEVER_HEX` # insert system.default_title_id sed -i -e "s|\(\)\(.*\)\(\)|\1${DISC_EMU_TITLEVER_DECIMAL}\3|" "$FILE_DEST" # else # No need to update meta.xml in $CAFE_META_DIR. # System uses $CAFE_MLC_DIR/title/$MLC_EMU_TID_HI/$MLC_EMU_TID_LO/meta/meta.xml installed by cafeinstall. fi } ############################################################################### # update_boot_logos ############################################################################### update_boot_logos() { local FILE_DEST="$1" # Src files local BOOT_MOVIE_H264="$CAFE_ROOT/system/bin/ghs/cafe/meta/bootMovie.h264" local BOOT_LOGO_TEX_TGA="$CAFE_ROOT/system/bin/ghs/cafe/meta/bootLogoTex.tga" local ICON_TEX_TGA="$CAFE_ROOT/system/bin/ghs/cafe/meta/iconTex.tga" local BOOT_TV_TGA="$CAFE_ROOT/system/bin/ghs/cafe/meta/bootTvTex.tga" local BOOT_DRC_TGA="$CAFE_ROOT/system/bin/ghs/cafe/meta/bootDrcTex.tga" # Dest files local DEST_BOOT_MOVIE_H264="$FILE_DEST/bootMovie.h264" local DEST_BOOT_LOGO_TEX_TGA="$FILE_DEST/bootLogoTex.tga" local DEST_ICON_TEX_TGA="$FILE_DEST/iconTex.tga" local DEST_BOOT_TV_TGA="$FILE_DEST/bootTvTex.tga" local DEST_BOOT_DRC_TGA="$FILE_DEST/bootDrcTex.tga" # Boot Logo should be updated cp -u "$BOOT_MOVIE_H264" "$DEST_BOOT_MOVIE_H264" cp -u "$BOOT_LOGO_TEX_TGA" "$DEST_BOOT_LOGO_TEX_TGA" # Applicaion Boot Textures should be copy if files do not exist if [ ! -f "$DEST_ICON_TEX_TGA" ] then cp -u "$ICON_TEX_TGA" "$DEST_ICON_TEX_TGA" fi if [ ! -f "$DEST_BOOT_TV_TGA" ] then cp -u "$BOOT_TV_TGA" "$DEST_BOOT_TV_TGA" fi if [ ! -f "$DEST_BOOT_DRC_TGA" ] then cp -u "$BOOT_DRC_TGA" "$DEST_BOOT_DRC_TGA" fi } ############################################################################### # check_directory_cygdrive_path ############################################################################### check_directory_cygdrive_path() { if [ -z "$1" ] then echo "$(basename "$0") failed: Please define $2" echo " Please 'export $2=/cygdrive///'" exit 15 fi if [ "${1:0:10}" != "/cygdrive/" ] then echo "$(basename "$0") failed: $2 path must start with /cygdrive/" echo " $2 = $1" echo " Please 'export $2=/cygdrive///'" exit 15 fi } ############################################################################### # create_directory_if_noexist ############################################################################### create_directory_if_noexist() { if [ ! -d "$1" ] then echo "$(basename "$0"): Creating dir: $1" mkdir -m 0777 -p "$1" fi } ############################################################################### # compute_flat_version # # Function to make version checking the Host Bridge easier for comparisons # Imported from hostcheckversion ############################################################################### compute_flat_version() { IFS="." local v=( $1 ) echo $((${v[0]} * 1000000 + ${v[1]} * 10000 + ${v[2]} * 1000 + ${v[3]})) } ################################################################################ # sed # # Wrapper function for /usr/bin/sed. Needed because of a sed bug: when using # some non-UTF-8 encoding formats (ex: Shift-JIS), executing on a file with # multibyte characters, sed can hang. This function forces sed to use the UTF-8 # encoding format, then restores to previous format. ################################################################################ sed() { local saved_lang=$LANG LANG=C.UTF-8 /usr/bin/sed "$@" LANG=$saved_lang } ############################################################################### # main ############################################################################### echo `basename "$BASH_SOURCE"`: using sed workaround while getopts :m:g:e:p:d:k:w:a:o:unxbijqNADLRFcfsryt:l:hH:2Vv:WM:z OPT do case $OPT in m ) echo "$(basename "$0") failed: memmap not supported" >&2 usage exit;; g ) PPC_OS_FLAGS=$(($PPC_OS_FLAGS | $OPTARG));; # set flags to pass to PPC COS p ) DEBUG_PROC_ID="$OPTARG" # specify a process to debug if [ "$((DEBUG_FLAGS & 0xf))" -ne 0 ] then DEBUG_FLAGS=$(($((DEBUG_FLAGS & ~0xf)) | $((DEBUG_PROC_ID & 0xf)))) fi;; d ) DEBUGGER="$OPTARG" # specify a debugger DEBUG_FLAGS=$(($DEBUG_FLAGS | $((DEBUG_PROC_ID & 0xf)))) #export CAFE_RUN_FORCERESTART=1 ;; k ) DEBUG_ELF_FILE="$OPTARG";; # file to send to debugger w ) PPC_OS_FLAGS=$(($PPC_OS_FLAGS | $OPTARG));; # temp hack for RiscWatch a ) DASH_A_ARGS="$OPTARG";; # arguments o ) CAFERUN_COLDBOOT_OS_VERSION="$OPTARG";; b ) CAFERUN_COLDBOOT_OS_VERSION=0x00050010100080${CAFERUN_OS_MAJOR_VERSION};; u ) CAFERUN_COLDBOOT_OS_VERSION=0x000500101000C0${CAFERUN_OS_MAJOR_VERSION};; n ) PPC_OS_FLAGS=$(($PPC_OS_FLAGS | 0x02000));; # specifically enable shared code i ) DEBUG_FLAGS=$(($DEBUG_FLAGS | 16));; # stop in init code R ) DEBUG_FLAGS=$(($DEBUG_FLAGS | 32));; # don't stop in main code j ) DEBUG_FLAGS=$(($DEBUG_FLAGS | 64));; # stop in pre-init code q ) CAFE_SYSLOG_LEVEL=0;; # turn warnings off v ) CAFE_SYSLOG_LEVEL="$OPTARG";; # set a syslog level (0..7) e ) # Use name-spacing to segregate consumers of options BRIDGE_PARAMETERS_WITH_E="$BRIDGE_PARAMETERS_WITH_E -e $OPTARG" if [ "${OPTARG%%:*}" == "mcp" ] then # Parse information for MCP's benefit MCP_INFO_OPTION=${OPTARG#*mcp:} if [ "${MCP_INFO_OPTION%%:*}" == "launch_hint" ] then MCP_LAUNCH_HINT=${MCP_INFO_OPTION#*launch_hint:} fi elif [ "$OPTARG" == "nopcfs" ] then # This is the designation for PCFSServer to disable PCFS echo "$(basename $0): Emulating PCFS Headless Mode." PCFS_HEADLESS_EMUL="-pcfsdisable" elif [ "$OPTARG" == "noFFIO" ] then # This is the designation for PCFSServer to disable Fast File IO echo "$(basename $0): Disabling PCFS Fast File IO." PCFSSERVER_PARAMETERS="$PCFSSERVER_PARAMETERS -noFFIO" elif [ "$OPTARG" == "noCSR" ] then # This is the designation for PCFSServer to disable Combined Send+Recv in MION echo "$(basename $0): Disabling Combined Send+Recv in MION." PCFSSERVER_PARAMETERS="$PCFSSERVER_PARAMETERS -noCSR" elif [ "$OPTARG" == "sdioasdbgr" ] then USE_EXI_AS_DEBUG_CHANNEL=0 elif [ "${OPTARG%%:*}" == "ejectstate" ] then # set the MION eject state (in or out) before launching EJECT_STATE=${OPTARG#*ejectstate:} if [ "$EJECT_STATE" != "in" -a "$EJECT_STATE" != "out" ] then echo "ERROR: invalid ejectstate parameter '$OPTARG'" exit fi elif [ "${OPTARG%%:*}" == "wumad" ] then # set the wumad to the file or directory provided CAFE_WUMAD=${OPTARG#*wumad:} BRIDGE_PARAMETERS="$BRIDGE_PARAMETERS -sata" BRIDGE_PARAMETERS_WITH_E="$BRIDGE_PARAMETERS_WITH_E -e sata" CAFE_RUN_FORCERESTART=1 # validation of wumad parameter is done at the time of creating the DLF. elif [ "${OPTARG%%:*}" == "soft_launch_cafe_elf" ] then # This is the CAFE_ELF of the top-level script # that invoked this script to power cafe on. This is used # to create the disk image CAFERUN_OPTION_CALLED_FROM_CAFEDISCRUN=yes SOFT_LAUNCH_CAFE_ELF=${OPTARG#*soft_launch_cafe_elf:} else # Pile up arguments to FSEmul and parse for hdd bank or pcfsport number BRIDGE_PARAMETERS="$BRIDGE_PARAMETERS -$OPTARG" if [ "${OPTARG%%:*}" == "h" ] then # This is the designation of which hard drive to use RUN_FROM_HDD_BANK=${OPTARG#*h:} fi if [ "${OPTARG%%:*}" == "pcfsport" ] then # This is the designation of which pcfs port number to use PCFS_OVER_SATA_PORT=${OPTARG#*pcfsport:} fi if [ "${OPTARG%%:*}" == "sdio" ] then # Make sure we have an appropriate version of FSEmul to use this option # Host Bridge 3.2.4.4 and beyond have this option source hostcheckversion hbver_flat=$(compute_flat_version $CAFERUN_HOSTBRIDGE_VERSION) if [ $hbver_flat -lt 3024004 ] then # remove the sdio parameter BRIDGE_PARAMETERS=${BRIDGE_PARAMETERS/-sdio} BRIDGE_PARAMETERS_WITH_E=${BRIDGE_PARAMETERS_WITH_E/-sdio} fi fi fi ;; c ) DEBUGGER="cattoucan";; # flag to cat serial to terminal f ) CAFESTOP_ONLY_IF_FSEMUL=1;; # only call cafestop if FSEmul is not running (option for autotest only) s ) CAFERUN_OPTION_SOFT_LAUNCH=1;; # use soft launch to run new app y ) CAFERUN_OPTION_FAST_RELAUNCH=1;; # use soft launch to run new app r ) CAFERUN_OPTION_SOFT_RESTART=1;; # restart current app (also possible with soft launch) F ) export CAFE_RUN_FORCERESTART=1;; # force restart t ) if [[ (( ${#OPTARG} = 18 && ${OPTARG:0:2} = "0x" )) || ${#OPTARG} = 16 ]] # Check for correct ID length. 16 characters, 18 with 0x. then CAFERUN_OPTION_MLC_EMU_LAUNCH=1 CAFERUN_OPTION_MLC_EMU_TITLEID="0x${OPTARG:(-16)}" # Take ID and add 0x in front else echo "Title ID has incorrect length." echo "A correct ID is 18 characters plus 0x in the beginning or 16 without 0x." echo "Ex: 0x1234567812345678 or 1234567812345678" echo "Found: ${OPTARG}" exit fi;; l ) if [ "${OPTARG:(-4)}" != ".rpl" ] then # convert spaces to '|' character so it can be put into a space-delimited list RPL_DIRS="$RPL_DIRS ${OPTARG// /|}" else RPL_FILES="$RPL_FILES ${OPTARG// /|}" fi;; h ) usage exit;; H ) if [ $OPTARG = "disable" ] then HEARTBEAT_DISABLE=$((0x00020000)) elif [ $OPTARG = "enable" ] then HEARTBEAT_DISABLE=0 else usage exit fi;; x ) BRIDGE_PARAMETERS="$BRIDGE_PARAMETERS -sata";; # Tell FSEmul to use sata z ) if [ ! -e "$CAFE_DATA_DIR" ] then echo "Session data directory is missing and needs to sync'd!" echo " Please re-run without the '-z' option." exit fi # Suppress the synctool mirroring of the session data directory export CAFERUN_OPTION_NO_DATA_SYNC=1;; A ) echo "*** -A option is deprecated and has no effect. ATFS is now default file system. ***";; # No effect now D ) echo "$(basename "$0") failed: -D option is deprecated. DVDFS is now unsupported" >&2 usage exit;; L ) IGNORE_VERSION=TRUE;; M ) SYSTEM_MODE="$OPTARG";; # System mode, must be "test" or "dev" \:) echo "$(basename "$0") failed: missing argument" >&2 usage exit;; \?) echo "$(basename "$0") failed: invalid option: -$OPTARG" >&2 usage exit;; esac done shift $(($OPTIND-1)) #if a PCFS over SATA port was not chosen by the command line if [ -z "$PCFS_OVER_SATA_PORT" ] then # if a PCFS port is specified by the environment if [ "$USE_PCFS_OVER_SATA" == "1" ] then # take the port from the environment PCFS_OVER_SATA_PORT=$SESSION_PCFS_SATA_PORT BRIDGE_PARAMETERS="$BRIDGE_PARAMETERS -pcfsport:$SESSION_PCFS_SATA_PORT" echo "$(basename $0): using PCFS over SATA on port $PCFS_OVER_SATA_PORT." else echo "$(basename $0): not using PCFS over SATA" fi fi if [ ! -z "$PCFS_OVER_SATA_PORT" ] then PCFSSERVER_PARAMETERS="$PCFSSERVER_PARAMETERS -c $PCFS_OVER_SATA_PORT" else echo "$(basename $0): PCFS_OVER_SATA_PORT is not set." fi if [ ! -z "$PCFSSERVER_PARAMETERS" ] then echo "$(basename $0): PCFSServer parameters '$PCFSSERVER_PARAMETERS'" fi # bridge parameters must have -h: or -em, otherwise # FSEmul will think it is the old, unsupported launch method if [[ ! "$BRIDGE_PARAMETERS" == *-h:* ]] then if [[ ! "$BRIDGE_PARAMETERS" == *-em* ]] then BRIDGE_PARAMETERS="$BRIDGE_PARAMETERS -em" fi fi # Choose hfio, disc block emulation, WUMAD or HDD mode DISC_EMU_TYPE=hfio if [ "$CAFERUN_OPTION_CALLED_FROM_CAFEDISCRUN" == "yes" ] then if [ -n "$RUN_FROM_HDD_BANK" ] then DISC_EMU_TYPE=hdd echo "$(basename "$0"): Will launch HDD bank $RUN_FROM_HDD_BANK" elif [ -n "$CAFE_WUMAD" ] then # wumad emulation started from cafediscrun DISC_EMU_TYPE=hdd elif [ $CAFERUN_OPTION_SOFT_LAUNCH -eq 1 ] then ALLOW_DISCRUN_IN_SOFTLAUNCH=1 DISC_EMU_TYPE=blockemu BRIDGE_PARAMETERS="$BRIDGE_PARAMETERS -em" # Tell FSEmul to use block emulation explicitly else DISC_EMU_TYPE=blockemu BRIDGE_PARAMETERS="$BRIDGE_PARAMETERS -em" # Tell FSEmul to use block emulation explicitly # Note that FSEmul may continue previous mode (HDD or EMU) # if it gets -sata option fi elif [ -n "$CAFE_WUMAD" ] then # wumad emulation started from caferun DISC_EMU_TYPE=hdd else # default DISC_EMU_TYPE=hfio if [ "$CAFE_BOOT_MODE" == "NAND" ] then if [ "$SYSTEM_MODE" = "test" ] # User specified test through the option then echo "$(basename "$0") Test mode not supported on NAND." exit 25 fi echo "$(basename "$0"): Will use NAND file system" else echo "$(basename "$0"): Will use PCFS file system emulation" fi if [ -n "$RUN_FROM_HDD_BANK" ] then echo "$(basename "$0"): HDD bank $RUN_FROM_HDD_BANK will be attached to odd" fi fi echo "$(basename "$0"): bridge parameters: $BRIDGE_PARAMETERS" # echo "$(basename "$0"): bridge parameters with -e: $BRIDGE_PARAMETERS_WITH_E" CAFERUN_COLDBOOT_OS_VERSION=$(printf %016llx $CAFERUN_COLDBOOT_OS_VERSION) # stop device + previous caferun (unlock files) HOSTSTOP_RVAL=0 if [ $CAFESTOP_ONLY_IF_FSEMUL -eq 0 -o "`ps | grep FSEmul`" != "" ] then source cafestop # cafestop -> hoststop -> sets HOSTSTOP_RVAL if [ $HOSTSTOP_RVAL -ne 0 ] then echo "$(basename "$0") failed: Please connect device and power on." exit 5 fi fi # Exits if not correct version within sourced script source hostcheckversion # abort the script when any command returns an error (non-zero value) after cafestop. set -e # with MULTI 5.3.13 it is no longer required to pass OSReport messages # over the debugger connection. MULTI 5.3.13 will by default read # directly from localhost:6001 if the port needs to be changed use: # the options (change localhost and 6001 as needed): # -console_iphost localhost -console_ipport 6001 # case "${CONSOLE}" in # toucan ) # if [ $CATOUTPUT = 1 -a $DEBUGGER != "cattoucan" ] # then # DEBUG_FLAGS=$(($DEBUG_FLAGS | 128)) # fi # ;; # exi ) # # do nothing # ;; # esac # use SDIO as the debug channel if [ $USE_EXI_AS_DEBUG_CHANNEL -eq 0 ] then DEBUG_FLAGS=$(($DEBUG_FLAGS | 256)) fi CAFE_SYSLOG_LEVEL=$((CAFE_SYSLOG_LEVEL & 7)) PPC_OS_FLAGS=$(($PPC_OS_FLAGS | $HEARTBEAT_DISABLE | $DEBUG_FLAGS | $((CAFE_SYSLOG_LEVEL << 9)))) # copy the STOP flags (0x70) and syslog level flags (0xe00) # move the STDOUT_TO_DBG flag from 0x80 to 0x02 # set 0x1 if PROC_ID != 0 PPC_APP_FLAGS=$(($((PPC_OS_FLAGS & 0x00000e70)) | $(((PPC_OS_FLAGS >> 1) & 0x80)) | $(((PPC_OS_FLAGS >> 6) & 0x02)) | $(((PPC_OS_FLAGS & 0xf) != 0)))) SYSTEM_XML="$CAFE_SLC_DIR/sys/config/system.xml" # Find a temporary directory if [ -z "$CAFE_TEMP" ] then #CAFERUN_WORK_DIR=`cygpath -m "$CYGWIN_PATH/tmp/${SESSION_PATH_PREFIX}caferun"` print "CAFE_TEMP environment variable is not set." exit -13 else CAFERUN_WORK_DIR=`cygpath -m "$CAFE_TEMP/${SESSION_PATH_PREFIX}caferun"` fi create_directory_if_noexist "$CAFERUN_WORK_DIR" # Syncronize the session data directory if multisession and not suppressed if [ $SESSION_MANAGER -eq 1 ] then if [ $CAFERUN_OPTION_NO_DATA_SYNC -eq 0 -a $CAFERUN_OPTION_SOFT_RESTART -eq 0 ] then syncsession export CAFERUN_OPTION_NO_DATA_SYNC=1 fi fi if [ $CAFERUN_OPTION_SOFT_RESTART -eq 0 ] then # Create SLC emulation directory check_directory_cygdrive_path "$CAFE_SLC_DIR" CAFE_SLC_DIR create_directory_if_noexist "$CAFE_SLC_DIR/sys" # Check MLC emulation directory (cafeinstall will create directories) check_directory_cygdrive_path "$CAFE_MLC_DIR" CAFE_MLC_DIR create_directory_if_noexist "$CAFE_MLC_DIR" if [ -n "$1" ] then if [ "$DISC_EMU_TYPE" == "hdd" ] then echo "$(basename "$0"): Specified rpx/elf file is used for setting title id from app.xml only" fi # Processing below is only for disc emulation application CAFE_ELF="`cygpath -a "$1"`" if [ "$SESSION_MANAGER" -eq 1 ] then # Check that the RPX exists if [ ! -e "$CAFE_ELF" ] then echo "$(basename "$0") failed: Cannot find rpx application in $CAFE_ELF" exit 2 fi TMP_SUB_DIR=`basename "$1" ."${CAFE_ELF##*.}"` # Check data TMP directory check_directory_cygdrive_path "$CAFE_DATA_TMP" CAFE_DATA_TMP create_directory_if_noexist "$CAFE_DATA_TMP/$TMP_SUB_DIR" CAFE_ELF_SRC_DIR="$(dirname "$CAFE_ELF")" # Sync CAFE_ELF_SRC_DIR to CAFE_DATA_TMP CAFE_ELF_DIR_DOS=`cygpath -w "$CAFE_ELF_SRC_DIR"` CAFE_DATA_TMP_DOS=`cygpath -w "$CAFE_DATA_TMP/$TMP_SUB_DIR"` if [ "$CAFE_ELF_DIR_DOS" != "$CAFE_DATA_TMP_DOS" ] then # # Don't sync if we are running from the data/tmp folder as this is most-likely # a restart from the Multi debugger. If not, the files are still ok as they were # from a previous sync. # SYNCTOOL_CFG=`cygpath -w "$CAFE_ROOT/system/bin/tool/synctool.code.xml"` SYNCTOOL_LOG=`cygpath -w "$CAFE_DATA_TMP/synctool.log"` set +e synctool.exe -cfgxml "$SYNCTOOL_CFG" "$CAFE_ELF_DIR_DOS" "$CAFE_DATA_TMP_DOS" >> "$SYNCTOOL_LOG" SYNCTOOL_RVAL=$? set -e if [ $SYNCTOOL_RVAL -ne 0 ] then # Alert user to the failure and to the log file echo " Session code sync FAILED with exit code $SYNCTOOL_RVAL!" echo " See $SYNCTOOL_LOG for details." exit 2 fi fi # Repoint the CAFE_ELF to the one in the CAFE_DATA_TMP folder CAFE_ELF="$CAFE_DATA_TMP/$TMP_SUB_DIR/$(basename "$1")" fi case "${CAFE_ELF##*.}" in elf) DEBUG_ELF_FILE="${CAFE_ELF}" if [ -e "${CAFE_ELF%.*}.rpx" ] then CAFE_ELF="${CAFE_ELF%.*}.rpx" fi ;; rpx) if [ -z "$DEBUG_ELF_FILE" ] then if [ -e "${CAFE_ELF%.*}.elf" ] then DEBUG_ELF_FILE="${CAFE_ELF%.*}.elf" fi fi ;; esac if [ "${CAFE_ELF:(-4)}" != ".rpx" ] then echo "$(basename "$0") failed: Please provide rpx application as first argument after run_options" usage exit 6 fi if [ ! -e "$CAFE_ELF" ] then echo "$(basename "$0") failed: Cannot find rpx application in $CAFE_ELF" exit 2 fi CAFE_ELF_DIR="$(dirname "$CAFE_ELF")" # Check content root and that it starts with "/cygdrive/" check_directory_cygdrive_path $CAFE_CONTENT_DIR CAFE_CONTENT_DIR create_directory_if_noexist "$CAFE_CONTENT_DIR" # Check meta directory check_directory_cygdrive_path $CAFE_META_DIR CAFE_META_DIR create_directory_if_noexist "$CAFE_META_DIR" # Check save directory check_directory_cygdrive_path "$CAFE_SAVE_DIR" CAFE_SAVE_DIR create_directory_if_noexist "$CAFE_SAVE_DIR" # Set CAFE_CODE_DIR export CAFE_CODE_DIR=$CAFE_ELF_DIR # title.xml update for command-line argument processing # update_app_xml must come before update_system_xml so that disc's os version is set properly APP_XML_FILE="$CAFE_CODE_DIR/app.xml" update_app_xml "$APP_XML_FILE" COS_XML_FILE="$CAFE_CODE_DIR/cos.xml" update_cos_xml "$COS_XML_FILE" "$PPC_APP_FLAGS" META_XML_FILE="$CAFE_META_DIR/meta.xml" update_meta_xml "$META_XML_FILE" update_arglist "$COS_XML_FILE" "$CAFE_ELF" "$@" update_boot_logos "$CAFE_META_DIR" for dir in $RPL_DIRS do find "${dir//|/ }" -iname '*.rpl' -exec cp '{}' "$CAFE_CODE_DIR" \; done for file in $RPL_FILES do cp "${file//|/ }" "$CAFE_CODE_DIR" done fi if [ $CAFERUN_INS == 0 ] then # Save CAFE_CODE_DIR for caferun -r if [ "$CAFERUN_OPTION_MLC_EMU_LAUNCH" -eq 1 ] then echo "" > "$CAFERUN_WORK_DIR/previous_launch_info.xml" echo "$CAFERUN_OPTION_MLC_EMU_TITLEID" >> "$CAFERUN_WORK_DIR/previous_launch_info.xml" else echo "" > "$CAFERUN_WORK_DIR/previous_launch_info.xml" echo "$CAFE_CODE_DIR" >> "$CAFERUN_WORK_DIR/previous_launch_info.xml" echo "$DISC_EMU_TYPE" >> "$CAFERUN_WORK_DIR/previous_launch_info.xml" echo "$RUN_FROM_HDD_BANK" >> "$CAFERUN_WORK_DIR/previous_launch_info.xml" echo "$DISC_EMU_TID" >> "$CAFERUN_WORK_DIR/previous_launch_info.xml" fi echo "$CAFERUN_COLDBOOT_OS_VERSION" >> "$CAFERUN_WORK_DIR/previous_launch_info.xml" echo "$CAFERUN_OPTION_FAST_RELAUNCH" >> "$CAFERUN_WORK_DIR/previous_launch_info.xml" fi update_system_xml "$SYSTEM_XML" "$PPC_OS_FLAGS" "$SYSTEM_MODE" "$MCP_LAUNCH_HINT" else if [ ! -f "$SYSTEM_XML" ] then echo "$(basename "$0") failed: Please $(basename "$0") an rpx application first" exit 9 fi # Retrieve previous settings CAFERUN_OPTION_MLC_EMU_TITLEID=`sed -n 's|.*\(.*\)|\1|p' "$CAFERUN_WORK_DIR/previous_launch_info.xml"` CAFERUN_OPTION_FAST_RELAUNCH=`sed -n 's|.*\(.*\)|\1|p' "$CAFERUN_WORK_DIR/previous_launch_info.xml"` if [ "$CAFERUN_OPTION_MLC_EMU_TITLEID" != "" ] then CAFERUN_OPTION_MLC_EMU_LAUNCH=1 CAFERUN_COLDBOOT_OS_VERSION=`sed -n 's|.*\(.*\)|\1|p' "$SYSTEM_XML"` else export CAFE_CODE_DIR=`sed -n 's|.*\(.*\)|\1|p' "$CAFERUN_WORK_DIR/previous_launch_info.xml"` DISC_EMU_TYPE=`sed -n 's|.*\(.*\)|\1|p' "$CAFERUN_WORK_DIR/previous_launch_info.xml"` RUN_FROM_HDD_BANK=`sed -n 's|.*\(.*\)|\1|p' "$CAFERUN_WORK_DIR/previous_launch_info.xml"` DISC_EMU_TID=`sed -n 's|.*\(.*\)|\1|p' "$CAFERUN_WORK_DIR/previous_launch_info.xml"` PREV_CAFE_ARGSTR=(`sed -n 's|.*\(.*\)|\1|p' "$CAFE_CODE_DIR/cos.xml"`) CAFE_ELF="$CAFE_CODE_DIR/${PREV_CAFE_ARGSTR[@]:0:1}" CAFERUN_COLDBOOT_OS_VERSION=`sed -n 's|.*\(.*\)|\1|p' "$CAFERUN_WORK_DIR/previous_launch_info.xml"` # Serve up correct ios version from cold boot if [ "$CAFERUN_COLDBOOT_OS_VERSION" == "" ] then CAFERUN_COLDBOOT_OS_VERSION=`sed -n 's|.*\(.*\)|\1|p' "$SYSTEM_XML"` fi if [ "$DISC_EMU_TYPE" != "hdd" ] then if [ ! -f "$CAFE_ELF" ] then echo "$(basename "$0") failed: Could not find $CAFE_ELF" exit 9 fi echo "$(basename "$0"): Restarting $CAFE_ELF" fi fi fi # Check that os version is built if [ "$CAFE_BOOT_MODE" == "PCFS" ] then if [ ! -d "$CAFE_SLC_DIR/sys/title/${CAFERUN_COLDBOOT_OS_VERSION:0:8}/${CAFERUN_COLDBOOT_OS_VERSION:8:8}/code" ] then echo "$(basename "$0") failed: Cannot find OS in ${CAFE_SLC_DIR}/sys/title/${CAFERUN_COLDBOOT_OS_VERSION:0:8}/${CAFERUN_COLDBOOT_OS_VERSION:8:8}/code" exit 8 elif [ `find "$CAFE_SLC_DIR/sys/title/${CAFERUN_COLDBOOT_OS_VERSION:0:8}/${CAFERUN_COLDBOOT_OS_VERSION:8:8}/code" -iname '*.rpl' | wc -l` -eq 0 ] then CAFERUN_OS_VERSION_PARTIAL_UNIQUE_ID=$((0x$CAFERUN_COLDBOOT_OS_VERSION >> 8 & 0xFF)) if [ $CAFERUN_OS_VERSION_PARTIAL_UNIQUE_ID -ge 192 ] # 0xC0 then echo "$(basename "$0") failed: Please build FDEBUG os version $CAFERUN_COLDBOOT_OS_VERSION" elif [ $CAFERUN_OS_VERSION_PARTIAL_UNIQUE_ID -ge 128 ] # 0x80 then echo "$(basename "$0") failed: Please build DEBUG os version $CAFERUN_COLDBOOT_OS_VERSION" echo " or do not use \"$(basename "$0") -b\" to use NDEBUG os version" elif [ $CAFERUN_OS_VERSION_PARTIAL_UNIQUE_ID -ge 64 ] # 0x40 then echo "$(basename "$0") failed: Please build NDEBUG os version $CAFERUN_COLDBOOT_OS_VERSION" echo " or use \"$(basename "$0") -b\" to use DEBUG os version" else echo "$(basename "$0") failed: Non-standard titleId for os version $CAFERUN_COLDBOOT_OS_VERSION" fi exit 8 fi fi # Image upload is not performed anymore # if [ ! -z "$RUN_FROM_HDD_BANK" ] # then # if [ $SKIP_HDD_IMAGE_UPLOAD = 0 ] # then # set +e # preparehdd $RUN_FROM_HDD_BANK "$CAFE_ELF" $BRIDGE_CURRENT_IP_ADDRESS "$CAFERUN_WORK_DIR" # PREPHDD_STAT=$? # if [ ! $PREPHDD_STAT = 0 ]; then # echo "$(basename "$0"): preparehdd found non-mion HDD test to be skipped" # exit $PREPHDD_STAT # fi # set -e # fi # fi ################################################################################ # # Set the eject state # # if the command line used '-e ejctstate:in' or '-e ejctstate:out' # call the MION using the CGI to set to eject state # ################################################################################ if [ ! -z "$EJECT_STATE" ] then mionurl $BRIDGE_CURRENT_IP_ADDRESS /mion/status.cgi operation=eject disc=$EJECT_STATE CMD_RESULT=$? if [ $CMD_RESULT -ne 0 ] then echo "Set ejectstate:'$EJECT_STATE' failed=$CMD_RESULT" echo "Continuing execution, Ignoring ejectstate" fi fi if [ -z "$PCFS_SRV_LOG_DIR" ] then PCFS_SRV_LOG_OUTPUT=/dev/null else PCFS_LOG_TIMESTAMP=`date +"%H%M%S"` PCFS_SRV_LOG_OUTPUT=$PCFS_SRV_LOG_DIR/${SESSION_PATH_PREFIX}pcfs_$PCFS_LOG_TIMESTAMP.txt echo PCFS output logged to $PCFS_SRV_LOG_OUTPUT fi # Prepare host file io. Use nohup to prevent shell CTRL-C from stopping PCFSServer.exe if [ "${CAFE_ELF:(-4)}" == ".rpx" -o "$DISC_EMU_TYPE" == "hdd" ] then if [ "$DISC_EMU_TYPE" == "hfio" ] then MAPDIR_MLC="$(cygpath -w "$CAFE_MLC_DIR")/" MAPDIR_SLC="$(cygpath -w "$CAFE_SLC_DIR")/" MAPDIR_CODE="$(cygpath -w "$CAFE_CODE_DIR")/" MAPDIR_META="$(cygpath -w "$CAFE_META_DIR")/" MAPDIR_CONTENT="$(cygpath -w "$CAFE_CONTENT_DIR")/" MAPDIR_SAVE="$(cygpath -w "$CAFE_SAVE_DIR")/" PCFS_DIR_MAPPING+=(-m /%MLC_EMU_DIR/ "$MAPDIR_MLC") PCFS_DIR_MAPPING+=(-m /%SLC_EMU_DIR/ "$MAPDIR_SLC") PCFS_DIR_MAPPING+=(-m /%DISC_EMU_DIR/code/ "$MAPDIR_CODE") PCFS_DIR_MAPPING+=(-m /%DISC_EMU_DIR/meta/ "$MAPDIR_META") PCFS_DIR_MAPPING+=(-m /%DISC_EMU_DIR/content/ "$MAPDIR_CONTENT") PCFS_DIR_MAPPING+=(-m /%DISC_EMU_DIR/save/ "$MAPDIR_SAVE") else MAPDIR_MLC="$(cygpath -w "$CAFE_MLC_DIR")/" MAPDIR_SLC="$(cygpath -w "$CAFE_SLC_DIR")/" MAPDIR_SAVE="$(cygpath -w "$CAFE_SAVE_DIR")/" PCFS_DIR_MAPPING+=(-m /%MLC_EMU_DIR/ "$MAPDIR_MLC") PCFS_DIR_MAPPING+=(-m /%SLC_EMU_DIR/ "$MAPDIR_SLC") PCFS_DIR_MAPPING+=(-m /%SAVE_EMU_DIR/ "$MAPDIR_SAVE") fi elif [ "$CAFERUN_OPTION_MLC_EMU_LAUNCH" -eq 1 ] then MAPDIR_MLC="$(cygpath -w "$CAFE_MLC_DIR")/" MAPDIR_SLC="$(cygpath -w "$CAFE_SLC_DIR")/" PCFS_DIR_MAPPING+=(-m /%MLC_EMU_DIR/ "$MAPDIR_MLC") PCFS_DIR_MAPPING+=(-m /%SLC_EMU_DIR/ "$MAPDIR_SLC") else # includes HDD case MAPDIR_MLC="$(cygpath -w "$CAFE_MLC_DIR")/" MAPDIR_SLC="$(cygpath -w "$CAFE_SLC_DIR")/" PCFS_DIR_MAPPING+=(-m /%MLC_EMU_DIR/ "$MAPDIR_MLC") PCFS_DIR_MAPPING+=(-m /%SLC_EMU_DIR/ "$MAPDIR_SLC") fi export CAFERUN_INS=1 ELF_NEST_OPT= ELF_NEST_VALUE= if [ "$ALLOW_DISCRUN_IN_SOFTLAUNCH" -eq 1 ] then # the DLF will not be used now - but it has to be made now, # as this is the point where all input environment variables are set correctly # for cafedevrun.sh to run source bootrun -makedlf if [[ ! "$BRIDGE_PARAMETERS_WITH_E" == *soft_launch_cafe_elf* ]] then if [ ! -z "$CAFE_ELF" ] then # we didn't get the ELF name from above. So we must to decide what it is. ELF_NEST_OPT=-e ELF_NEST_VALUE="soft_launch_cafe_elf:$CAFE_ELF" # Since there is no way to communicate new DLF contents into an existing FSEmul, # we need a forceful restart for this case - even though it is softlaunch CAFE_RUN_FORCERESTART=1 fi fi fi if [ "$CAFERUN_OPTION_SOFT_LAUNCH" -eq 1 ] then if [ "$CAFE_RUN_FORCERESTART" -eq 1 ] then echo "**** FORCE REBOOT ****" cafestop sleep 1 cafeon -noprompt $BRIDGE_PARAMETERS_WITH_E $ELF_NEST_OPT "$ELF_NEST_VALUE" sleep 20 fi set +e # try this three times for i in 1 2 3 do PCFS_SYNC_DATE=$(date +%F-%H-%M-%S-)$(expr substr $(date +%N), 1 4) echo "Launching $(basename "$CAFE_ELF") @ sync date [$PCFS_SYNC_DATE]" PCFSServerSync.exe -comment "$(basename "$0"): ----- [$PCFS_SYNC_DATE] Launching $(basename "$CAFE_ELF") -----" \ $PCFS_HEADLESS_EMUL -softlaunch -message "${PCFS_DIR_MAPPING[@]}" CMD_RESULT=$? if [ $CMD_RESULT -eq 0 ] then #if [ $CAFERUN_OPTION_SOFT_LAUNCH -eq 1 -a "$CAFE_BOOT_MODE" == "NAND" ] #then set_system_xml_cos_flags "$PPC_OS_FLAGS" CMD_RESULT=$? #fi if [ $CMD_RESULT -eq 0 ] then # this is softlaunch, and there is no RPX specified. # try to see if we can get it from the user - in case it applies if [ -z "$DISC_EMU_TID" ] then if [ "$CAFERUN_OPTION_MLC_EMU_LAUNCH" -eq 1 ] then DISC_EMU_TID="0x${CAFERUN_OPTION_MLC_EMU_TITLEID:(-16)}" echo "HDD emulation: using command line TID $DISC_EMU_TID" fi fi # still not set despite our attemtps? if [ -z "$DISC_EMU_TID" ] then echo "$(basename "$0") failed: Unable to determine title ID, and it was not specified in the command line." exit 9 fi # this is to phase in adoption smoothly into autotest, # avoiding any changes to tests other than cafediscrun. # We may disable this check later. if [ "$ALLOW_DISCRUN_IN_SOFTLAUNCH" -eq 1 ] then CMD_RESULT=0 if [ "$SYSTEM_MODE" == "prod" -o "$SYSTEM_MODE" == "PROD" ] then echo "Setting system mode to 0" devkitmsg "sys_mode 0" CMD_RESULT=$? elif [ "$SYSTEM_MODE" == "dev" -o "$SYSTEM_MODE" == "DEV" ] then echo "Setting system mode to 1" devkitmsg "sys_mode 1" CMD_RESULT=$? elif [ "$SYSTEM_MODE" == "test" -o "$SYSTEM_MODE" == "TEST" ] then echo "Setting system mode to 2" devkitmsg "sys_mode 2" CMD_RESULT=$? fi if [ ! $CMD_RESULT -eq 0 ] then echo "$(basename "$0") failed: Unable to set system mode to $SYSTEM_MODE" exit 1 fi fi if [ "$CAFERUN_OPTION_FAST_RELAUNCH" -eq 1 ] then if [ "$CAFERUN_OPTION_MLC_EMU_TITLEID" -eq "0xFFFFFFFFFFFFFFFF" ] then COSDEBUG_TID_HI=${DISC_EMU_TITLEID:0:10} COSDEBUG_TID_LO=${DISC_EMU_TITLEID:10:8} else COSDEBUG_TID_HI=${CAFERUN_OPTION_MLC_EMU_TITLEID:0:10} COSDEBUG_TID_LO=${CAFERUN_OPTION_MLC_EMU_TITLEID:10:8} fi # extract the cos arguments local COS_ARGS=`sed -n 's|\(\)\(.*\)\(\)|\1|p' "$FILE_DEST"` cosdebug.sh cos launchex 0x$COSDEBUG_TID_HI 0x$COSDEBUG_TID_LO $COS_ARGS else if [ ! -z "$MCP_LAUNCH_HINT" ] then devkitmsg "title_softlaunch $CAFERUN_COLDBOOT_OS_VERSION $DISC_EMU_TID $MCP_LAUNCH_HINT" -v -p $SESSION_LAUNCH_CTRL_PORT else devkitmsg "title_softlaunch $CAFERUN_COLDBOOT_OS_VERSION $DISC_EMU_TID" -v -p $SESSION_LAUNCH_CTRL_PORT fi fi CMD_RESULT=$? if [ $CMD_RESULT -eq 0 ] then break; fi fi fi # one of previous commands failed, reboot and try again echo "**** BOOTING CATDEV ****" cafestop sleep 5 cafeon -noprompt $BRIDGE_PARAMETERS_WITH_E $ELF_NEST_OPT "$ELF_NEST_VALUE" sleep 20 done set -e else PCFS_SYNC_DATE=$(date +%F-%H-%M-%S-)$(expr substr $(date +%N), 1 4) echo "Starting PCFSServer.exe @ sync date [$PCFS_SYNC_DATE] from $PCFSSERVER_EXE" nohup "$PCFSSERVER_EXE" -r 100 $PCFSSERVER_PARAMETERS $PCFS_HEADLESS_EMUL \ "${PCFS_DIR_MAPPING[@]}" < /dev/null > $PCFS_SRV_LOG_OUTPUT 2>&1 & echo "PCFSServer has started" if [ ! -z "$PCFSSERVER_PARAMETERS" ] then echo "Waiting for PCFSServer initialization..." set +e PCFSServerSync.exe -wait 25000 $PCFS_HEADLESS_EMUL -comment "$(basename $0): [$PCFS_SYNC_DATE] ----- Hard-launch Startup Complete -----" PCFSSERVERSYNC_RVAL=$? set -e if [ $PCFSSERVERSYNC_RVAL -ne 0 ] then echo "PCFSServerSync exited with value $PCFSSERVERSYNC_RVAL!" exit 30 fi echo "PCFSServer initialization complete !" else echo "PCFSServer started without syncronization." fi BOOTRUN_ELF_OPT= BOOTRUN_ELF_VALUE= if [ ! -z $SOFT_LAUNCH_CAFE_ELF ] then BOOTRUN_ELF_OPT=-usedlf BOOTRUN_ELF_VALUE="$SOFT_LAUNCH_CAFE_ELF" fi source bootrun $BOOTRUN_ELF_OPT "$BOOTRUN_ELF_VALUE" fi connect_serial_or_debugger