comparison loadtools/flprogsrec.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-srec and 2 * This module implements the flash program-srec and flash program-m0 commands:
3 * flash program-m0 commands: programming flash using S-record files 3 * programming flash using S-record files as the data source.
4 * as the data source.
5 */ 4 */
6 5
7 #include <sys/types.h> 6 #include <sys/types.h>
8 #include <stdio.h> 7 #include <stdio.h>
9 #include <stdint.h> 8 #include <stdint.h>
23 unsigned long rec_count; 22 unsigned long rec_count;
24 23
25 if (flash_get_cfi(bank) < 0) 24 if (flash_get_cfi(bank) < 0)
26 return(-1); 25 return(-1);
27 bi = flash_bank_info + bank; 26 bi = flash_bank_info + bank;
28 if (bi->cfi->cmdset_style != 2) {
29 fprintf(stderr,
30 "error: this command is currently only implemented for AMD-style flash\n");
31 return(-1);
32 }
33 srr.filename = imgfile; 27 srr.filename = imgfile;
34 resp = open_srec_file(&srr); 28 resp = open_srec_file(&srr);
35 if (resp < 0) 29 if (resp < 0)
36 return(resp); 30 return(resp);
37 resp = flash_id_check(bank, 0); 31 resp = flash_id_check(bank, 0);
38 if (resp) { 32 if (resp) {
39 fclose(srr.openfile); 33 fclose(srr.openfile);
40 return(resp); 34 return(resp);
41 } 35 }
42 sprintf(shortarg, "%lx", (u_long) bi->base_addr); 36 sprintf(shortarg, "%lx", (u_long) bi->base_addr);
43 targv[0] = "AMFB"; 37 targv[0] = bi->ops->loadagent_setbase_cmd;
44 targv[1] = shortarg; 38 targv[1] = shortarg;
45 targv[2] = 0; 39 targv[2] = 0;
46 printf("Setting flash base address: %s %s\n", targv[0], targv[1]); 40 printf("Setting flash base address: %s %s\n", targv[0], targv[1]);
47 tpinterf_make_cmd(targv); 41 tpinterf_make_cmd(targv);
48 if (tpinterf_send_cmd() < 0) { 42 if (tpinterf_send_cmd() < 0) {
52 resp = tpinterf_pass_output(1); 46 resp = tpinterf_pass_output(1);
53 if (resp) { 47 if (resp) {
54 fclose(srr.openfile); 48 fclose(srr.openfile);
55 return(resp); 49 return(resp);
56 } 50 }
57 targv[0] = "AMFW"; 51 targv[0] = bi->ops->loadagent_program_cmd;
58 targv[1] = shortarg; 52 targv[1] = shortarg;
59 targv[2] = longarg; 53 targv[2] = longarg;
60 targv[3] = 0; 54 targv[3] = 0;
61 for (rec_count = 0; ; ) { 55 for (rec_count = 0; ; ) {
62 if (read_s_record(&srr) < 0) { 56 if (read_s_record(&srr) < 0) {
96 "%s line %d: violates word alignment requirement\n", 90 "%s line %d: violates word alignment requirement\n",
97 srr.filename, srr.lineno); 91 srr.filename, srr.lineno);
98 fclose(srr.openfile); 92 fclose(srr.openfile);
99 return(-1); 93 return(-1);
100 } 94 }
101 srr.addr &= bi->cfi->total_size - 1; 95 srr.addr &= bi->geom->total_size - 1;
102 if (srr.addr + srr.datalen > bi->cfi->total_size) { 96 if (srr.addr + srr.datalen > bi->geom->total_size) {
103 fprintf(stderr, 97 fprintf(stderr,
104 "%s line %d: goes past the end of the flash bank\n", 98 "%s line %d: goes past the end of the flash bank\n",
105 srr.filename, srr.lineno); 99 srr.filename, srr.lineno);
106 fclose(srr.openfile); 100 fclose(srr.openfile);
107 return(-1); 101 return(-1);