Skip to contentSkip to conversation

Add imls utility command

PATCH RESEND Superseded Marco 2 participants 3 messages Apr 15, 2009 – Apr 28, 2009

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Marco

author
#0 lore raw

PATCH RESEND v5 1/1 Add imls utility command

From: Marco Stornelli <[email protected]>

This patch adds, under tools folder, a new command called imls. Its goal is the same of UBoot's imls but it can be used as Linux shell command. It reads from raw mtd partition and prints the list of the stored images.

---

 tools/imls/Makefile |  106 ++++++++++++++++++++
 tools/imls/README   |   57 +++++++++++
 tools/imls/imls.c   |  270 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 433 insertions(+), 0 deletions(-)
 create mode 100644 tools/imls/Makefile
 create mode 100644 tools/imls/README
 create mode 100644 tools/imls/imls.c
tools/imls/Makefile new file +106 -0
new file mode 100644
index 0000000..d654658
@@ -0,0 +1,106 @@
+#
+# (C) Copyright 2009 Marco Stornelli <[email protected]>
+#
+# 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., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+include $(TOPDIR)/config.mk
+
+HOST_CFLAGS = -Wall -pedantic
+
+# Generated executable files
+BIN_FILES-y += imls
+
+# Source files which exist outside the tools directory
+EXT_OBJ_FILES-y += lib_generic/crc32.o
+EXT_OBJ_FILES-y += lib_generic/md5.o
+EXT_OBJ_FILES-y += lib_generic/sha1.o
+EXT_OBJ_FILES-y += common/image.o
+
+# Source files located in the tools directory
+OBJ_FILES-y += imls.o
+
+# Flattened device tree objects
+LIBFDT_OBJ_FILES-y += fdt.o
+LIBFDT_OBJ_FILES-y += fdt_ro.o
+LIBFDT_OBJ_FILES-y += fdt_rw.o
+LIBFDT_OBJ_FILES-y += fdt_strerror.o
+LIBFDT_OBJ_FILES-y += fdt_wip.o
+
+# now $(obj) is defined
+SRCS	+= $(addprefix $(SRCTREE)/,$(EXT_OBJ_FILES-y:.o=.c))
+SRCS	+= $(addprefix $(SRCTREE)/tools/,$(OBJ_FILES-y:.o=.c))
+SRCS	+= $(addprefix $(SRCTREE)/libfdt/,$(LIBFDT_OBJ_FILES-y:.o=.c))
+BINS	:= $(addprefix $(obj),$(sort $(BIN_FILES-y)))
+LIBFDT_OBJS	:= $(addprefix $(obj),$(LIBFDT_OBJ_FILES-y))
+
+#
+# Use native tools and options
+# Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
+#
+CPPFLAGS   = -idirafter $(SRCTREE)/include \
+		-idirafter $(OBJTREE)/include2 \
+		-idirafter $(OBJTREE)/include \
+	        -I $(SRCTREE)/libfdt \
+		-I $(SRCTREE)/tools \
+		-DUSE_HOSTCC -D__KERNEL_STRICT_NAMES
+CFLAGS     = $(HOST_CFLAGS) $(CPPFLAGS) -O
+
+# No -pedantic switch to avoid libfdt compilation warnings
+FIT_CFLAGS = -Wall $(CPPFLAGS) -O
+
+CC	   = $(CROSS_COMPILER)gcc
+STRIP	   = $(CROSS_COMPILER)strip
+
+ifeq ($(MTD_VERSION),old)
+CPPFLAGS += -DMTD_OLD
+endif
+
+all:	$(BINS)
+
+$(obj)imls:	$(obj)imls.o $(obj)crc32.o $(obj)image.o $(obj)md5.o \
+		$(obj)sha1.o $(LIBFDT_OBJS)
+	$(CC) $(CFLAGS) -o $@ $^
+	$(STRIP) $@
+
+# Some files complain if compiled with -pedantic, use FIT_CFLAGS
+$(obj)image.o: $(SRCTREE)/common/image.c
+	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+
+$(obj)imls.o: imls.c
+	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+
+# Some of the tool objects need to be accessed from outside the tools directory
+$(obj)%.o: $(SRCTREE)/common/%.c
+	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+
+$(obj)%.o: $(SRCTREE)/lib_generic/%.c
+	$(CC) -g $(CFLAGS) -c -o $@ $<
+
+$(obj)%.o: $(SRCTREE)/libfdt/%.c
+	$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+
+clean:
+	rm -rf *.o imls
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
tools/imls/README new file +57 -0

57 lines not on this page · raw message

tools/imls/imls.c new file +270 -0

270 lines not on this page · raw message

