#!/usr/bin/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. # ############################################################################### FLG=0 #============================== #MAIN FRAMEWORK #This script contains functions #used globally between the #installation and debug scripts # #VERSION 1.9 #============================== #============================== # GLOBAL DEFINES #============================== _initFlags(){ TITLE_USB=2 #debug/install title on USB TITLE_MLC=4 #debug/install title on NAND #launch NOT PCFS TITLE_HINT=$((TITLE_USB|TITLE_MLC)) } initFlags(){ _initFlags DBG_BUILD=8 #is debug build } #============================== # GLOBAL FUNCTIONS #============================== #send message and exit with error die(){ echo "$@" exit 1 } #test if a value is numeric not_numeric(){ printf '%d' "0x$TID" &>/dev/null if [ $? == 0 ];then echo -ne false else echo -ne true fi } #make sure that the user input for title ID is valid ($TID) verifyTID(){ if [ ${#TID} -gt 16 ] || `not_numeric "$TID"`;then die Invalid Title ID fi } #pad the title id ($TID) padTID(){ for((i=${#TID};i<16;++i));do TID=0"$TID" done } doSync(){ trap runTrap INT if [ "$SESSION_MANAGER" == 1 ];then syncsession if [ $? != 0 ];then die Sync Failed fi fi } toLower(){ echo -ne "$@" | tr [:upper:] [:lower:] } nextFile(){ FIL="${tmp[i]}" if [ -z "$FIL" ];then x=0 else x=1 fi } #gets the full filename for the RPX _getRPX(){ #empty? if [ -z "$FIL" ];then #current dir, find rpx tmp=(./*) i=0 nextFile while [ $x != 0 ];do if [ $(toLower "${FIL:${#FIL}-4}") == .rpx ];then tmp= echo Working with RPX:" $FIL " return fi let i=i+1 nextFile done echo No RPX found in current working directory...' Please specify an RPX or CD to a directory with an RPX... ' displayHelp 1 fi #append .rpx FIL="$FIL".rpx #check if the RPX exists if [ ! -f "$FIL" ];then FIL="${FIL/$CAFE_ROOT/\$CAFE_ROOT}" FIL="${FIL/system\/bin\/$TOOLCHAIN\/$PLATFORM/system/bin/\$TOOLCHAIN/\$PLATFORM}" die This file does not exist:" $FIL" fi } getRPX(){ _getRPX #get real path FIL=$(realpath "$FIL") #warn user about debug version if [[ $((FLG&DBG_BUILD)) == 0 && $(awk -v a=$(toLower "$FIL") -v b=/debug 'BEGIN{printf index(a,b)}') != 0 ]];then echo ' =====================WARNING========================== Found a directory that starts with "debug"! If running a DEBUG version, Please specify option "-b" ====================================================== Continuing execution in 3 seconds...' sleep 3 fi } #main trap function _runTrap(){ unset FIL #stop cafe if [ $((FLG&1)) != 0 ];then echo ' 'Stopping cafe... cafestop >/dev/null FLG=$((FLG&(~1))) fi } #trap wrapper runTrap(){ _runTrap exit 0 } #============================== # SCP SCRIPTING #============================== #script writer writeSCP(){ #append \r to the data echo -e "$1\r" >> "$scp" #check if write was successful if [ $? != 0 ];then die ' 'Failed to write custom script fi } #write delay writeSCPDelay(){ writeSCP 'echo ===Bug Work-around===\r sleep 10' } #remove custom script _closeSCP(){ rm -f "$scp" } #close function wrapper closeSCP(){ if [ -e "$scp" ];then _closeSCP fi } #script trap wrapper scpTrap(){ _runTrap closeSCP exit 0 } #open a new script session openSCP(){ #init file names scp="$CAFE_MLC_DIR/xtr$$".scp #trap scpTrap trap scpTrap INT #create the custom script echo -ne '' > "$scp" if [ $? != 0 ];then die ' 'Failed to create the custom script fi #bug work-around writeSCPDelay } #run custom script runSCP(){ #finish off custom script writeSCP '\r exit' #source the custom script FLG=$((FLG|1)) cafeon -nobgd -nosync -c "source '-c' '-q' /vol/storage_hfiomlc01/xtr$$.scp" -c exit FLG=$((FLG&(~1))) #return to previous state _closeSCP } #============================== # RUN DEBUG #============================== #run an RPX for debugging runDBG(){ #where are we debugging from i=$((FLG&TITLE_HINT)) if [ $i == $TITLE_HINT ];then die Cannot specify '-u and -n' elif [ $i != 0 ];then if [ $i == $TITLE_USB ];then i=usb else i=mlc fi i="-e mcp:launch_hint:$i" else i= fi #check if debug build if [ $((FLG&DBG_BUILD)) != 0 ];then i="-b $i" fi #run the RPX for debugging FLG=$((FLG|1)) caferun -d multi -z $i "$FIL" $ARG FLG=$((FLG&(~1))) }