comparison loadtools/flprogbin.c @ 405:a212b4968b29

fc-loadtool flash: another refactoring: geometry vs. command set
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 17 Jun 2014 00:33:05 +0000
parents f027c6fbe37e
children 81d387690063
comparison
equal deleted inserted replaced
404:7daea2476062 405:a212b4968b29
1 /* 1 /*
2 * In this module we are going to implement the flash program-bin command: 2 * This module implements the flash program-bin command:
3 * programming flash using a binary file as the data source. 3 * programming flash using a binary file as the data source.
4 */ 4 */
5 5
6 #include <sys/types.h> 6 #include <sys/types.h>
7 #include <sys/stat.h> 7 #include <sys/stat.h>
36 if (*strtoul_endp) 36 if (*strtoul_endp)
37 goto inv; 37 goto inv;
38 if (flash_get_cfi(bank) < 0) 38 if (flash_get_cfi(bank) < 0)
39 return(-1); 39 return(-1);
40 bi = flash_bank_info + bank; 40 bi = flash_bank_info + bank;
41 if (bi->cfi->cmdset_style != 2) { 41 if (flashoff >= bi->geom->total_size) {
42 fprintf(stderr,
43 "error: this command is currently only implemented for AMD-style flash\n");
44 return(-1);
45 }
46 if (flashoff >= bi->cfi->total_size) {
47 fprintf(stderr, 42 fprintf(stderr,
48 "error: specified flash offset exceeds bank size (0x%lx)\n", 43 "error: specified flash offset exceeds bank size (0x%lx)\n",
49 (u_long) bi->cfi->total_size); 44 (u_long) bi->geom->total_size);
50 return(-1); 45 return(-1);
51 } 46 }
52 if (flashoff & 1) { 47 if (flashoff & 1) {
53 fprintf(stderr, "error: flash offset must be even\n"); 48 fprintf(stderr, "error: flash offset must be even\n");
54 return(-1); 49 return(-1);
95 if (!len) { 90 if (!len) {
96 printf("Length is zero - nothing to do!\n"); 91 printf("Length is zero - nothing to do!\n");
97 fclose(binf); 92 fclose(binf);
98 return(0); 93 return(0);
99 } 94 }
100 if (len > bi->cfi->total_size - flashoff) { 95 if (len > bi->geom->total_size - flashoff) {
101 fprintf(stderr, 96 fprintf(stderr,
102 "error: specified flash offset+length exceed bank size (0x%lx)\n", 97 "error: specified flash offset+length exceed bank size (0x%lx)\n",
103 (u_long) bi->cfi->total_size); 98 (u_long) bi->geom->total_size);
104 fclose(binf); 99 fclose(binf);
105 return(-1); 100 return(-1);
106 } 101 }
107 if (len & 1) { 102 if (len & 1) {
108 fprintf(stderr, "error: program length must be even\n"); 103 fprintf(stderr, "error: program length must be even\n");
114 if (flash_id_check(bank, 0) < 0) { 109 if (flash_id_check(bank, 0) < 0) {
115 fclose(binf); 110 fclose(binf);
116 return(-1); 111 return(-1);
117 } 112 }
118 sprintf(shortarg, "%lx", (u_long) bi->base_addr); 113 sprintf(shortarg, "%lx", (u_long) bi->base_addr);
119 targv[0] = "AMFB"; 114 targv[0] = bi->ops->loadagent_setbase_cmd;
120 targv[1] = shortarg; 115 targv[1] = shortarg;
121 targv[2] = 0; 116 targv[2] = 0;
122 printf("Setting flash base address: %s %s\n", targv[0], targv[1]); 117 printf("Setting flash base address: %s %s\n", targv[0], targv[1]);
123 tpinterf_make_cmd(targv); 118 tpinterf_make_cmd(targv);
124 if (tpinterf_send_cmd() < 0) { 119 if (tpinterf_send_cmd() < 0) {
129 if (cc) { 124 if (cc) {
130 fclose(binf); 125 fclose(binf);
131 return(cc); 126 return(cc);
132 } 127 }
133 fseek(binf, fileoff, SEEK_SET); 128 fseek(binf, fileoff, SEEK_SET);
134 targv[0] = "AMFW"; 129 targv[0] = bi->ops->loadagent_program_cmd;
135 targv[1] = shortarg; 130 targv[1] = shortarg;
136 targv[2] = longarg; 131 targv[2] = longarg;
137 targv[3] = 0; 132 targv[3] = 0;
138 printf("Programming flash: %lu (0x%lx) bytes\n", len, len); 133 printf("Programming flash: %lu (0x%lx) bytes\n", len, len);
139 origlen = len; 134 origlen = len;