[flashrom] [commit] r1819 - trunk

repository service svn at flashrom.org
Thu Jun 12 02:04:33 CEST 2014


Author: stefanct
Date: Thu Jun 12 02:04:32 2014
New Revision: 1819
URL: http://flashrom.org/trac/flashrom/changeset/1819

Log:
Introduce helpers.c.

Move some suitable functions there, add it to the Makefile, but leave the
declarations in flash.h for now.

Signed-off-by: Stefan Tauner <stefan.tauner at alumni.tuwien.ac.at>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>

Added:
   trunk/helpers.c   (contents, props changed)
Modified:
   trunk/Makefile
   trunk/at45db.c
   trunk/flash.h
   trunk/flashrom.c

Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile	Wed Jun  4 18:17:03 2014	(r1818)
+++ trunk/Makefile	Thu Jun 12 02:04:32 2014	(r1819)
@@ -353,7 +353,7 @@
 ###############################################################################
 # 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.

Modified: trunk/at45db.c
==============================================================================
--- trunk/at45db.c	Wed Jun  4 18:17:03 2014	(r1818)
+++ trunk/at45db.c	Thu Jun 12 02:04:32 2014	(r1819)
@@ -215,17 +215,6 @@
 	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
  * 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

Modified: trunk/flash.h
==============================================================================
--- trunk/flash.h	Wed Jun  4 18:17:03 2014	(r1818)
+++ trunk/flash.h	Thu Jun 12 02:04:32 2014	(r1819)
@@ -241,6 +241,14 @@
 int print_supported(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 */
 extern int verbose_screen;
 extern int verbose_logfile;
@@ -251,13 +259,9 @@
 int erase_flash(struct flashctx *flash);
 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 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);
 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);
-char *strcat_realloc(char *dest, const char *src);
 void print_version(void);
 void print_buildinfo(void);
 void print_banner(void);

Modified: trunk/flashrom.c
==============================================================================
--- trunk/flashrom.c	Wed Jun  4 18:17:03 2014	(r1818)
+++ trunk/flashrom.c	Thu Jun 12 02:04:32 2014	(r1819)
@@ -535,42 +535,6 @@
 	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().
  * 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

Added: trunk/helpers.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/helpers.c	Thu Jun 12 02:04:32 2014	(r1819)
@@ -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);
+}
+




More information about the flashrom mailing list