summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/common.h4
-rw-r--r--lib/Makemodule.am1
-rw-r--r--lib/common.c (renamed from ubi-utils/ubiutils-common.c)16
-rw-r--r--ubi-utils/Makemodule.am2
-rw-r--r--ubi-utils/include/ubiutils-common.h34
-rw-r--r--ubi-utils/mtdinfo.c7
-rw-r--r--ubi-utils/ubiattach.c7
-rw-r--r--ubi-utils/ubiformat.c11
-rw-r--r--ubi-utils/ubimkvol.c7
-rw-r--r--ubi-utils/ubinfo.c11
-rw-r--r--ubi-utils/ubinize.c13
-rw-r--r--ubi-utils/ubirsvol.c3
12 files changed, 40 insertions, 76 deletions
diff --git a/include/common.h b/include/common.h
index 11e1989..4f0bb9b 100644
--- a/include/common.h
+++ b/include/common.h
@@ -220,6 +220,10 @@ do { \
#include "xalloc.h"
+long long util_get_bytes(const char *str);
+void util_print_bytes(long long bytes, int bracket);
+int util_srand(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index b30a8aa..694a151 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -1,6 +1,7 @@
libmtd_a_SOURCES = \
lib/libmtd.c \
lib/libfec.c \
+ lib/common.c \
lib/libcrc32.c \
lib/libmtd_legacy.c \
lib/libmtd_int.h
diff --git a/ubi-utils/ubiutils-common.c b/lib/common.c
index 5636785..69b03b3 100644
--- a/ubi-utils/ubiutils-common.c
+++ b/lib/common.c
@@ -17,13 +17,13 @@
*/
/*
- * This file contains various common stuff used by UBI utilities.
+ * This file contains various common stuff.
*
* Authors: Artem Bityutskiy
* Adrian Hunter
*/
-#define PROGRAM_NAME "ubiutils"
+#define PROGRAM_NAME "mtd-utils"
#include <sys/time.h>
#include <sys/types.h>
@@ -62,7 +62,7 @@ static int get_multiplier(const char *str)
}
/**
- * ubiutils_get_bytes - convert a string containing amount of bytes into an
+ * util_get_bytes - convert a string containing amount of bytes into an
* integer
* @str: string to convert
*
@@ -70,7 +70,7 @@ static int get_multiplier(const char *str)
* size specifiers. Returns positive amount of bytes in case of success and %-1
* in case of failure.
*/
-long long ubiutils_get_bytes(const char *str)
+long long util_get_bytes(const char *str)
{
char *endp;
long long bytes = strtoull(str, &endp, 0);
@@ -95,7 +95,7 @@ long long ubiutils_get_bytes(const char *str)
}
/**
- * ubiutils_print_bytes - print bytes.
+ * util_print_bytes - print bytes.
* @bytes: variable to print
* @bracket: whether brackets have to be put or not
*
@@ -104,7 +104,7 @@ long long ubiutils_get_bytes(const char *str)
* amount of Kilobytes, Megabytes, or Gigabytes, depending on how big @bytes
* is.
*/
-void ubiutils_print_bytes(long long bytes, int bracket)
+void util_print_bytes(long long bytes, int bracket)
{
const char *p;
@@ -129,14 +129,14 @@ void ubiutils_print_bytes(long long bytes, int bracket)
}
/**
- * ubiutils_srand - randomly seed the standard pseudo-random generator.
+ * util_srand - randomly seed the standard pseudo-random generator.
*
* This helper function seeds the standard libc pseudo-random generator with a
* more or less random value to make sure the 'rand()' call does not return the
* same sequence every time UBI utilities run. Returns zero in case of success
* and a %-1 in case of error.
*/
-int ubiutils_srand(void)
+int util_srand(void)
{
struct timeval tv;
struct timezone tz;
diff --git a/ubi-utils/Makemodule.am b/ubi-utils/Makemodule.am
index dc68f38..f1c50df 100644
--- a/ubi-utils/Makemodule.am
+++ b/ubi-utils/Makemodule.am
@@ -1,4 +1,4 @@
-libubi_a_SOURCES = ubi-utils/libubi.c ubi-utils/ubiutils-common.c ubi-utils/libubi_int.h
+libubi_a_SOURCES = ubi-utils/libubi.c ubi-utils/libubi_int.h
libubi_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include
libubigen_a_SOURCES = ubi-utils/libubigen.c
diff --git a/ubi-utils/include/ubiutils-common.h b/ubi-utils/include/ubiutils-common.h
deleted file mode 100644
index 99c18f7..0000000
--- a/ubi-utils/include/ubiutils-common.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) Artem Bityutskiy, 2007, 2008
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __UBI_UTILS_COMMON_H__
-#define __UBI_UTILS_COMMON_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-long long ubiutils_get_bytes(const char *str);
-void ubiutils_print_bytes(long long bytes, int bracket);
-int ubiutils_srand(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* !__UBI_UTILS_COMMON_H__ */
diff --git a/ubi-utils/mtdinfo.c b/ubi-utils/mtdinfo.c
index a86abd1..11e59c1 100644
--- a/ubi-utils/mtdinfo.c
+++ b/ubi-utils/mtdinfo.c
@@ -34,7 +34,6 @@
#include <libubigen.h>
#include <libmtd.h>
#include "common.h"
-#include "ubiutils-common.h"
/* The variables below are set by command line arguments */
struct args {
@@ -172,7 +171,7 @@ static void print_ubi_info(const struct mtd_info *mtd_info,
printf("Default UBI VID header offset: %d\n", ui.vid_hdr_offs);
printf("Default UBI data offset: %d\n", ui.data_offs);
printf("Default UBI LEB size: ");
- ubiutils_print_bytes(ui.leb_size, 0);
+ util_print_bytes(ui.leb_size, 0);
printf("\n");
printf("Maximum UBI volumes count: %d\n", ui.max_volumes);
}
@@ -306,10 +305,10 @@ static int print_dev_info(libmtd_t libmtd, const struct mtd_info *mtd_info, int
printf("Name: %s\n", mtd.name);
printf("Type: %s\n", mtd.type_str);
printf("Eraseblock size: ");
- ubiutils_print_bytes(mtd.eb_size, 0);
+ util_print_bytes(mtd.eb_size, 0);
printf("\n");
printf("Amount of eraseblocks: %d (", mtd.eb_cnt);
- ubiutils_print_bytes(mtd.size, 0);
+ util_print_bytes(mtd.size, 0);
printf(")\n");
printf("Minimum input/output unit size: %d %s\n",
mtd.min_io_size, mtd.min_io_size > 1 ? "bytes" : "byte");
diff --git a/ubi-utils/ubiattach.c b/ubi-utils/ubiattach.c
index a7c62d0..09f85af 100644
--- a/ubi-utils/ubiattach.c
+++ b/ubi-utils/ubiattach.c
@@ -31,7 +31,6 @@
#include <libubi.h>
#include "common.h"
-#include "ubiutils-common.h"
#define DEFAULT_CTRL_DEV "/dev/ubi_ctrl"
@@ -238,11 +237,11 @@ int main(int argc, char * const argv[])
}
printf("UBI device number %d, total %d LEBs (", dev_info.dev_num, dev_info.total_lebs);
- ubiutils_print_bytes(dev_info.total_bytes, 0);
+ util_print_bytes(dev_info.total_bytes, 0);
printf("), available %d LEBs (", dev_info.avail_lebs);
- ubiutils_print_bytes(dev_info.avail_bytes, 0);
+ util_print_bytes(dev_info.avail_bytes, 0);
printf("), LEB size ");
- ubiutils_print_bytes(dev_info.leb_size, 1);
+ util_print_bytes(dev_info.leb_size, 1);
printf("\n");
libubi_close(libubi);
diff --git a/ubi-utils/ubiformat.c b/ubi-utils/ubiformat.c
index 21409ca..68906f2 100644
--- a/ubi-utils/ubiformat.c
+++ b/ubi-utils/ubiformat.c
@@ -45,7 +45,6 @@
#include <mtd_swab.h>
#include <crc32.h>
#include "common.h"
-#include "ubiutils-common.h"
/* The variables below are set by command line arguments */
struct args {
@@ -130,7 +129,7 @@ static const struct option long_options[] = {
static int parse_opt(int argc, char * const argv[])
{
- ubiutils_srand();
+ util_srand();
args.image_seq = rand();
while (1) {
@@ -143,7 +142,7 @@ static int parse_opt(int argc, char * const argv[])
switch (key) {
case 's':
- args.subpage_size = ubiutils_get_bytes(optarg);
+ args.subpage_size = util_get_bytes(optarg);
if (args.subpage_size <= 0)
return errmsg("bad sub-page size: \"%s\"", optarg);
if (!is_power_of_2(args.subpage_size))
@@ -170,7 +169,7 @@ static int parse_opt(int argc, char * const argv[])
break;
case 'S':
- args.image_sz = ubiutils_get_bytes(optarg);
+ args.image_sz = util_get_bytes(optarg);
if (args.image_sz <= 0)
return errmsg("bad image-size: \"%s\"", optarg);
break;
@@ -791,9 +790,9 @@ int main(int argc, char * const argv[])
if (!args.quiet) {
normsg_cont("mtd%d (%s), size ", mtd.mtd_num, mtd.type_str);
- ubiutils_print_bytes(mtd.size, 1);
+ util_print_bytes(mtd.size, 1);
printf(", %d eraseblocks of ", mtd.eb_cnt);
- ubiutils_print_bytes(mtd.eb_size, 1);
+ util_print_bytes(mtd.eb_size, 1);
printf(", min. I/O size %d bytes\n", mtd.min_io_size);
}
diff --git a/ubi-utils/ubimkvol.c b/ubi-utils/ubimkvol.c
index 7c2a234..fdbc67f 100644
--- a/ubi-utils/ubimkvol.c
+++ b/ubi-utils/ubimkvol.c
@@ -33,7 +33,6 @@
#include <libubi.h>
#include "common.h"
-#include "ubiutils-common.h"
/* The variables below are set by command line arguments */
struct args {
@@ -137,7 +136,7 @@ static int parse_opt(int argc, char * const argv[])
break;
case 's':
- args.bytes = ubiutils_get_bytes(optarg);
+ args.bytes = util_get_bytes(optarg);
if (args.bytes <= 0)
return errmsg("bad volume size: \"%s\"", optarg);
break;
@@ -278,9 +277,9 @@ int main(int argc, char * const argv[])
}
printf("Volume ID %d, size %d LEBs (", vol_info.vol_id, vol_info.rsvd_lebs);
- ubiutils_print_bytes(vol_info.rsvd_bytes, 0);
+ util_print_bytes(vol_info.rsvd_bytes, 0);
printf("), LEB size ");
- ubiutils_print_bytes(vol_info.leb_size, 1);
+ util_print_bytes(vol_info.leb_size, 1);
printf(", %s, name \"%s\", alignment %d\n",
req.vol_type == UBI_DYNAMIC_VOLUME ? "dynamic" : "static",
vol_info.name, vol_info.alignment);
diff --git a/ubi-utils/ubinfo.c b/ubi-utils/ubinfo.c
index cb88f53..82d4f18 100644
--- a/ubi-utils/ubinfo.c
+++ b/ubi-utils/ubinfo.c
@@ -31,7 +31,6 @@
#include <libubi.h>
#include "common.h"
-#include "ubiutils-common.h"
/* The variables below are set by command line arguments */
struct args {
@@ -211,12 +210,12 @@ static int print_vol_info(libubi_t libubi, int dev_num, int vol_id)
printf("Alignment: %d\n", vol_info.alignment);
printf("Size: %d LEBs (", vol_info.rsvd_lebs);
- ubiutils_print_bytes(vol_info.rsvd_bytes, 0);
+ util_print_bytes(vol_info.rsvd_bytes, 0);
printf(")\n");
if (vol_info.type == UBI_STATIC_VOLUME) {
printf("Data bytes: ");
- ubiutils_print_bytes(vol_info.data_bytes, 1);
+ util_print_bytes(vol_info.data_bytes, 1);
printf("\n");
}
printf("State: %s\n", vol_info.corrupted ? "corrupted" : "OK");
@@ -240,15 +239,15 @@ static int print_dev_info(libubi_t libubi, int dev_num, int all)
printf("ubi%d\n", dev_info.dev_num);
printf("Volumes count: %d\n", dev_info.vol_count);
printf("Logical eraseblock size: ");
- ubiutils_print_bytes(dev_info.leb_size, 0);
+ util_print_bytes(dev_info.leb_size, 0);
printf("\n");
printf("Total amount of logical eraseblocks: %d (", dev_info.total_lebs);
- ubiutils_print_bytes(dev_info.total_bytes, 0);
+ util_print_bytes(dev_info.total_bytes, 0);
printf(")\n");
printf("Amount of available logical eraseblocks: %d (", dev_info.avail_lebs);
- ubiutils_print_bytes(dev_info.avail_bytes, 0);
+ util_print_bytes(dev_info.avail_bytes, 0);
printf(")\n");
printf("Maximum count of volumes %d\n", dev_info.max_vol_count);
diff --git a/ubi-utils/ubinize.c b/ubi-utils/ubinize.c
index b5ebadc..c85ff9b 100644
--- a/ubi-utils/ubinize.c
+++ b/ubi-utils/ubinize.c
@@ -37,7 +37,6 @@
#include <libiniparser.h>
#include <libubi.h>
#include "common.h"
-#include "ubiutils-common.h"
static const char optionsstr[] =
"-o, --output=<file name> output file name\n"
@@ -110,7 +109,7 @@ static struct args args = {
static int parse_opt(int argc, char * const argv[])
{
- ubiutils_srand();
+ util_srand();
args.image_seq = rand();
while (1) {
@@ -131,13 +130,13 @@ static int parse_opt(int argc, char * const argv[])
break;
case 'p':
- args.peb_size = ubiutils_get_bytes(optarg);
+ args.peb_size = util_get_bytes(optarg);
if (args.peb_size <= 0)
return errmsg("bad physical eraseblock size: \"%s\"", optarg);
break;
case 'm':
- args.min_io_size = ubiutils_get_bytes(optarg);
+ args.min_io_size = util_get_bytes(optarg);
if (args.min_io_size <= 0)
return errmsg("bad min. I/O unit size: \"%s\"", optarg);
if (!is_power_of_2(args.min_io_size))
@@ -145,7 +144,7 @@ static int parse_opt(int argc, char * const argv[])
break;
case 's':
- args.subpage_size = ubiutils_get_bytes(optarg);
+ args.subpage_size = util_get_bytes(optarg);
if (args.subpage_size <= 0)
return errmsg("bad sub-page size: \"%s\"", optarg);
if (!is_power_of_2(args.subpage_size))
@@ -324,7 +323,7 @@ static int read_section(const struct ubigen_info *ui, const char *sname,
sprintf(buf, "%s:vol_size", sname);
p = iniparser_getstring(args.dict, buf, NULL);
if (p) {
- vi->bytes = ubiutils_get_bytes(p);
+ vi->bytes = util_get_bytes(p);
if (vi->bytes <= 0)
return errmsg("bad \"vol_size\" key value \"%s\" (section \"%s\")",
p, sname);
@@ -353,7 +352,7 @@ static int read_section(const struct ubigen_info *ui, const char *sname,
normsg_cont("volume size was not specified in section \"%s\", assume"
" minimum to fit image \"%s\"", sname, *img);
- ubiutils_print_bytes(vi->bytes, 1);
+ util_print_bytes(vi->bytes, 1);
printf("\n");
}
diff --git a/ubi-utils/ubirsvol.c b/ubi-utils/ubirsvol.c
index c469060..69a4ea1 100644
--- a/ubi-utils/ubirsvol.c
+++ b/ubi-utils/ubirsvol.c
@@ -33,7 +33,6 @@
#include <libubi.h>
#include "common.h"
-#include "ubiutils-common.h"
/* The variables below are set by command line arguments */
struct args {
@@ -114,7 +113,7 @@ static int parse_opt(int argc, char * const argv[])
switch (key) {
case 's':
- args.bytes = ubiutils_get_bytes(optarg);
+ args.bytes = util_get_bytes(optarg);
if (args.bytes <= 0)
return errmsg("bad volume size: \"%s\"", optarg);
break;