pubrom 4.2 KB
#!/bin/sh

MKCMD=$ROOT/usr/sbin/mkCmd
GENDESC=$ROOT/usr/sbin/gen_desc.pl
HOST_DATA_DIR=$ROOT/usr/host_data
DEFAULT_THUMB=$HOST_DATA_DIR/rom_thumb.rgba
DEFAULT_TITLE_IMG=$HOST_DATA_DIR/rom_title.inta
DEFAULT_TITLE=$HOST_DATA_DIR/rom_title.txt
DEFAULT_ISBN=$HOST_DATA_DIR/isbn.txt
DEFAULT_CRID=$HOST_DATA_DIR/crid.txt
DEFAULT_OADID=$HOST_DATA_DIR/oadid.txt

AES_KEY="a81902767e25db170f3449c5d94b162f"
AES_IV="a438b3410298747b0c089d8f6d2991a8"

desc=/tmp/desc$$
tmp_title=/tmp/title$$

CID_LIST="sm 0x00000001 eeprom=4\n
          sm_e 0x00001001 eeprom=4\n
	  wr 0x00000002 eeprom=4,cpak=1\n
	  wr_j 0x00001002 eeprom=4,cpak=1\n
	  mk 0x00000003 eeprom=4,cpak=2\n
	  mk_e 0x00001003 eeprom=4,cpak=2\n
	  sf 0x00000004 eeprom=4\n
	  sf_e 0x00001004 eeprom=4\n
	  f0x 0x00000005 sram=256\n
	  f0x_e 0x00001005 sram=256\n
	  zelda 0x00000006 sram=256\n
	  zelda_e 0x00001006 sram=256\n
	  dm 0x00000007 eeprom=4\n
	  dm_e 0x00001007 eeprom=4\n
	  usbmon 0x00000008 ''\n
          batman 0x00000009 ''\n
          hydro  0x0000000a cpak=4,errataSize=16384,errataAddress=0x807bc000\n
          quake2 0x0000000b cpak=4\n
          sfrush  0x0000000c cpak=4,errataSize=16384,errataAddress=0x807bc000\n
          rogue  0x0000000d eeprom=4,errataSize=16384,errataAddress=0x807bc000\n
          naboo  0x0000000e eeprom=4,errataSize=16384,errataAddress=0x807bc000\n
          golden  0x0000000f eeprom=4,errataSize=16384,errataAddress=0x807bc000\n
          iqueclub 0x0000ffff ''\n
	  end xxxxxxxx ''\n"

function find_cid {
    echo -e $CID_LIST | while read name value meta; do
	if [ $1 == $name ]; then
	    echo $value
	    return 1;
	elif [ $name == end ]; then
	    echo $1;
	    return 1;
	fi
    done
}
function find_meta {
    echo -e $CID_LIST | while read name value meta; do
	if [ $1 == $name ]; then
	    echo $meta
	    return 1;
	elif [ $name == end ]; then
	    echo "";
	    return 1;
	fi
    done
}
function usage {

    echo "Usage: pubrom [-e] [-i image_file] [-T title_img_file] [-n title_file | -t title_string] [-s isbn_file] [-c crid_file] [-o oadid_file] [-r hw_rights] [-R sk_rights][-L caCrlVersion] [-l cpCrlVersion] [-m metadata] [-p prop_file_out] rom cid"

    exit 1
}

recrypt="-e"
thumb_file= title_file= title_string= isbn_file= crid_file= oadid_file= signer_key= pub_prop_file= 
keep_desc="n"
while getopts "i:T:n:eEt:s:c:o:r:R:m:S:dp:L:l:" a
do
   case $a in
      e) recrypt="-e";;
      E) recrypt="";;
      i) thumb_file=$OPTARG;;
      T) title_img=$OPTARG;;
      n) title_file=$OPTARG;;
      t) title_string=$OPTARG;;
      s) isbn_file=$OPTARG;;
      c) crid_file=$OPTARG;;
      o) oadid_file=$OPTARG;;
      r) rights="-r $OPTARG";;
      R) Rights="-R $OPTARG";;
      L) caCrlVersion="-L $OPTARG";;
      l) cpCrlVersion="-l $OPTARG";;
      m) metadata="$OPTARG";;
      S) signer_key="-S $OPTARG";;
      d) keep_desc="y";;
      p) pub_prop_file="-p $OPTARG";;
      *) usage; exit;;
   esac
done
shift `expr $OPTIND - 1`

[ $# != 2 ] && usage

cid=`find_cid $2`
[ "$metadata" != "" ] || metadata=`find_meta $2`
name=`perl -e 'printf "%08x\n", '$cid;`
rom=$1
# default usbmon to all rights and no re-encryption
if [ $name == 00000008 ]; then
    rights="-r 0xffffffff"
    recrypt=
fi
# default iqueclub to no re-encryption, with fs & sk rights
if [ $name == 0000ffff ]; then
    rights="-r 0x00000013 -R 0x00006001"
    recrypt=
fi

[ "$thumb_file" != "" ] || thumb_file=$DEFAULT_THUMB
[ "$title_img" != "" ] || title_img=$DEFAULT_TITLE_IMG
[ "$title_file" != "" ] || title_file=$DEFAULT_TITLE
[ "$isbn_file" != "" ] || isbn_file=$DEFAULT_ISBN
[ "$crid_file" != "" ] || crid_file=$DEFAULT_CRID
[ "$oadid_file" != "" ] || oadid_file=$DEFAULT_OADID
if [ -n "$title_string" ]; then
    echo -n $title_string > $tmp_title
    title_file=$tmp_title
fi
# force iqueclub title to be "iQue Club"
if [ $name == 0000ffff ]; then
    echo -n "iQue Club" > $tmp_title
    title_file=$tmp_title
fi

$GENDESC $thumb_file $title_img $title_file "$metadata" $isbn_file $crid_file $oadid_file $desc         

$MKCMD $pub_prop_file $rights $Rights $cpCrlVersion $caCrlVersion $recrypt $signer_key -d $desc -c $cid $rom $AES_KEY $AES_IV $name.app $name.cmd

if [ "$keep_desc" == "y" ]; then 
    cp $desc $name.desc
    rm -f $tmp_title
else 
    rm -f $desc $tmp_title
fi