FreeCalypso > hg > freecalypso-sw
changeset 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 | 278052b6afda |
children | 10996c267de4 |
files | loadtools/Makefile loadtools/flutil.c loadtools/ltflash.c |
diffstat | 3 files changed, 53 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/loadtools/Makefile Sun Jun 23 20:13:59 2013 +0000 +++ b/loadtools/Makefile Sun Jun 23 20:50:41 2013 +0000 @@ -9,7 +9,7 @@ IRAM_OBJS= defpath.o hexdecode.o hwparam.o hwparamstubs.o romload.o \ sercomm.o sertool.o srecreader.o ttypassthru.o -LOADTOOL_OBJS= crc32tab.o defpath.o hexdecode.o hwparam.o labaud.o \ +LOADTOOL_OBJS= crc32tab.o defpath.o flutil.o hexdecode.o hwparam.o labaud.o \ ltdispatch.o ltdump.o ltexit.o ltflash.o ltmain.o ltpassthru.o \ ltscript.o romload.o sercomm.o srecreader.o tpinterf.o \ tpinterf2.o
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loadtools/flutil.c Sun Jun 23 20:50:41 2013 +0000 @@ -0,0 +1,34 @@ +/* + * Miscellaneous utility functions for flash support + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include "flash.h" + +extern struct flash_bank_info flash_bank_info[2]; + +compute_flash_totsize_nsecs(bank) +{ + struct flash_bank_info *bi; + struct flash_region_desc *reg; + + bi = flash_bank_info + bank; + for (reg = bi->bank_desc->regions; reg->nsectors; reg++) { + bi->nsectors += reg->nsectors; + bi->total_size += reg->sector_size * reg->nsectors; + } +} + +/* the following function is used to verify that total_size is a power of 2 */ +count_ones(word) + uint32_t word; +{ + int count; + + for (count = 0; word; word >>= 1) + count += word & 1; + return count; +}
--- a/loadtools/ltflash.c Sun Jun 23 20:13:59 2013 +0000 +++ b/loadtools/ltflash.c Sun Jun 23 20:50:41 2013 +0000 @@ -54,6 +54,7 @@ char *cp, *np, *ep; struct flash_device_desc *tp; int bank; + struct flash_bank_info *bi; if (selected_flash_device) { fprintf(stderr, "%s line %d: duplicate flash setting\n", @@ -93,7 +94,8 @@ ; if (*cp) *cp++ = '\0'; - flash_bank_info[bank].base_addr = strtoul(np, &ep, 16); + bi = flash_bank_info + bank; + bi->base_addr = strtoul(np, &ep, 16); if (*ep) { fprintf(stderr, "%s line %d: syntax error (base addr expected after flash device type)\n", @@ -101,9 +103,21 @@ exit(1); } /* the rest comes from the flash device type */ - flash_bank_info[bank].bank_desc = - selected_flash_device->bank_desc + bank; - /* TODO: call function to init total_size and nsectors */ + bi->bank_desc = selected_flash_device->bank_desc + bank; + compute_flash_totsize_nsecs(bank); + if (count_ones(bi->total_size) != 1) { + fprintf(stderr, +"fc-loadtool internal bug: flash bank %d size for %s is not a power of 2\n", + bank, selected_flash_device->name); + exit(1); + } + if (bi->base_addr & (bi->total_size - 1)) { + fprintf(stderr, +"%s line %d: flash bank %d base addr is not aligned to the bank size (0x%lx)\n", + filename_for_errs, lineno_for_errs, bank, + (u_long) bi->total_size); + exit(1); + } } while (isspace(*cp)) cp++;