comparison frbl/test/frbl2.c @ 323:cefa700d1b8f

frbl: beginning of frbl2test
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 05 Mar 2020 22:05:01 +0000
parents
children 43c92df87ac6
comparison
equal deleted inserted replaced
322:6e442ed0f64d 323:cefa700d1b8f
1 #include <sys/types.h>
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <strings.h>
7 #include <unistd.h>
8 #include "srecreader.h"
9
10 extern char *target_ttydev;
11 extern int target_fd;
12 extern struct srecreader srimage;
13
14 #define MAX_IMAGE_LEN 32768
15
16 static u_char codeimage[MAX_IMAGE_LEN];
17 static unsigned codeimage_len;
18 static uint32_t loadaddr;
19
20 read_srec_image()
21 {
22 u_char *writep;
23 uint32_t endaddr;
24 int i;
25
26 if (open_srec_file(&srimage) < 0)
27 exit(1);
28 for (;;) {
29 if (read_s_record(&srimage) < 0)
30 exit(1);
31 switch (srimage.record_type) {
32 case '0':
33 if (srimage.lineno == 1)
34 continue;
35 fprintf(stderr,
36 "%s: S0 record found in line %d (expected in line 1 only)\n",
37 srimage.filename, srimage.lineno);
38 exit(1);
39 case '3':
40 case '7':
41 if (s3s7_get_addr_data(&srimage) < 0)
42 exit(1);
43 break;
44 default:
45 fprintf(stderr,
46 "%s line %d: S%c record type not supported\n",
47 srimage.filename, srimage.lineno,
48 srimage.record_type);
49 exit(1);
50 }
51 if (srimage.record_type == '7')
52 break;
53 /* must be S3 */
54 if (srimage.datalen < 1) {
55 fprintf(stderr,
56 "%s line %d: S3 record has zero data length\n",
57 srimage.filename, srimage.lineno);
58 exit(1);
59 }
60 if (srimage.datalen & 1) {
61 fprintf(stderr,
62 "%s line %d: S3 record has odd data length\n",
63 srimage.filename, srimage.lineno);
64 exit(1);
65 }
66 if (srimage.addr & 1) {
67 fprintf(stderr,
68 "%s line %d: S3 record has odd address\n",
69 srimage.filename, srimage.lineno);
70 exit(1);
71 }
72 /* handle first record */
73 if (!codeimage_len) {
74 endaddr = loadaddr = srimage.addr;
75 writep = codeimage;
76 }
77 if (srimage.addr != endaddr) {
78 fprintf(stderr, "%s line %d: address discontinuity\n",
79 srimage.filename, srimage.lineno);
80 exit(1);
81 }
82 if (codeimage_len + srimage.datalen > MAX_IMAGE_LEN) {
83 fprintf(stderr,
84 "%s line %d: max image length exceeded\n",
85 srimage.filename, srimage.lineno);
86 exit(1);
87 }
88 /* reverse byte order */
89 for (i = 0; i < srimage.datalen; i += 2) {
90 *writep++ = srimage.record[i+6];
91 *writep++ = srimage.record[i+5];
92 }
93 endaddr += srimage.datalen;
94 codeimage_len += srimage.datalen;
95 }
96 /* got S7 */
97 fclose(srimage.openfile);
98 if (!codeimage_len) {
99 fprintf(stderr,
100 "%s line %d: S7 without any preceding S3 data records\n",
101 srimage.filename, srimage.lineno);
102 exit(1);
103 }
104 if (srimage.addr != loadaddr) {
105 fprintf(stderr,
106 "%s line %d: S7 address differs from image load address\n",
107 srimage.filename, srimage.lineno);
108 exit(1);
109 }
110 /* all good */
111 return(0);
112 }
113
114 frbl_test_main()
115 {
116 read_srec_image();
117 /* remainder to be implemented */
118 }