From cfe19f917ab14b88c677def857fb2413d12f9fb7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 14 Nov 2013 10:58:56 +0900 Subject: [PATCH] tools: imls: Remove a broken and unused tool. It looks like tools/imls/Makefile is invoked from nowhere. And also it is broken. Signed-off-by: Masahiro Yamada --- tools/imls/Makefile | 84 --------------- tools/imls/README | 41 ------- tools/imls/imls.c | 256 -------------------------------------------- 3 files changed, 381 deletions(-) delete mode 100644 tools/imls/Makefile delete mode 100644 tools/imls/README delete mode 100644 tools/imls/imls.c diff --git a/tools/imls/Makefile b/tools/imls/Makefile deleted file mode 100644 index b045df2df0..0000000000 --- a/tools/imls/Makefile +++ /dev/null @@ -1,84 +0,0 @@ -# -# (C) Copyright 2009 Marco Stornelli -# -# SPDX-License-Identifier: GPL-2.0+ -# - -include $(TOPDIR)/config.mk - -# Generated executable files -BIN_FILES-y += imls - -# Source files which exist outside the tools/imls directory -EXT_OBJ_FILES-y += lib/crc32.o -EXT_OBJ_FILES-y += lib/md5.o -EXT_OBJ_FILES-y += lib/sha1.o -EXT_OBJ_FILES-y += common/image.o - -# Source files located in the tools/imls 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)/lib/libfdt/,$(LIBFDT_OBJ_FILES-y:.o=.c)) -BINS := $(addprefix $(obj),$(sort $(BIN_FILES-y))) -LIBFDT_OBJS := $(addprefix $(obj),$(LIBFDT_OBJ_FILES-y)) - -# -# Compile for a hosted environment on the target -# Define __KERNEL_STRICT_NAMES to prevent typedef overlaps -# -HOSTCPPFLAGS = -idirafter $(SRCTREE)/include \ - -idirafter $(SRCTREE)/arch/$(ARCH)/include \ - -idirafter $(OBJTREE)/include \ - -I $(SRCTREE)/lib/libfdt \ - -I $(SRCTREE)/tools \ - -DUSE_HOSTCC -D__KERNEL_STRICT_NAMES - -ifeq ($(MTD_VERSION),old) -HOSTCPPFLAGS += -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) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^ - $(STRIP) $@ - -# Some files complain if compiled with -pedantic, use HOSTCFLAGS_NOPED -$(obj)image.o: $(SRCTREE)/common/image.c - $(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $< - -$(obj)imls.o: $(SRCTREE)/tools/imls/imls.c - $(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $< - -# Some of the tool objects need to be accessed from outside the tools/imls directory -$(obj)%.o: $(SRCTREE)/common/%.c - $(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $< - -$(obj)%.o: $(SRCTREE)/lib/%.c - $(CC) -g $(HOSTCFLAGS) -c -o $@ $< - -$(obj)%.o: $(SRCTREE)/lib/libfdt/%.c - $(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $< - -clean: - rm -rf *.o imls - -######################################################################### - -# defines $(obj).depend target -include $(SRCTREE)/rules.mk - -sinclude $(obj).depend - -######################################################################### diff --git a/tools/imls/README b/tools/imls/README deleted file mode 100644 index 9adf92305d..0000000000 --- a/tools/imls/README +++ /dev/null @@ -1,41 +0,0 @@ -# -# (C) Copyright 2009 Marco Stornelli -# -# SPDX-License-Identifier: GPL-2.0+ -# - -IMLS -------------- - -imls is an implementation of a Linux command line tool to access -to raw flash partitions and list images made with mkimage command. - -For building against older versions of the MTD headers (meaning before -v2.6.8-rc1) it is required to pass the argument "MTD_VERSION=old" to -make. - -Usage examples --------------- - -1) Flash with sectors of 128KiB and 32 sectors: - -> imls -c 32 -s 131072 /dev/mtd0 -Searching... -Image Name: foo -Created: Fri Apr 10 18:11:30 2009 -Image Type: Intel x86 Linux Standalone Program (uncompressed) -Data Size: 10716 Bytes = 10.46 kB = 0.01 MB -Load Address: 00000000 -Entry Point: 00000000 - -2) Flash with sectors of 64KiB and 128 sectors and with a search offset of one -sector: - -> imls -o 1 -c 128 -s 65536 /dev/mtd0 -Searching... -Image Name: foo -Created: Fri Apr 10 18:11:30 2009 -Image Type: Intel x86 Linux Standalone Program (uncompressed) -Data Size: 10716 Bytes = 10.46 kB = 0.01 MB -Load Address: 00000000 -Entry Point: 00000000 diff --git a/tools/imls/imls.c b/tools/imls/imls.c deleted file mode 100644 index 95043b450b..0000000000 --- a/tools/imls/imls.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * (C) Copyright 2009 Marco Stornelli - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef MTD_OLD -#include -#include -#else -#define __user /* nothing */ -#include -#endif - -#include -#include -#include -#include - -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - -extern unsigned long crc32(unsigned long crc, const char *buf, unsigned int len); -static void usage(void); -static int image_verify_header(char *ptr, int fd); -static int flash_bad_block(int fd, uint8_t mtd_type, loff_t start); - -char *cmdname; -char *devicefile; - -unsigned int sectorcount = 0; -int sflag = 0; -unsigned int sectoroffset = 0; -unsigned int sectorsize = 0; -int cflag = 0; - -int main (int argc, char **argv) -{ - int fd = -1, err = 0, readbyte = 0, j; - struct mtd_info_user mtdinfo; - char buf[sizeof(image_header_t)]; - int found = 0; - - cmdname = *argv; - - while (--argc > 0 && **++argv == '-') { - while (*++*argv) { - switch (**argv) { - case 'c': - if (--argc <= 0) - usage (); - sectorcount = (unsigned int)atoi(*++argv); - cflag = 1; - goto NXTARG; - case 'o': - if (--argc <= 0) - usage (); - sectoroffset = (unsigned int)atoi(*++argv); - goto NXTARG; - - case 's': - if (--argc <= 0) - usage (); - sectorsize = (unsigned int)atoi(*++argv); - sflag = 1; - goto NXTARG; - default: - usage (); - } - } -NXTARG: ; - } - - if (argc != 1 || cflag == 0 || sflag == 0) - usage(); - - devicefile = *argv; - - fd = open(devicefile, O_RDONLY); - if (fd < 0) { - fprintf (stderr, "%s: Can't open %s: %s\n", - cmdname, devicefile, strerror(errno)); - exit(EXIT_FAILURE); - } - - err = ioctl(fd, MEMGETINFO, &mtdinfo); - if (err < 0) { - fprintf(stderr, "%s: Cannot get MTD information: %s\n",cmdname, - strerror(errno)); - exit(EXIT_FAILURE); - } - - if (mtdinfo.type != MTD_NORFLASH && mtdinfo.type != MTD_NANDFLASH) { - fprintf(stderr, "%s: Unsupported flash type %u\n", - cmdname, mtdinfo.type); - exit(EXIT_FAILURE); - } - - if (sectorsize * sectorcount != mtdinfo.size) { - fprintf(stderr, "%s: Partition size (%d) incompatible with " - "sector size and count\n", cmdname, mtdinfo.size); - exit(EXIT_FAILURE); - } - - if (sectorsize * sectoroffset >= mtdinfo.size) { - fprintf(stderr, "%s: Partition size (%d) incompatible with " - "sector offset given\n", cmdname, mtdinfo.size); - exit(EXIT_FAILURE); - } - - if (sectoroffset > sectorcount - 1) { - fprintf(stderr, "%s: Sector offset cannot be grater than " - "sector count minus one\n", cmdname); - exit(EXIT_FAILURE); - } - - printf("Searching....\n"); - - for (j = sectoroffset; j < sectorcount; ++j) { - - if (lseek(fd, j*sectorsize, SEEK_SET) != j*sectorsize) { - fprintf(stderr, "%s: lseek failure: %s\n", - cmdname, strerror(errno)); - exit(EXIT_FAILURE); - } - - err = flash_bad_block(fd, mtdinfo.type, j*sectorsize); - if (err < 0) - exit(EXIT_FAILURE); - if (err) - continue; /* Skip and jump to next */ - - readbyte = read(fd, buf, sizeof(image_header_t)); - if (readbyte != sizeof(image_header_t)) { - fprintf(stderr, "%s: Can't read from device: %s\n", - cmdname, strerror(errno)); - exit(EXIT_FAILURE); - } - - if (fdt_check_header(buf)) { - /* old-style image */ - if (image_verify_header(buf, fd)) { - found = 1; - image_print_contents((image_header_t *)buf); - } - } else { - /* FIT image */ - fit_print_contents(buf); - } - - } - - close(fd); - - if(!found) - printf("No images found\n"); - - exit(EXIT_SUCCESS); -} - -void usage() -{ - fprintf (stderr, "Usage:\n" - " %s [-o offset] -s size -c count device\n" - " -o ==> number of sectors to use as offset\n" - " -c ==> number of sectors\n" - " -s ==> size of sectors (byte)\n", - cmdname); - - exit(EXIT_FAILURE); -} - -static int image_verify_header(char *ptr, int fd) -{ - int len, nread; - char *data; - uint32_t checksum; - image_header_t *hdr = (image_header_t *)ptr; - char buf[PAGE_SIZE]; - - if (image_get_magic(hdr) != IH_MAGIC) - return 0; - - data = (char *)hdr; - len = image_get_header_size(); - - checksum = image_get_hcrc(hdr); - hdr->ih_hcrc = htonl(0); /* clear for re-calculation */ - - if (crc32(0, data, len) != checksum) { - fprintf(stderr, - "%s: Maybe image found but it has bad header checksum!\n", - cmdname); - return 0; - } - - len = image_get_size(hdr); - checksum = 0; - - while (len > 0) { - nread = read(fd, buf, MIN(len,PAGE_SIZE)); - if (nread != MIN(len,PAGE_SIZE)) { - fprintf(stderr, - "%s: Error while reading: %s\n", - cmdname, strerror(errno)); - exit(EXIT_FAILURE); - } - checksum = crc32(checksum, buf, nread); - len -= nread; - } - - if (checksum != image_get_dcrc(hdr)) { - fprintf (stderr, - "%s: Maybe image found but it has corrupted data!\n", - cmdname); - return 0; - } - - return 1; -} - -/* - * Test for bad block on NAND, just returns 0 on NOR, on NAND: - * 0 - block is good - * > 0 - block is bad - * < 0 - failed to test - */ -static int flash_bad_block(int fd, uint8_t mtd_type, loff_t start) -{ - if (mtd_type == MTD_NANDFLASH) { - int badblock = ioctl(fd, MEMGETBADBLOCK, &start); - - if (badblock < 0) { - fprintf(stderr,"%s: Cannot read bad block mark: %s\n", - cmdname, strerror(errno)); - return badblock; - } - - if (badblock) { - return badblock; - } - } - - return 0; -} -- 2.25.1