#1 lore raw

PATCH RESEND v5 1/1 Add imls utility command

Dear Marco,

Quoted 6 lines · In message <[email protected]> you wrote:

From: Marco Stornelli <[email protected]>

This patch adds, under tools folder, a new command called imls. Its goal is the same of UBoot's imls but it can be used as Linux shell command. It reads from raw mtd partition and prints the list of the stored images.

Hm...

...

Quoted 23 lines
tools/imls/imls.c new file +23 -0
+	while (--argc > 0 && **++argv == '-') {
+		while (*++*argv) {
+			switch (**argv) {
+			case 's':
+				if (--argc <= 0) 
+					usage ();
+				sectorcount = (unsigned int)atoi(*++argv);
+				sflag = 1;
+				goto NXTARG;
+			case 'o':
+				if (--argc <= 0)
+					usage ();
+				sectoroffset = (unsigned int)atoi(*++argv);
+				goto NXTARG;
+
+			case 'c':
+				if (--argc <= 0)
+					usage ();
+				sectorsize = (unsigned int)atoi(*++argv);
+				cflag = 1;
+				goto NXTARG;
+			default:
+				usage ();

...

tools/imls/imls.c line 193

Quoted 6 lines
tools/imls/imls.c new file +6 -0
+	fprintf (stderr, "Usage:\n"
+			 "       %s [-o offset] -c size -s count device\n"
+			 "          -o ==> number of sectors to use as offset\n"
+			 "          -s ==> number of sectors\n"
+			 "          -c ==> size of sectors (byte)\n",
+		cmdname);

I think this is *extremely" misleading.

If I have options "-c" and "-s" and arguments "size" and "count" I will *always" assume that "-s" is for "size" and "-c" is for "count".

Please consider the principle of least surprise
(http://en.wikipedia.org/wiki/Least_surprise) and swap variable resp. option names.

Thanks.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
What is research but a blind date with knowledge?      -- Will Harvey
#2 lore raw

PATCH RESEND v5 1/1 Add imls utility command

2009/4/28 Wolfgang Denk <[email protected]>:

Quoted 44 lines

Dear Marco,

Quoted 6 lines · In message <[email protected]> you wrote:

From: Marco Stornelli <[email protected]>

This patch adds, under tools folder, a new command called imls. Its goal is the same of UBoot's imls but it can be used as Linux shell command. It reads from raw mtd partition and prints the list of the stored images.

Hm...

...

Quoted 23 lines

+ ? ? while (--argc > 0 && **++argv == '-') {
+ ? ? ? ? ? ? while (*++*argv) {
+ ? ? ? ? ? ? ? ? ? ? switch (**argv) {
+ ? ? ? ? ? ? ? ? ? ? case 's':
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (--argc <= 0)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? usage ();
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? sectorcount = (unsigned int)atoi(*++argv);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? sflag = 1;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto NXTARG;
+ ? ? ? ? ? ? ? ? ? ? case 'o':
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (--argc <= 0)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? usage ();
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? sectoroffset = (unsigned int)atoi(*++argv);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto NXTARG;
+
+ ? ? ? ? ? ? ? ? ? ? case 'c':
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (--argc <= 0)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? usage ();
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? sectorsize = (unsigned int)atoi(*++argv);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? cflag = 1;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto NXTARG;
+ ? ? ? ? ? ? ? ? ? ? default:
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? usage ();

...

Quoted 6 lines

+ ? ? fprintf (stderr, "Usage:\n"
+ ? ? ? ? ? ? ? ? ? ? ?" ? ? ? %s [-o offset] -c size -s count device\n"
+ ? ? ? ? ? ? ? ? ? ? ?" ? ? ? ? ?-o ==> number of sectors to use as offset\n"
+ ? ? ? ? ? ? ? ? ? ? ?" ? ? ? ? ?-s ==> number of sectors\n"
+ ? ? ? ? ? ? ? ? ? ? ?" ? ? ? ? ?-c ==> size of sectors (byte)\n",
+ ? ? ? ? ? ? cmdname);

Quoted 4 lines

I think this is *extremely" misleading.

If I have options "-c" and "-s" and arguments "size" and "count" I will *always" assume that "-s" is for "size" and "-c" is for "count".

-s was for "Sector count" but it can be used even as "size", it's a choice. However it's a very simple modification, I'll resend a new version as soon as possible.

Marco

Quoted 17 lines

Please consider the principle of least surprise
(http://en.wikipedia.org/wiki/Least_surprise) and swap variable resp. option names.

Thanks.

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, ? ? MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de What is research but a blind date with knowledge? ? ? ?-- Will Harvey