annotate loadtools/flutil.c @ 56:d98137625c0d

fc-loadtool flash: total_size logic implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 23 Jun 2013 20:50:41 +0000
parents
children a10491da8c3a
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 }