annotate loadtools/flutil.c @ 390:bb4814eb51e4

target-utils abb[rw] commands: call abb_init() to avoid dead hang
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 11 Jun 2014 07:11:16 +0000
parents cd12d1049f91
children f027c6fbe37e
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
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 compute_flash_totsize_nsecs(bank)
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 {
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 struct flash_bank_info *bi;
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 struct flash_region_desc *reg;
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 bi = flash_bank_info + bank;
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 for (reg = bi->bank_desc->regions; reg->nsectors; reg++) {
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 bi->nsectors += reg->nsectors;
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 bi->total_size += reg->sector_size * reg->nsectors;
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 }
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 }
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 /* the following function is used to verify that total_size is a power of 2 */
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 count_ones(word)
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 uint32_t word;
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 {
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 int count;
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 for (count = 0; word; word >>= 1)
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 count += word & 1;
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 return count;
d98137625c0d fc-loadtool flash: total_size logic implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 }
61
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
35
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
36 get_flash_sector_table(bank)
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
37 {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
38 struct flash_bank_info *bi;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
39 struct flash_region_desc *reg;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
40 struct sector_info *sp;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
41 uint32_t offset;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
42 int i;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
43
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
44 bi = flash_bank_info + bank;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
45 if (bi->sectors)
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
46 return(0);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
47 sp = (struct sector_info *) malloc(sizeof(struct sector_info)
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
48 * (bi->nsectors + 1));
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
49 if (!sp) {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
50 fprintf(stderr,
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
51 "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
52 bank);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
53 return(-1);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
54 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
55 bi->sectors = sp;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
56 /* now fill it */
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
57 offset = 0;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
58 for (reg = bi->bank_desc->regions; reg->nsectors; reg++) {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
59 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
60 sp->start = offset;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
61 sp->size = reg->sector_size;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
62 sp++;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
63 offset += reg->sector_size;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
64 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
65 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
66 /* sanity checks */
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
67 if (sp - bi->sectors != bi->nsectors) {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
68 fprintf(stderr,
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
69 "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
70 abort();
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
71 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
72 if (offset != bi->total_size) {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
73 fprintf(stderr,
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
74 "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
75 abort();
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
76 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
77 /* finish */
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
78 sp->start = 0;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
79 sp->size = 0;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
80 return(0);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
81 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
82
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
83 flashcmd_sectors(argc, argv, bank)
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
84 char **argv;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
85 {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
86 struct flash_bank_info *bi;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
87 struct sector_info *sp;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
88
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
89 if (argc > 2) {
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
90 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
91 return(-1);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
92 }
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
93 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
94 return(-1);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
95 bi = flash_bank_info + bank;
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
96 printf("%u sectors in flash bank %d:\n", bi->nsectors, bank);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
97 printf("Offset Size\n");
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
98 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
99 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
100 return(0);
a10491da8c3a fc-loadtool flash support: sector table generation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 56
diff changeset
101 }
62
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
102
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
103 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
104 struct flash_bank_info *bi;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
105 u_long useroff, userlen;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
106 struct sector_info **startp, **endp;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
107 {
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
108 struct sector_info *sp;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
109 uint32_t remlen;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
110
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
111 for (sp = bi->sectors; sp->size; sp++)
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
112 if (sp->start == useroff)
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
113 break;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
114 if (!sp->size) {
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
115 fprintf(stderr,
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
116 "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
117 return(-1);
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
118 }
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
119 *startp = sp;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
120 for (remlen = userlen; remlen; ) {
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
121 if (remlen < sp->size) {
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
122 fprintf(stderr,
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
123 "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
124 return(-1);
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
125 }
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
126 remlen -= sp->size;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
127 sp++;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
128 }
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
129 *endp = sp;
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
130 return(0);
6fb41cfa773d fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 61
diff changeset
131 }
65
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
132
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
133 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
134 u_char *bin;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
135 char *strbuf;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
136 int nwords, m0src;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
137 {
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
138 int i;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
139 u_char *dp;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
140 char *s;
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
141
95
336f5cc96810 fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 65
diff changeset
142 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
143 if (m0src)
96f56e875862 fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 95
diff changeset
144 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
145 else
96f56e875862 fc-loadtool: minor polish in build_flashw_hex_string()
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 95
diff changeset
146 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
147 }
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
148 *s = '\0';
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
149 }
204
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
150
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
151 flash_id_check(bank, repeat)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
152 {
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
153 struct flash_bank_info *bi;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
154 struct flash_bank_desc *bd;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
155 struct flash_idcheck *id;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
156 int stat, fail;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
157 uint16_t rdval;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
158 unsigned cnt;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
159
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
160 bi = flash_bank_info + bank;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
161 if (bi->idcheck_done && !repeat)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
162 return(0);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
163 printf("Performing flash ID check\n");
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
164 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
165 if (stat) {
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
166 bad_w16: fprintf(stderr,
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
167 "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
168 return(-1);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
169 }
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
170 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
171 if (stat)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
172 goto bad_w16;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
173 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
174 if (stat)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
175 goto bad_w16;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
176 bd = bi->bank_desc;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
177 id = bd->idcheck_table;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
178 fail = 0;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
179 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
180 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
181 if (stat)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
182 return(stat); /* error msg already printed */
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
183 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
184 if (rdval == id->expect_val)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
185 printf("PASS\n");
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
186 else {
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
187 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
188 fail = 1;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
189 break;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
190 }
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
191 id++;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
192 }
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
193 /* reset flash to read mode */
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
194 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
195 if (stat) {
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
196 fprintf(stderr,
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
197 "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
198 return(-1);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
199 }
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
200 if (fail)
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
201 return(-1);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
202 bi->idcheck_done = 1;
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
203 return(0);
61c7480b3c50 fc-loadtool: flash idcheck standalone command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 199
diff changeset
204 }