mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
Introduce helpers.c
Move some suitable functions there, add it to the Makefile, but leave the declarations in flash.h for now. Corresponding to flashrom svn r1819. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
This commit is contained in:
parent
a60d408a78
commit
6ad6e01e9b
2
Makefile
2
Makefile
@ -353,7 +353,7 @@ CHIP_OBJS = jedec.o stm50.o w39.o w29ee011.o \
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# Library code.
|
# Library code.
|
||||||
|
|
||||||
LIB_OBJS = layout.o flashrom.o udelay.o programmer.o
|
LIB_OBJS = layout.o flashrom.o udelay.o programmer.o helpers.o
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Frontend related stuff.
|
# Frontend related stuff.
|
||||||
|
11
at45db.c
11
at45db.c
@ -215,17 +215,6 @@ int probe_spi_at45db(struct flashctx *flash)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the minimum number of bits needed to represent the given address.
|
|
||||||
* FIXME: use mind-blowing implementation.
|
|
||||||
* FIXME: move to utility module. */
|
|
||||||
static uint32_t address_to_bits(uint32_t addr)
|
|
||||||
{
|
|
||||||
unsigned int lzb = 0;
|
|
||||||
while (((1 << (31 - lzb)) & ~addr) != 0)
|
|
||||||
lzb++;
|
|
||||||
return 32 - lzb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* In case of non-power-of-two page sizes we need to convert the address flashrom uses to the address the
|
/* In case of non-power-of-two page sizes we need to convert the address flashrom uses to the address the
|
||||||
* DataFlash chips use. The latter uses a segmented address space where the page address is encoded in the
|
* DataFlash chips use. The latter uses a segmented address space where the page address is encoded in the
|
||||||
* more significant bits and the offset within the page is encoded in the less significant bits. The exact
|
* more significant bits and the offset within the page is encoded in the less significant bits. The exact
|
||||||
|
12
flash.h
12
flash.h
@ -241,6 +241,14 @@ char *flashbuses_to_text(enum chipbustype bustype);
|
|||||||
int print_supported(void);
|
int print_supported(void);
|
||||||
void print_supported_wiki(void);
|
void print_supported_wiki(void);
|
||||||
|
|
||||||
|
/* helpers.c */
|
||||||
|
uint32_t address_to_bits(uint32_t addr);
|
||||||
|
int bitcount(unsigned long a);
|
||||||
|
int max(int a, int b);
|
||||||
|
int min(int a, int b);
|
||||||
|
char *strcat_realloc(char *dest, const char *src);
|
||||||
|
void tolower_string(char *str);
|
||||||
|
|
||||||
/* flashrom.c */
|
/* flashrom.c */
|
||||||
extern int verbose_screen;
|
extern int verbose_screen;
|
||||||
extern int verbose_logfile;
|
extern int verbose_logfile;
|
||||||
@ -251,13 +259,9 @@ int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, uns
|
|||||||
int erase_flash(struct flashctx *flash);
|
int erase_flash(struct flashctx *flash);
|
||||||
int probe_flash(struct registered_programmer *pgm, int startchip, struct flashctx *fill_flash, int force);
|
int probe_flash(struct registered_programmer *pgm, int startchip, struct flashctx *fill_flash, int force);
|
||||||
int read_flash_to_file(struct flashctx *flash, const char *filename);
|
int read_flash_to_file(struct flashctx *flash, const char *filename);
|
||||||
int min(int a, int b);
|
|
||||||
int max(int a, int b);
|
|
||||||
void tolower_string(char *str);
|
|
||||||
char *extract_param(const char *const *haystack, const char *needle, const char *delim);
|
char *extract_param(const char *const *haystack, const char *needle, const char *delim);
|
||||||
int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len);
|
int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len);
|
||||||
int need_erase(const uint8_t *have, const uint8_t *want, unsigned int len, enum write_granularity gran);
|
int need_erase(const uint8_t *have, const uint8_t *want, unsigned int len, enum write_granularity gran);
|
||||||
char *strcat_realloc(char *dest, const char *src);
|
|
||||||
void print_version(void);
|
void print_version(void);
|
||||||
void print_buildinfo(void);
|
void print_buildinfo(void);
|
||||||
void print_banner(void);
|
void print_banner(void);
|
||||||
|
36
flashrom.c
36
flashrom.c
@ -535,42 +535,6 @@ int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int min(int a, int b)
|
|
||||||
{
|
|
||||||
return (a < b) ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
int max(int a, int b)
|
|
||||||
{
|
|
||||||
return (a > b) ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bitcount(unsigned long a)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
for (; a != 0; a >>= 1)
|
|
||||||
if (a & 1)
|
|
||||||
i++;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tolower_string(char *str)
|
|
||||||
{
|
|
||||||
for (; *str != '\0'; str++)
|
|
||||||
*str = (char)tolower((unsigned char)*str);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *strcat_realloc(char *dest, const char *src)
|
|
||||||
{
|
|
||||||
dest = realloc(dest, strlen(dest) + strlen(src) + 1);
|
|
||||||
if (!dest) {
|
|
||||||
msg_gerr("Out of memory!\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
strcat(dest, src);
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is a somewhat hacked function similar in some ways to strtok().
|
/* This is a somewhat hacked function similar in some ways to strtok().
|
||||||
* It will look for needle with a subsequent '=' in haystack, return a copy of
|
* It will look for needle with a subsequent '=' in haystack, return a copy of
|
||||||
* needle and remove everything from the first occurrence of needle to the next
|
* needle and remove everything from the first occurrence of needle to the next
|
||||||
|
72
helpers.c
Normal file
72
helpers.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the flashrom project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009-2010 Carl-Daniel Hailfinger
|
||||||
|
* Copyright (C) 2013 Stefan Tauner
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "flash.h"
|
||||||
|
|
||||||
|
/* Returns the minimum number of bits needed to represent the given address.
|
||||||
|
* FIXME: use mind-blowing implementation. */
|
||||||
|
uint32_t address_to_bits(uint32_t addr)
|
||||||
|
{
|
||||||
|
unsigned int lzb = 0;
|
||||||
|
while (((1 << (31 - lzb)) & ~addr) != 0)
|
||||||
|
lzb++;
|
||||||
|
return 32 - lzb;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bitcount(unsigned long a)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for (; a != 0; a >>= 1)
|
||||||
|
if (a & 1)
|
||||||
|
i++;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
int max(int a, int b)
|
||||||
|
{
|
||||||
|
return (a > b) ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int min(int a, int b)
|
||||||
|
{
|
||||||
|
return (a < b) ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *strcat_realloc(char *dest, const char *src)
|
||||||
|
{
|
||||||
|
dest = realloc(dest, strlen(dest) + strlen(src) + 1);
|
||||||
|
if (!dest) {
|
||||||
|
msg_gerr("Out of memory!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strcat(dest, src);
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tolower_string(char *str)
|
||||||
|
{
|
||||||
|
for (; *str != '\0'; str++)
|
||||||
|
*str = (char)tolower((unsigned char)*str);
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user