annotate rvinterf/etmsync/fsmisc.c @ 300:19b846c8abed

fc-fsio: format and preformat commands added
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 02 Mar 2014 01:32:55 +0000
parents
children 8dd522a8d60e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
300
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * Miscellaneous (dangerous!) FFS2 operations
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "etm.h"
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "ffs.h"
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "tmffs2.h"
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "limits.h"
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "ffslimits.h"
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #include "localtypes.h"
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 #include "localstruct.h"
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 #include "exitcodes.h"
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 extern u_char rvi_msg[];
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 extern int rvi_msg_len;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 cmd_format(argc, argv)
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 char **argv;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 {
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 int rc, slen;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 slen = strlen(argv[1]);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 if (slen >= TMFFS_STRING_SIZE) {
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 printf("error: argument exceeds string length limit\n");
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 return;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 }
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 dp = cmdpkt + 1;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 *dp++ = ETM_FFS2;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 *dp++ = TMFFS_FORMAT;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 *dp++ = slen + 1;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 strcpy(dp, argv[1]);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 dp += slen + 1;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 /* magic is 0x2BAD, 16-bit little-endian */
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 *dp++ = 0xAD;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 *dp++ = 0x2B;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 if (rc)
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 return(rc);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 if (rvi_msg_len != 5) {
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 printf("error: TMFFS_FORMAT response has wrong length\n");
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 return(ERROR_TARGET);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 }
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 if (rvi_msg[3]) {
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 report_ffs_err("format", rvi_msg[3]);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 return(ERROR_TARGET);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 }
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 return(0);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 }
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 cmd_preformat()
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 {
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 u_char cmdpkt[6];
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 int rc;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 cmdpkt[1] = ETM_FFS2;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 cmdpkt[2] = TMFFS_PREFORMAT;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 /* magic is 0xDEAD, 16-bit little-endian */
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 cmdpkt[3] = 0xAD;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 cmdpkt[4] = 0xDE;
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 rc = etm_pkt_exch(cmdpkt, 4);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 if (rc)
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 return(rc);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 if (rvi_msg_len != 5) {
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 printf("error: TMFFS_PREFORMAT response has wrong length\n");
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 return(ERROR_TARGET);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 }
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 if (rvi_msg[3]) {
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 report_ffs_err("preformat", rvi_msg[3]);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 return(ERROR_TARGET);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 }
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 return(0);
19b846c8abed fc-fsio: format and preformat commands added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 }