annotate loadtools/flutil.c @ 403:7602443edf0d

fc-loadtool flash: CFI query code implemented, compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 15 Jun 2014 22:06:46 +0000
parents f027c6fbe37e
children a212b4968b29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
56
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * Miscellaneous utility functions for flash support
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdint.h>
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdlib.h>
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include "flash.h"
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 extern struct flash_bank_info flash_bank_info[2];
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
403
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
13 static int
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
14 cfi_read_byte(bi, off, ret16p)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
15 struct flash_bank_info *bi;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
16 int off;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
17 uint16_t *ret16p;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
18 {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
19 return do_r16(bi->base_addr + (off << 1), ret16p);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
20 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
21
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
22 static int
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
23 cfi_read_twobyte(bi, off, retptr)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
24 struct flash_bank_info *bi;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
25 int off;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
26 uint16_t *retptr;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
27 {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
28 uint16_t lo, hi;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
29
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
30 if (cfi_read_byte(bi, off, &lo) < 0)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
31 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
32 lo &= 0xFF;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
33 if (cfi_read_byte(bi, off + 1, &hi) < 0)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
34 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
35 hi &= 0xFF;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
36 *retptr = (hi << 8) | lo;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
37 return(0);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
38 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
39
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
40 static int
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
41 cfi_id_return_to_read_mode(bi)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
42 struct flash_bank_info *bi;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
43 {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
44 if (do_w16(bi->base_addr + 0xAAA, 0xF0)) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
45 fprintf(stderr,
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
46 "unexpected response to w16 when resetting flash to read mode!\n");
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
47 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
48 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
49 return(0);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
50 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
51
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
52 flash_get_cfi(bank)
56
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 {
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 struct flash_bank_info *bi;
403
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
55 struct cfi_info *cfi;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
56 struct flash_region_desc *reg;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
57 int nr;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
58 uint16_t rdval;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
59 uint32_t size_check;
56
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 bi = flash_bank_info + bank;
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
62 if (bi->cfi)
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
63 return(0);
403
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
64 printf("Performing CFI query\n");
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
65 if (do_w16(bi->base_addr + 0xAA, 0x98)) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
66 fprintf(stderr, "unexpected response to w16 - aborting\n");
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
67 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
68 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
69 /* if do_r16() returns -1, error msg has already been printed */
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
70 if (cfi_read_byte(bi, 0x10, &rdval) < 0)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
71 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
72 if (rdval != 'Q') {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
73 noqry: fprintf(stderr, "error: no QRY response from flash\n");
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
74 cfi_id_return_to_read_mode(bi);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
75 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
76 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
77 if (cfi_read_byte(bi, 0x11, &rdval) < 0)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
78 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
79 if (rdval != 'R')
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
80 goto noqry;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
81 if (cfi_read_byte(bi, 0x12, &rdval) < 0)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
82 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
83 if (rdval != 'Y')
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
84 goto noqry;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
85 cfi = malloc(sizeof(struct cfi_info));
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
86 if (!cfi) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
87 fprintf(stderr,
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
88 "unable to malloc buffer for flash bank %d CFI structure\n",
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
89 bank);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
90 cfi_id_return_to_read_mode(bi);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
91 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
92 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
93 if (cfi_read_twobyte(bi, 0x13, &cfi->cmdset_style) < 0) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
94 free_and_immed_out:
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
95 free(cfi);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
96 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
97 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
98 /* total device size */
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
99 if (cfi_read_byte(bi, 0x27, &rdval) < 0)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
100 goto free_and_immed_out;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
101 if (rdval < 20 || rdval > 24) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
102 fprintf(stderr,
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
103 "error: CFI reports unreasonable device size\n");
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
104 free_and_clean_out:
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
105 free(cfi);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
106 cfi_id_return_to_read_mode(bi);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
107 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
108 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
109 cfi->total_size = 1 << rdval;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
110 if (cfi->total_size > bi->bank_desc->align_size) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
111 fprintf(stderr,
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
112 "error: CFI device size 0x%lx exceeds configured maximum 0x%lx\n",
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
113 (u_long) cfi->total_size, bi->bank_desc->align_size);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
114 goto free_and_clean_out;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
115 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
116 if (cfi_read_byte(bi, 0x2C, &rdval) < 0)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
117 goto free_and_immed_out;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
118 if (rdval < 1 || rdval > CFI_MAX_REGIONS) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
119 fprintf(stderr,
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
120 "error: CFI reports unreasonable # of erase regions\n");
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
121 goto free_and_clean_out;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
122 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
123 cfi->nregions = rdval;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
124 cfi->total_sectors = 0;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
125 size_check = 0;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
126 for (nr = 0; nr < cfi->nregions; nr++) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
127 reg = cfi->regions + nr;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
128 if (cfi_read_twobyte(bi, 0x2D + nr*4, &rdval) < 0)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
129 goto free_and_immed_out;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
130 if (rdval > 255) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
131 fprintf(stderr,
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
132 "error: CFI reports unreasonable # of sectors in region %d\n",
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
133 nr);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
134 goto free_and_clean_out;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
135 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
136 reg->nsectors = rdval + 1;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
137 cfi->total_sectors += reg->nsectors;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
138 if (cfi_read_twobyte(bi, 0x2F + nr*4, &rdval) < 0)
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
139 goto free_and_immed_out;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
140 if (rdval < 0x20 || rdval > 0x400) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
141 fprintf(stderr,
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
142 "error: CFI reports unreasonable sector size in region %d\n",
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
143 nr);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
144 goto free_and_clean_out;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
145 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
146 reg->sector_size = rdval << 8;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
147 size_check += reg->sector_size * reg->nsectors;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
148 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
149 if (cfi_id_return_to_read_mode(bi) < 0) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
150 /* error msg already printed */
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
151 free(cfi);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
152 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
153 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
154 if (size_check != cfi->total_size) {
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
155 fprintf(stderr,
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
156 "CFI error: added size of erase regions (%lx) != reported devive size (%lx)\n",
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
157 (u_long) size_check, (u_long) cfi->total_size);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
158 free(cfi);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
159 return(-1);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
160 }
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
161 /* all checks passed */
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
162 bi->cfi = cfi;
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
163 printf(
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
164 "CFI query successful: total size %lx, %u sectors, command set style %04X\n\n",
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
165 (u_long) cfi->total_size, cfi->total_sectors,
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
166 cfi->cmdset_style);
7602443edf0d fc-loadtool flash: CFI query code implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 400
diff changeset
167 return(1);
56
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 }
61
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
169
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
170 get_flash_sector_table(bank)
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
171 {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
172 struct flash_bank_info *bi;
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
173 struct cfi_info *cfi;
61
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
174 struct flash_region_desc *reg;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
175 struct sector_info *sp;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
176 uint32_t offset;
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
177 int nr, i;
61
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
178
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
179 bi = flash_bank_info + bank;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
180 if (bi->sectors)
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
181 return(0);
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
182 i = flash_get_cfi(bank);
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
183 if (i < 0)
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
184 return(i);
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
185 cfi = bi->cfi;
61
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
186 sp = (struct sector_info *) malloc(sizeof(struct sector_info)
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
187 * (cfi->total_sectors + 1));
61
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
188 if (!sp) {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
189 fprintf(stderr,
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
190 "unable to malloc buffer for flash bank %d sector table\n",
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
191 bank);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
192 return(-1);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
193 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
194 bi->sectors = sp;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
195 /* now fill it */
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
196 offset = 0;
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
197 for (nr = 0; nr < cfi->nregions; nr++) {
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
198 reg = cfi->regions + nr;
61
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
199 for (i = 0; i < reg->nsectors; i++) {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
200 sp->start = offset;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
201 sp->size = reg->sector_size;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
202 sp++;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
203 offset += reg->sector_size;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
204 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
205 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
206 /* sanity checks */
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
207 if (sp - bi->sectors != cfi->total_sectors) {
61
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
208 fprintf(stderr,
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
209 "BUG in get_flash_sector_table(): wrong # of sectors at the end\n");
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
210 abort();
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
211 }
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
212 if (offset != cfi->total_size) {
61
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
213 fprintf(stderr,
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
214 "BUG in get_flash_sector_table(): wrong offset at the end\n");
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
215 abort();
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
216 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
217 /* finish */
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
218 sp->start = 0;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
219 sp->size = 0;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
220 return(0);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
221 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
222
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
223 flashcmd_sectors(argc, argv, bank)
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
224 char **argv;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
225 {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
226 struct flash_bank_info *bi;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
227 struct sector_info *sp;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
228
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
229 if (argc > 2) {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
230 fprintf(stderr, "error: too many arguments\n");
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
231 return(-1);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
232 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
233 if (get_flash_sector_table(bank) < 0)
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
234 return(-1);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
235 bi = flash_bank_info + bank;
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
236 printf("%u sectors in flash bank %d:\n", bi->cfi->total_sectors, bank);
61
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
237 printf("Offset Size\n");
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
238 for (sp = bi->sectors; sp->size; sp++)
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
239 printf("%08lX %lx\n", (u_long) sp->start, (u_long) sp->size);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
240 return(0);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
241 }
62
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
242
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
243 get_flash_sector_range(bi, useroff, userlen, startp, endp)
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
244 struct flash_bank_info *bi;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
245 u_long useroff, userlen;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
246 struct sector_info **startp, **endp;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
247 {
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
248 struct sector_info *sp;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
249 uint32_t remlen;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
250
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
251 for (sp = bi->sectors; sp->size; sp++)
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
252 if (sp->start == useroff)
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
253 break;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
254 if (!sp->size) {
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
255 fprintf(stderr,
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
256 "error: specified offset not aligned to a flash sector boundary\n");
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
257 return(-1);
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
258 }
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
259 *startp = sp;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
260 for (remlen = userlen; remlen; ) {
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
261 if (remlen < sp->size) {
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
262 fprintf(stderr,
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
263 "error: specified length not aligned to a flash sector boundary\n");
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
264 return(-1);
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
265 }
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
266 remlen -= sp->size;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
267 sp++;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
268 }
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
269 *endp = sp;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
270 return(0);
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
271 }
65
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
272
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
273 build_flashw_hex_string(bin, strbuf, nwords, m0src)
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
274 u_char *bin;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
275 char *strbuf;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
276 int nwords, m0src;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
277 {
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
278 int i;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
279 u_char *dp;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
280 char *s;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
281
95
336f5cc96810 fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 65
diff changeset
282 for (dp = bin, s = strbuf, i = 0; i < nwords; dp += 2, s += 4, i++) {
199
96f56e875862 fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 95
diff changeset
283 if (m0src)
96f56e875862 fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 95
diff changeset
284 sprintf(s, "%02X%02X", dp[0], dp[1]);
96f56e875862 fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 95
diff changeset
285 else
96f56e875862 fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 95
diff changeset
286 sprintf(s, "%02X%02X", dp[1], dp[0]);
65
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
287 }
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
288 *s = '\0';
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
289 }
204
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
290
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
291 flash_id_check(bank, repeat)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
292 {
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
293 struct flash_bank_info *bi;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
294 struct flash_bank_desc *bd;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
295 struct flash_idcheck *id;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
296 int stat, fail;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
297 uint16_t rdval;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
298 unsigned cnt;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
299
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
300 bi = flash_bank_info + bank;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
301 if (bi->idcheck_done && !repeat)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
302 return(0);
400
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
303 bd = bi->bank_desc;
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
304 if (!bd->idcheck_table || !bd->idcheck_num)
f027c6fbe37e fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 205
diff changeset
305 return(0);
204
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
306 printf("Performing flash ID check\n");
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
307 stat = do_w16(bi->base_addr + 0xAAA, 0xAA);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
308 if (stat) {
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
309 bad_w16: fprintf(stderr,
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
310 "unexpected response to w16 in read ID cmd sequence - aborting\n");
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
311 return(-1);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
312 }
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
313 stat = do_w16(bi->base_addr + 0x554, 0x55);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
314 if (stat)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
315 goto bad_w16;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
316 stat = do_w16(bi->base_addr + 0xAAA, 0x90);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
317 if (stat)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
318 goto bad_w16;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
319 id = bd->idcheck_table;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
320 fail = 0;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
321 for (cnt = 0; cnt < bd->idcheck_num; cnt++) {
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
322 stat = do_r16(bi->base_addr + id->offset, &rdval);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
323 if (stat)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
324 return(stat); /* error msg already printed */
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
325 printf("offset %02X: %04X -- ", (int)id->offset, (int)rdval);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
326 if (rdval == id->expect_val)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
327 printf("PASS\n");
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
328 else {
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
329 printf("FAIL: expected %04X\n", (int)id->expect_val);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
330 fail = 1;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
331 break;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
332 }
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
333 id++;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
334 }
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
335 /* reset flash to read mode */
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
336 stat = do_w16(bi->base_addr + 0xAAA, 0xF0);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
337 if (stat) {
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
338 fprintf(stderr,
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
339 "unexpected response to w16 when resetting flash to read mode!\n");
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
340 return(-1);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
341 }
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
342 if (fail)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
343 return(-1);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
344 bi->idcheck_done = 1;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
345 return(0);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
346 }