From: Michael Gernoth Date: Wed, 28 Jan 2009 22:34:29 +0000 (+0100) Subject: allow modification of BOARD_DESCRIPTION X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/rsbs2/commitdiff_plain/453260c6d10cd873aae10c392aa275edbb42cefe allow modification of BOARD_DESCRIPTION --- diff --git a/firmware.c b/firmware.c index 6b47e2b..ac83b96 100644 --- a/firmware.c +++ b/firmware.c @@ -152,9 +152,49 @@ void change_properties(unsigned char *fw, int len, struct propaction *paction) } } +void print_boarddescription(unsigned char *bd) +{ + int j; + + for (j = 0; j < 32; j++) { + printf("%02x ", *(bd+j)); + } + printf("\n"); +} + void handle_boarddescription(unsigned char *fw, int len, int patch) { - /* 0x01 0x01 0x50 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x88 0x02 0xac 0x01 0xd0 0x05 0x00 0x00 0x6a 0x3a 0x00 0x00 0x06 0x00 0x01 0x00 0x00 0x00 0x00 0x00 */ + int i; + + for (i = len - (strlen("pdata")+1); i > 0; i--) { + if (FINDSTR(fw+i, "pdata")) { + unsigned char *pos = fw + i + strlen("pdata") + 1; + + /* MAGIC? */ + if (*((unsigned int*)pos) != 0x00002802) { + continue; + } + + pos += 26; + + /* MAGIC2? */ + if (*((unsigned int*)pos) != 0x00500101) { + continue; + } + + printf("0x%08x: BOARD_DESCRIPTION: ", pos-fw); + print_boarddescription(pos); + + if (patch) { + /* Enable ATX and relay power switching */ + pos[22] |= 0x03; + printf("0x%08x: BOARD_DESCRIPTION: ", pos-fw); + print_boarddescription(pos); + } + + break; + } + } } void syntax(char *name) @@ -163,6 +203,7 @@ void syntax(char *name) fprintf(stderr,"parameters as follows:\n"); fprintf(stderr,"\t-d\t\tdisplay all properties of the image\n"); fprintf(stderr,"\t-u\t\tupdate checksum of the image\n"); + fprintf(stderr,"\t-b\t\tmodify BOARD_DESCRIPTION for more power-switch options\n"); fprintf(stderr,"\t-t property\tset 'property' to true\n"); fprintf(stderr,"\t-f property\tset 'property' to false\n"); fprintf(stderr,"\t-w property\tallow read-write access to 'property'\n"); @@ -258,12 +299,13 @@ int main(int argc, char **argv) struct propaction *paction = NULL; int showall = 0; int update_crc = 0; + int patch_bd = 0; int patch_fw = 0; if (argc < 2) syntax(argv[0]); - while ((opt = getopt(argc, argv, "dut:f:w:r:")) != -1) { + while ((opt = getopt(argc, argv, "dubt:f:w:r:")) != -1) { switch(opt) { case 'd': showall = 1; @@ -271,6 +313,9 @@ int main(int argc, char **argv) case 'u': update_crc = 1; break; + case 'b': + patch_bd = 1; + break; case 't': case 'f': case 'w': @@ -350,10 +395,16 @@ int main(int argc, char **argv) printf("\n"); } - if (showall) + if (patch_bd) { + handle_boarddescription(fw, statbuf.st_size -4, 1); + } + + if (showall) { show_properties(fw, statbuf.st_size - 4); + handle_boarddescription(fw, statbuf.st_size -4, 0); + } - if (update_crc || patch_fw) { + if (update_crc || patch_fw || patch_bd) { ret = rsb_crc2(fw, statbuf.st_size, 0x55335053, &crc); if (ret == 4) { *((unsigned int*)(fw + statbuf.st_size - 4)) = crc; diff --git a/set_better_defaults b/set_better_defaults index 7f4250c..51f8011 100755 --- a/set_better_defaults +++ b/set_better_defaults @@ -5,7 +5,7 @@ if [ "$1" = "" ]; then exit 1 fi -./firmware \ +./firmware -b \ -w /default/fw_prop/FP_COMREDIRECT -t /default/fw_prop/FP_COMREDIRECT \ -t /default/fw_prop/FP_REMOTE_POWER \ -w /default/fw_prop/FP_NO_DIAG_PANEL -f /default/fw_prop/FP_NO_DIAG_PANEL \