annotate loadtools/flutil.c @ 146:4d629b6bbcfd

gsm-fw/sprintf: %f implemented, debug output looks correct
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 14 Nov 2013 19:03:52 +0000
parents 336f5cc96810
children 96f56e875862
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++) {
65
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
143 if (m0src) {
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
144 sprintf(s, "%02X", dp[0]);
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
145 sprintf(s + 2, "%02X", dp[1]);
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
146 } else {
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
147 sprintf(s, "%02X", dp[1]);
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
148 sprintf(s + 2, "%02X", dp[0]);
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
149 }
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
150 }
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
151 *s = '\0';
a7da6648a7f8 fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 62
diff changeset
152 }