comparison loadtools/flutil.c @ 61:a10491da8c3a

fc-loadtool flash support: sector table generation implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 24 Jun 2013 17:46:15 +0000
parents d98137625c0d
children 6fb41cfa773d
comparison
equal deleted inserted replaced
60:048329d0888e 61:a10491da8c3a
30 30
31 for (count = 0; word; word >>= 1) 31 for (count = 0; word; word >>= 1)
32 count += word & 1; 32 count += word & 1;
33 return count; 33 return count;
34 } 34 }
35
36 get_flash_sector_table(bank)
37 {
38 struct flash_bank_info *bi;
39 struct flash_region_desc *reg;
40 struct sector_info *sp;
41 uint32_t offset;
42 int i;
43
44 bi = flash_bank_info + bank;
45 if (bi->sectors)
46 return(0);
47 sp = (struct sector_info *) malloc(sizeof(struct sector_info)
48 * (bi->nsectors + 1));
49 if (!sp) {
50 fprintf(stderr,
51 "unable to malloc buffer for flash bank %d sector table\n",
52 bank);
53 return(-1);
54 }
55 bi->sectors = sp;
56 /* now fill it */
57 offset = 0;
58 for (reg = bi->bank_desc->regions; reg->nsectors; reg++) {
59 for (i = 0; i < reg->nsectors; i++) {
60 sp->start = offset;
61 sp->size = reg->sector_size;
62 sp++;
63 offset += reg->sector_size;
64 }
65 }
66 /* sanity checks */
67 if (sp - bi->sectors != bi->nsectors) {
68 fprintf(stderr,
69 "BUG in get_flash_sector_table(): wrong # of sectors at the end\n");
70 abort();
71 }
72 if (offset != bi->total_size) {
73 fprintf(stderr,
74 "BUG in get_flash_sector_table(): wrong offset at the end\n");
75 abort();
76 }
77 /* finish */
78 sp->start = 0;
79 sp->size = 0;
80 return(0);
81 }
82
83 flashcmd_sectors(argc, argv, bank)
84 char **argv;
85 {
86 struct flash_bank_info *bi;
87 struct sector_info *sp;
88
89 if (argc > 2) {
90 fprintf(stderr, "error: too many arguments\n");
91 return(-1);
92 }
93 if (get_flash_sector_table(bank) < 0)
94 return(-1);
95 bi = flash_bank_info + bank;
96 printf("%u sectors in flash bank %d:\n", bi->nsectors, bank);
97 printf("Offset Size\n");
98 for (sp = bi->sectors; sp->size; sp++)
99 printf("%08lX %lx\n", (u_long) sp->start, (u_long) sp->size);
100 return(0);
101 }