#!/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. # ############################################################################### # this script prepares the hard drive to run a HDD-based test, # only in the event that the environment is set up with a HDD number. # The script will create a HD image and burn that to disk # arguments to this script: # $1: hard disk slot - empty means no hard disk # $2: name of the RPX file to generate image from # $3: IP address of MION to upload image to. Defaults to configured bridge # $4: temporary work directory to use - optional, will use $TEMP if not specified IMG_UPLOAD_WINDOWS_PATH= IMG_UPLOAD_HDD_BANK=$1 IMG_UPLOAD_RPX_FILE=$2 IMG_UPLOAD_IP_ADDR=$3 IMG_UPLOAD_WORK_DIR=$4 #NOTE: Autotest is looking for this to determine the # condition of a test that's skipped because of no HDD available IMG_UPLOAD_FORCE_TEST_SKIP=25 DEFAULT_TIMEOUT_SECS=3600 #Versions of the uploader above this one are able to auto-concatenate the header file MIN_AUTOCONCAT_UPLOADER=702 #Local variables used in detecting version IMGUPLOADERV= IMGUPLOADFLAT=0 vpart=0 IMGVF1= ############################################################################### # create_directory_if_noexist ############################################################################### create_directory_if_noexist() { if [ ! -d "$1" ] then echo "$(basename "$0"): Creating dir: $1" mkdir -m 0777 -p "$1" fi } ############################################################################### # usage ############################################################################### usage () { cat < [mion_ip_address] [temp_folder] EOF } ############################################################################### # main ############################################################################### source getbridgetype if [ -z "$IMG_UPLOAD_HDD_BANK" ]; then usage exit 1 fi if [ -z "$IMG_UPLOAD_RPX_FILE" ]; then usage exit 1 fi if [ -z "$IMG_UPLOAD_IP_ADDR" ]; then IMG_UPLOAD_IP_ADDR=$BRIDGE_CURRENT_IP_ADDRESS fi if [ -z "$IMG_UPLOAD_WORK_DIR" ]; then if [ -z "$CAFE_TEMP" ]; then echo "ERROR: unable to find temporary directory for upload" exit 1 fi IMG_UPLOAD_WORK_DIR=$CAFE_TEMP fi if [ "$BRIDGE_TYPE" == "Toucan" ] then echo "Skipping SATA HDD test with non-MION image" echo "PASS or FAIL" exit $IMG_UPLOAD_FORCE_TEST_SKIP fi if [ ! "$BRIDGE_TYPE" == "Mion" ] then echo "Skipping SATA HDD test with non-MION image" echo "PASS or FAIL" exit $IMG_UPLOAD_FORCE_TEST_SKIP fi IMGUPLOADERV=`ImageUploader.exe | grep "Image Uploader by"` if [ -z "$IMGUPLOADERV" ]; then echo "Working around cygwin backtick output limitation" # we really didn't want to create any files here - # but certain versions of Cygwin don't capture the text that # comes out of ImageUploader.exe for some strange unknown reason - # but they are happy to capture the results of 'cat' create_directory_if_noexist "$IMG_UPLOAD_WORK_DIR/hddimage" ImageUploader.exe>"$IMG_UPLOAD_WORK_DIR/hddimage/imguploaderv.txt" IMGUPLOADERV=`cat "$IMG_UPLOAD_WORK_DIR/hddimage/imguploaderv.txt" | grep "Image Uploader by"` fi if [[ $IMGUPLOADERV == *ver.* ]] then IMGUPLOADERV=${IMGUPLOADERV#*.} IMGUPLOADFLAT=0 vpart=0 while [ $vpart -lt 4 ] do # delete all after the first dot IMGVF1=${IMGUPLOADERV%%.*} IMGUPLOADERV=${IMGUPLOADERV#*.} IMGVF1=${IMGVF1//[^0-9]/} ((IMGUPLOADFLAT=IMGUPLOADFLAT*100+IMGVF1)) ((vpart=vpart+1)) done echo Detected ImageUploader flatversion to be $IMGUPLOADFLAT else set IMGUPLOADFLAT=$MIN_AUTOCONCAT_UPLOADER echo "WARNING: Unable to query ImageUploader version" fi ############ # all checks done, prepare for action create_directory_if_noexist "$IMG_UPLOAD_WORK_DIR/hddimage" echo "About to generate HDD image" makecfmsd.sh "$IMG_UPLOAD_RPX_FILE" "$IMG_UPLOAD_WORK_DIR/hddimage/dvdfs.ddi" ret=$? if [ ! $ret = 0 ]; then echo "Unable to create DDI image" exit 1 fi if [[ ! $IMGUPLOADFLAT -lt $MIN_AUTOCONCAT_UPLOADER ]] then echo "Performing direct upload of header" IMG_HEADER_WINDOWS_PATH=`cygpath --windows ${0%/*}/mh_cafe.bin` IMG_FILE_WINDOWS_PATH=`cygpath --windows $IMG_UPLOAD_WORK_DIR/hddimage/dvdfs.ddi` ImageUploader.exe -ip $IMG_UPLOAD_IP_ADDR -upload $IMG_UPLOAD_HDD_BANK "-h:$IMG_HEADER_WINDOWS_PATH" "$IMG_FILE_WINDOWS_PATH" -timeout $DEFAULT_TIMEOUT_SECS ret=$? if [ ! $ret = 0 ]; then echo "Unable to upload image to disk" exit 1 fi else # this is the older uploader, which can only handle one file # so we must create a temp dir and build a full image with header # there cat "${0%/*}/mh_cafe.bin" > "$IMG_UPLOAD_WORK_DIR/hddimage/mion.bin" ret=$? if [ ! $ret = 0 ]; then echo "Unable to copy header file ${0%/*}/mh_cafe.bin" exit 1 fi cat "$IMG_UPLOAD_WORK_DIR/hddimage/dvdfs.ddi" >> "$IMG_UPLOAD_WORK_DIR/hddimage/mion.bin" ret=$? if [ ! $ret = 0 ]; then echo "Unable to concatenate header file and image file" exit 1 fi echo "About to upload HDD image to bank #$IMG_UPLOAD_HDD_BANK" IMG_UPLOAD_WINDOWS_PATH=`cygpath --windows $IMG_UPLOAD_WORK_DIR/hddimage/mion.bin` ImageUploader.exe -ip $IMG_UPLOAD_IP_ADDR -upload $IMG_UPLOAD_HDD_BANK "$IMG_UPLOAD_WINDOWS_PATH" -timeout $DEFAULT_TIMEOUT_SECS ret=$? if [ ! $ret = 0 ]; then echo "Unable to upload image to disk" exit 1 fi fi exit 0