bundleGame 2.46 KB
#!/bin/sh

HOST_TOOL_DIR=$ROOT/usr/sbin
HOST_DATA_DIR=$ROOT/usr/host_data

CONTENT_TOOL=$HOST_TOOL_DIR/mkCmd
TICK_TOOL=$HOST_TOOL_DIR/mkTicket
TICK_SYS_TOOL=$HOST_TOOL_DIR/appTicketFile
GEN_DESC_TOOL=$HOST_TOOL_DIR/gen_desc.pl

DEFAULT_THUMB=$HOST_DATA_DIR/rom_thumb.rgba
DEFAULT_TITLE=$HOST_DATA_DIR/rom_title.txt

AES_KEY="a81902767e25db170f3449c5d94b162f"
AES_IV="a438b3410298747b0c089d8f6d2991a8"

TMP_CMD=/tmp/bb_rom$$.cmd
GEN_BB_CERT=/tmp/bb_cert$$
DESC=/tmp/bb_rom$$.desc

# package a prebuilt rom that will be loaded by the sysapp. creates
# cmd and eticket. takes args: 
#      $1: full pathname of game rom (makerom output file) to be packaged
#      $2: cid
#      $3: rom output name (encrypted)
#      $4: ticket output name
function package_rom {
    
    if ! $CONTENT_TOOL -r $hw_rights -R $sw_rights $recrypt -d $DESC -c $2 $1 $AES_KEY $AES_IV $3 $TMP_CMD 
    then
	echo "failed to package sysapp-loadable game rom and create cmd"
	exit 1
    fi

    # generate bb_cert
    if [ -z "$BB_CERT" ]; then
        BB_CERT=$GEN_BB_CERT
	$ROOT/usr/sbin/bbcert -b 1 -p a81902767e25db170f3449c5d94b162fa81902767e25db170f3449c5d94b162f $BB_CERT
    fi

    # generate the ticket
    if ! $TICK_TOOL $TMP_CMD null $4 $BB_CERT; then
        echo "failed to create rom eticket"
	exit 1
    fi
}

# args:
#   $1: ticket.sys file (created if does not exist)
#   $2: ticket to add
function add_ticket {
    if ! $TICK_SYS_TOOL $1 $2; then
	echo "failed to create ticket.sys"
	exit 1
    fi
}

function usage {
    echo "Usage:"
    echo -n "bundleGame [-e] [-t ticket_file] [-b bbid | -c bbcert] [-i image file(32x32 sgi format)] [-n rom_title_file] [-r hw_rights] [-R sw_rights] rom_in cid_in rom_aes_out ticket_out"
    echo
    echo "where -e is used to require re-encryption."
}

bbid=1
hw_rights=0
sw_rights=0
recrypt=
ticket_file= thumb_file= title_file=
while getopts "c:t:b:i:n:er:R:" a
do
   case $a in
      e) recrypt="-e";;
      t) ticket_file=$OPTARG;;
      b) bbid=$OPTARG;;
      c) BB_CERT=$OPTARG;;
      i) thumb_file=$OPTARG;;
      n) title_file=$OPTARG;;
      r) hw_rights=$OPTARG;;
      R) sw_rights=$OPTARG;;
      *) usage; exit;;
   esac
done
shift `expr $OPTIND - 1`

if [ $# != 4 ]; then
    usage
    exit 1
fi

[ "$thumb_file" != "" ] || thumb_file=$DEFAULT_THUMB
[ "$title_file" != "" ] || title_file=$DEFAULT_TITLE
$GEN_DESC_TOOL $thumb_file $title_file "" $DESC         

package_rom $@

[ "$ticket_file" == "" ] || add_ticket $ticket_file $4
rm -f $DESC $TMP_CMD $GEN_BB_CERT