]> www.infradead.org Git - mtd-utils.git/commitdiff
[MTD] UBI: Removed automake, autoconf, added ubi userspace headers.
authorFrank Haverkamp <haver@vnet.ibm.com>
Wed, 21 Jun 2006 12:26:02 +0000 (14:26 +0200)
committerFrank Haverkamp <haver@vnet.ibm.com>
Tue, 31 Oct 2006 14:06:06 +0000 (15:06 +0100)
Signed-off-by: Frank Haverkamp <haver@vnet.ibm.com>
62 files changed:
include/mtd/ubi-header.h [new file with mode: 0644]
include/mtd/ubi-user.h [new file with mode: 0644]
ubi-utils/Makefile
ubi-utils/Makefile.am [deleted file]
ubi-utils/bootstrap [deleted file]
ubi-utils/configure.ac [deleted file]
ubi-utils/inc/Makefile.am [deleted file]
ubi-utils/inc/config-h.in [deleted file]
ubi-utils/perl/f128_nand_sample.cfg [moved from ubi-utils/src/mkpfi/f128_nand_sample.cfg with 100% similarity]
ubi-utils/perl/f64_nor_sample.cfg [moved from ubi-utils/src/mkpfi/f64_nor_sample.cfg with 100% similarity]
ubi-utils/perl/mkpfi [moved from ubi-utils/src/mkpfi/mkpfi with 100% similarity]
ubi-utils/perl/ubicrc32.pl [moved from ubi-utils/src/ubicrc32/ubicrc32.pl with 100% similarity]
ubi-utils/scripts/ubi_test.sh
ubi-utils/scripts/ubi_tools_test.sh
ubi-utils/src/bin2nand.c [moved from ubi-utils/src/bin2nand/bin2nand.c with 88% similarity]
ubi-utils/src/bin2nand/nandecc.h [deleted file]
ubi-utils/src/bootenv.c [moved from ubi-utils/src/libbootenv/bootenv.c with 97% similarity]
ubi-utils/src/bootenv.h [moved from ubi-utils/inc/bootenv.h with 100% similarity]
ubi-utils/src/config.h [new file with mode: 0644]
ubi-utils/src/crc32.c [moved from ubi-utils/src/libcrc32/crc32.c with 100% similarity]
ubi-utils/src/crc32.h [moved from ubi-utils/inc/crc32.h with 100% similarity]
ubi-utils/src/error.c [moved from ubi-utils/src/liberror/error.c with 100% similarity]
ubi-utils/src/error.h [moved from ubi-utils/inc/error.h with 99% similarity]
ubi-utils/src/example_ubi.h [moved from ubi-utils/inc/example_ubi.h with 100% similarity]
ubi-utils/src/hashmap.c [moved from ubi-utils/src/libbootenv/hashmap.c with 100% similarity]
ubi-utils/src/hashmap.h [moved from ubi-utils/src/libbootenv/hashmap.h with 100% similarity]
ubi-utils/src/libpfiflash.c [moved from ubi-utils/src/libpfiflash/pfiflash.c with 97% similarity]
ubi-utils/src/libubi.c [moved from ubi-utils/src/libubi/libubi.c with 100% similarity]
ubi-utils/src/libubi_int.h [moved from ubi-utils/src/libubi/libubi_int.h with 97% similarity]
ubi-utils/src/libubi_sysfs.c [moved from ubi-utils/src/libubi/libubi_sysfs.c with 96% similarity]
ubi-utils/src/libubi_sysfs.h [moved from ubi-utils/src/libubi/libubi_sysfs.h with 100% similarity]
ubi-utils/src/libubigen.c [moved from ubi-utils/src/libubigen/ubigen.c with 99% similarity]
ubi-utils/src/libubimirror.c [moved from ubi-utils/src/libubimirror/ubimirror.c with 95% similarity]
ubi-utils/src/list.c [moved from ubi-utils/src/liblist/list.c with 100% similarity]
ubi-utils/src/list.h [moved from ubi-utils/inc/list.h with 100% similarity]
ubi-utils/src/mkbootenv.c [moved from ubi-utils/src/mkbootenv/mkbootenv.c with 100% similarity]
ubi-utils/src/nand2bin.c [moved from ubi-utils/src/nand2bin/nand2bin.c with 96% similarity]
ubi-utils/src/nandcorr.c [moved from ubi-utils/src/nand2bin/nandcorr.c with 100% similarity]
ubi-utils/src/nandecc.c [moved from ubi-utils/src/bin2nand/nandecc.c with 100% similarity]
ubi-utils/src/nandecc.h [moved from ubi-utils/inc/nandecc.h with 100% similarity]
ubi-utils/src/pddcustomize.c [moved from ubi-utils/src/pddcustomize/pddcustomize.c with 100% similarity]
ubi-utils/src/peb.c [moved from ubi-utils/src/libpeb/peb.c with 100% similarity]
ubi-utils/src/peb.h [moved from ubi-utils/inc/peb.h with 100% similarity]
ubi-utils/src/pfi.c [moved from ubi-utils/src/libpfi/pfi.c with 100% similarity]
ubi-utils/src/pfi.h [moved from ubi-utils/inc/pfi.h with 100% similarity]
ubi-utils/src/pfi2bin.c [moved from ubi-utils/src/pfi2bin/pfi2bin.c with 100% similarity]
ubi-utils/src/pfiflash.c [moved from ubi-utils/src/pfiflash/pfiflash.c with 99% similarity]
ubi-utils/src/pfiflash.h [moved from ubi-utils/inc/pfiflash.h with 100% similarity]
ubi-utils/src/reader.c [moved from ubi-utils/src/libreader/reader.c with 95% similarity]
ubi-utils/src/reader.h [moved from ubi-utils/inc/reader.h with 100% similarity]
ubi-utils/src/ubicrc32.c [moved from ubi-utils/src/ubicrc32/ubicrc32.c with 100% similarity]
ubi-utils/src/ubigen.c [moved from ubi-utils/src/ubigen/ubigen_main.c with 100% similarity]
ubi-utils/src/ubigen.h [moved from ubi-utils/inc/ubigen.h with 100% similarity]
ubi-utils/src/ubiinfo/ubiflash.h [deleted file]
ubi-utils/src/ubiinfo/ubiinfo.c [deleted file]
ubi-utils/src/ubiinfo/ubiipl.h [deleted file]
ubi-utils/src/ubimirror.c [moved from ubi-utils/src/ubimirror/ubimirror.c with 100% similarity]
ubi-utils/src/ubimirror.h [moved from ubi-utils/inc/ubimirror.h with 96% similarity]
ubi-utils/src/ubimkvol.c [moved from ubi-utils/src/ubimkvol/ubimkvol.c with 97% similarity]
ubi-utils/src/ubirmvol.c [moved from ubi-utils/src/ubirmvol/ubirmvol.c with 98% similarity]
ubi-utils/src/ubiupdatevol.c [moved from ubi-utils/src/ubiwritevol/ubiwritevol.c with 97% similarity]
ubi-utils/src/unubi.c [moved from ubi-utils/src/unubi/unubi.c with 96% similarity]

diff --git a/include/mtd/ubi-header.h b/include/mtd/ubi-header.h
new file mode 100644 (file)
index 0000000..1b325a1
--- /dev/null
@@ -0,0 +1,390 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2006
+ *
+ * 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
+ *
+ * Authors: Artem B. Bityutskiy
+ *          Thomas Gleixner
+ *          Frank Haverkamp
+ *          Oliver Lohmann
+ *          Andreas Arnez
+ */
+
+/*
+ * This file defines the layout of UBI headers and all the other UBI on-flash
+ * data structures.
+ */
+
+#ifndef __UBI_HEADER_H__
+#define __UBI_HEADER_H__
+
+#include <asm/byteorder.h>
+
+/* The version of this UBI implementation */
+#define UBI_VERSION 1
+
+/* The highest erase counter value supported by this implementation of UBI */
+#define UBI_MAX_ERASECOUNTER 0x7FFFFFFF
+
+/* The initial CRC32 value used when calculating CRC checksums */
+#define UBI_CRC32_INIT 0xFFFFFFFFU
+
+/**
+ * Magic numbers of the UBI headers.
+ *
+ * @UBI_EC_HDR_MAGIC: erase counter header magic number (ASCII "UBI#")
+ * @UBI_VID_HDR_MAGIC: volume identifier header magic number (ASCII "UBI!")
+ */
+enum {
+       UBI_EC_HDR_MAGIC  = 0x55424923,
+       UBI_VID_HDR_MAGIC = 0x55424921
+};
+
+/**
+ * Molume type constants used in volume identifier headers.
+ *
+ * @UBI_VID_DYNAMIC: dynamic volume
+ * @UBI_VID_STATIC: static volume
+ */
+enum {
+       UBI_VID_DYNAMIC = 1,
+       UBI_VID_STATIC  = 2
+};
+
+/**
+ * Compatibility constants used by internal volumes.
+ *
+ * @UBI_COMPAT_DELETE: delete this internal volume before anything is written
+ * to the flash
+ * @UBI_COMPAT_RO: attach this device in read-only mode
+ * @UBI_COMPAT_IGNORE: ignore this internal volume, but the UBI wear-leveling
+ * unit may still move these logical eraseblocks to ensure wear-leveling
+ * @UBI_COMPAT_PRESERVE: preserve this internal volume - do not touch its
+ * physical eraseblocks, don't even allow the wear-leveling unit to move
+ * them
+ * @UBI_COMPAT_REJECT: reject this UBI image
+ */
+enum {
+       UBI_COMPAT_DELETE   = 1,
+       UBI_COMPAT_RO       = 2,
+       UBI_COMPAT_IGNORE   = 3,
+       UBI_COMPAT_PRESERVE = 4,
+       UBI_COMPAT_REJECT   = 5
+};
+
+/*
+ * ubi16_t/ubi32_t/ubi64_t - 16, 32, and 64-bit integers used in UBI on-flash
+ * data structures.
+ */
+typedef struct {
+       uint16_t int16;
+} __attribute__ ((packed)) ubi16_t;
+
+typedef struct {
+       uint32_t int32;
+} __attribute__ ((packed)) ubi32_t;
+
+typedef struct {
+       uint64_t int64;
+} __attribute__ ((packed)) ubi64_t;
+
+/*
+ * In this implementation UBI uses the big-endian format for on-flash integers.
+ * The below are the corresponding endianess conversion macros.
+ */
+#define cpu_to_ubi16(x) ((ubi16_t){__cpu_to_be16(x)})
+#define ubi16_to_cpu(x) ((uint16_t)__be16_to_cpu((x).int16))
+
+#define cpu_to_ubi32(x) ((ubi32_t){__cpu_to_be32(x)})
+#define ubi32_to_cpu(x) ((uint32_t)__be32_to_cpu((x).int32))
+
+#define cpu_to_ubi64(x) ((ubi64_t){__cpu_to_be64(x)})
+#define ubi64_to_cpu(x) ((uint64_t)__be64_to_cpu((x).int64))
+
+/*
+ * Sizes of UBI headers.
+ */
+#define UBI_EC_HDR_SIZE  sizeof(struct ubi_ec_hdr)
+#define UBI_VID_HDR_SIZE sizeof(struct ubi_vid_hdr)
+
+/*
+ * Sizes of UBI headers without the ending CRC.
+ */
+#define UBI_EC_HDR_SIZE_CRC  (UBI_EC_HDR_SIZE  - sizeof(ubi32_t))
+#define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(ubi32_t))
+
+/*
+ * How much private data may internal volumes store in the VID header.
+ */
+#define UBI_VID_HDR_IVOL_DATA_SIZE 12
+
+/**
+ * struct ubi_ec_hdr - UBI erase counter header.
+ *
+ * @magic: the erase counter header magic number (%UBI_EC_HDR_MAGIC)
+ * @version: the version of UBI implementation which is supposed to accept this
+ * UBI image (%UBI_VERSION)
+ * @padding1: reserved for future, zeroes
+ * @ec: the erase counter
+ * @vid_hdr_offset: where the VID header begins
+ * @data_offset: where the user data begins
+ * @padding2: reserved for future, zeroes
+ * @hdr_crc: the erase counter header CRC checksum
+ *
+ * The erase counter header takes 64 bytes and has a plenty of unused space for
+ * future usage. The unused fields are zeroed. The @version field is used to
+ * indicate the version of UBI implementation which is supposed to be able to
+ * work with this UBI image. If @version is greater then the current UBI
+ * version, the image is rejecter. This may be useful in future if something
+ * is changed radically. This field is duplicated in the volume identifier
+ * header.
+ *
+ * The @vid_hdr_offset and @data_offset fields contain the offset of the the
+ * volume identifier header and user data, relative to the beginning of the
+ * eraseblock. These values have to be the same for all eraseblocks.
+ */
+struct ubi_ec_hdr {
+       ubi32_t magic;
+       uint8_t version;
+       uint8_t padding1[3];
+       ubi64_t ec; /* Warning: the current limit is 31-bit anyway! */
+       ubi32_t vid_hdr_offset;
+       ubi32_t data_offset;
+       uint8_t padding2[36];
+       ubi32_t hdr_crc;
+} __attribute__ ((packed));
+
+/**
+ * struct ubi_vid_hdr - on-flash UBI volume identifier header.
+ *
+ * @magic: volume identifier header magic number (%UBI_VID_HDR_MAGIC)
+ * @version: UBI implementation version which is supposed to accept this UBI
+ * image (%UBI_VERSION)
+ * @vol_type: volume type (%UBI_VID_DYNAMIC or %UBI_VID_STATIC)
+ * @copy_flag: a flag indicating if this physical eraseblock was created by
+ * means of copying an original physical eraseblock to ensure wear-leveling.
+ * @compat: compatibility of this volume (%UBI_COMPAT_DELETE,
+ * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT)
+ * @vol_id: volume ID
+ * @lnum: logical eraseblock number
+ * @leb_ver: eraseblock copy number
+ * @data_size: how many bytes of data this eraseblock contains.
+ * @used_ebs: total number of used logical eraseblocks in this volume
+ * @data_pad: how many bytes at the end of this eraseblock are not used
+ * @data_crc: CRC checksum of data containing in this eraseblock
+ * @padding1: reserved for future, zeroes
+ * @ivol_data: private data of internal volumes
+ * @hdr_crc: volume identifier header CRC checksum
+ *
+ * The @leb_ver and the @copy_flag fields are used to distinguish between older
+ * and newer copies of logical eraseblocks, as well as to guarantee robustness
+ * to unclean reboots. As UBI erases logical eraseblocks asynchronously, it has
+ * to distinguish between older and newer copies of eraseblocks. This is done
+ * using the @version field. On the other hand, when UBI moves an eraseblock,
+ * its version is also increased and the @copy_flag is set to 1. Additionally,
+ * when moving eraseblocks, UBI calculates data CRC and stores it in the
+ * @data_crc field, even for dynamic volumes.
+ *
+ * Thus, if there are 2 eraseblocks of the same volume and logical number, UBI
+ * uses the following algorithm to pick one of them. It first picks the one
+ * with larger version (say, A). If @copy_flag is not set, then A is picked. If
+ * @copy_flag is set, UBI checks the CRC of the eraseblock (@data_crc). This is
+ * needed to ensure that copying was finished. If the CRC is all right, A is
+ * picked. If not, the older eraseblock is picked.
+ *
+ * Note, the @leb_ver field may overflow. Thus, if you have 2 versions A and B,
+ * then A > B if abs(A-B) < 0x7FFFFFFF, and A < B otherwise.
+ *
+ * There are 2 sorts of volumes in UBI: user volumes and internal volumes.
+ * Internal volumes are not seen from outside and are used for different
+ * internal UBI purposes. In this implementation there are only two internal
+ * volumes: the layout volume and the update volume. Internal volumes are the
+ * main mechanism of UBI extensions. For example, in future one may introduce a
+ * journal internal volume.
+ *
+ * The @compat field is only used for internal volumes and contains the degree
+ * of their compatibility. This field is always zero for user volumes. This
+ * field provides a mechanism to introduce UBI extensions and to be still
+ * compatible with older UBI binaries. For example, if someone introduced an
+ * journal internal volume in future, he would probably use %UBI_COMPAT_DELETE
+ * compatibility.  And in this case, older UBI binaries, which know nothing
+ * about the journal volume, would just delete this and work perfectly fine.
+ * This is somewhat similar to what Ext2fs does when it is fed by an Ext3fs
+ * image - it just ignores the Ext3fs journal.
+ *
+ * The @data_crc field contains the CRC checksum of the contents of the logical
+ * eraseblock if this is a static volume.  In case of dynamic volumes, it does
+ * not contain the CRC checksum as a rule. The only exception is when the
+ * logical eraseblock was moved by the wear-leveling unit, then the
+ * wear-leveling unit calculates the eraseblocks' CRC and stores it at
+ * @data_crc.
+ *
+ * The @data_size field is always used for static volumes because we want to
+ * know about how many bytes of data are stored in this eraseblock.  For
+ * dynamic eraseblocks, this field usually contains zero. The only exception is
+ * when the logical eraseblock is moved to another physical eraseblock due to
+ * wear-leveling reasons. In this case, UBI calculates CRC checksum of the
+ * contents and uses both @data_crc and @data_size fields. In this case, the
+ * @data_size field contains the size of logical eraseblock of this volume
+ * (which may vary owing to @alignment).
+ *
+ * The @used_ebs field is used only for static volumes and indicates how many
+ * eraseblocks the data of the volume takes. For dynamic volumes this field is
+ * not used and always contains zero.
+ *
+ * The @data_pad is calculated when volumes are created using the alignment
+ * parameter. So, effectively, the @data_pad field reduces the size of logical
+ * eraseblocks of this volume. This is very handy when one uses block-oriented
+ * software (say, cramfs) on top of the UBI volume.
+ *
+ * The @ivol_data contains private data of internal volumes. This might be very
+ * handy to store data in the VID header, not in the eraseblock's contents. For
+ * example it may make life of simple boot-loaders easier. The @ivol_data field
+ * contains zeroes for user volumes.
+ */
+struct ubi_vid_hdr {
+       ubi32_t magic;
+       uint8_t version;
+       uint8_t vol_type;
+       uint8_t copy_flag;
+       uint8_t compat;
+       ubi32_t vol_id;
+       ubi32_t lnum;
+       ubi32_t leb_ver;
+       ubi32_t data_size;
+       ubi32_t used_ebs;
+       ubi32_t data_pad;
+       ubi32_t data_crc;
+       uint8_t padding1[12];
+       uint8_t ivol_data[UBI_VID_HDR_IVOL_DATA_SIZE];
+       ubi32_t hdr_crc;
+} __attribute__ ((packed));
+
+/**
+ * struct ubi_vid_hdr_upd_vol - private data of the update internal volume
+ * stored in volume identifier headers.
+ *
+ * @vol_id: volume ID of the volume under update
+ * @padding: zeroes
+ */
+struct ubi_vid_hdr_upd_vol {
+       ubi32_t vol_id;
+       uint8_t padding[UBI_VID_HDR_IVOL_DATA_SIZE - 4];
+} __attribute__ ((packed));
+
+/*
+ * Count of internal UBI volumes.
+ */
+#define UBI_INT_VOL_COUNT 2
+
+/*
+ * Internal volume IDs start from this digit. There is a reserved room for 4096
+ * internal volumes.
+ */
+#define UBI_INTERNAL_VOL_START (0x7FFFFFFF - 4096)
+
+/**
+ * enum ubi_internal_volume_numbers - volume IDs of internal UBI volumes.
+ *
+ * %UBI_LAYOUT_VOL_ID: volume ID of the layout volume
+ * %UBI_UPDATE_VOL_ID: volume ID of the update volume
+ */
+enum ubi_internal_volume_ids {
+       UBI_LAYOUT_VOL_ID = UBI_INTERNAL_VOL_START,
+       UBI_UPDATE_VOL_ID = UBI_INTERNAL_VOL_START + 1
+};
+
+/*
+ * Number of logical eraseblocks reserved for internal volumes.
+ */
+#define UBI_LAYOUT_VOLUME_EBS 2
+#define UBI_UPDATE_VOLUME_EBS 1
+
+/*
+ * Names of internal volumes
+ */
+#define UBI_LAYOUT_VOLUME_NAME "The layout volume"
+#define UBI_UPDATE_VOLUME_NAME "The update volume"
+
+/*
+ * Compatibility flags of internal volumes.
+ */
+#define UBI_LAYOUT_VOLUME_COMPAT UBI_COMPAT_REJECT
+#define UBI_UPDATE_VOLUME_COMPAT UBI_COMPAT_REJECT
+
+/*
+ * The maximum number of volumes per one UBI device.
+ */
+#define UBI_MAX_VOLUMES 128
+
+/*
+ * The maximum volume name length.
+ */
+#define UBI_VOL_NAME_MAX 127
+
+/*
+ * Size of volume table records.
+ */
+#define UBI_VTBL_RECORD_SIZE sizeof(struct ubi_vol_tbl_record)
+
+/*
+ * Size of volume table records without the ending CRC.
+ */
+#define UBI_VTBL_RECORD_SIZE_CRC (UBI_VTBL_RECORD_SIZE - sizeof(ubi32_t))
+
+/**
+ * struct ubi_vol_tbl_record - a record in the volume table.
+ *
+ * @reserved_pebs: how many physical eraseblocks are reserved for this volume
+ * @alignment: volume alignment
+ * @data_pad: how many bytes are not used at the end of the eraseblocks to
+ * satisfy the requested alignment
+ * @padding1: reserved, zeroes
+ * @name_len: the volume name length
+ * @name: the volume name
+ * @padding2: reserved, zeroes
+ * @crc: a CRC32 checksum of the record
+ *
+ * The layout volume consists of 2 logical eraseblock, each of which contains
+ * the volume table (i.e., the volume table is duplicated). The volume table is
+ * an array of &struct ubi_vol_tbl_record objects indexed by the volume ID.
+ *
+ * If the size of the logical eraseblock is large enough to fit
+ * %UBI_MAX_VOLUMES, the volume table contains %UBI_MAX_VOLUMES records.
+ * Otherwise, it contains as much records as can be fit (i.e., size of logical
+ * eraseblock divided by sizeof(struct ubi_vol_tbl_record)).
+ *
+ * The @alignment field is specified when the volume is created and cannot be
+ * later changed. It may be useful, for example, when a block-oriented file
+ * system works on top of UBI. The @data_pad field is calculated using the
+ * logical eraseblock size and @alignment. The alignment must be multiple to the
+ * minimal flash I/O unit. If @alignment is 1, all the available space of
+ * eraseblocks is used.
+ *
+ * Empty records contain all zeroes and the CRC checksum of those zeroes.
+ */
+struct ubi_vol_tbl_record {
+       ubi32_t reserved_pebs;
+       ubi32_t alignment;
+       ubi32_t data_pad;
+       uint8_t vol_type;
+       uint8_t padding1;
+       ubi16_t name_len;
+       uint8_t name[UBI_VOL_NAME_MAX + 1];
+       uint8_t padding2[24];
+       ubi32_t crc;
+} __attribute__ ((packed));
+
+#endif /* !__UBI_HEADER_H__ */
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h
new file mode 100644 (file)
index 0000000..161f674
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2006
+ *
+ * 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
+ *
+ * Author: Artem B. Bityutskiy
+ */
+
+#ifndef __UBI_USER_H__
+#define __UBI_USER_H__
+
+#ifndef __KERNEL__
+#define __user
+#endif
+
+/*
+ * When a new volume is created, users may either specify the volume number they
+ * want to create or to let UBI automatically assign a volume number using this
+ * constant.
+ */
+#define UBI_VOL_NUM_AUTO (-1)
+
+/*
+ * IOCTL commands of UBI character devices
+ */
+
+#define UBI_IOC_MAGIC 'o'
+
+/* Create an UBI volume */
+#define UBI_IOCMKVOL _IOW(UBI_IOC_MAGIC, 0, struct ubi_mkvol_req)
+/* Remove an UBI volume */
+#define UBI_IOCRMVOL _IOW(UBI_IOC_MAGIC, 1, int32_t)
+/* Re-size an UBI volume */
+#define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req)
+
+/*
+ * IOCTL commands of UBI volume character devices.
+ */
+
+#define UBI_VOL_IOC_MAGIC 'O'
+
+/* Start UBI volume update */
+#define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, int64_t)
+/* An eraseblock erasure command, used for debugging, disabled by dafault */
+#define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 0, int32_t)
+
+/**
+ * UBI volume type constants.
+ *
+ * @UBI_DYNAMIC_VOLUME: dynamic volume
+ * @UBI_STATIC_VOLUME:  static volume
+ */
+enum {
+       UBI_DYNAMIC_VOLUME = 3,
+       UBI_STATIC_VOLUME = 4
+};
+
+/**
+ * struct ubi_mkvol_req - volume description data structure used in
+ * volume creation requests.
+ *
+ * @vol_id: volume number
+ * @alignment: volume alignment
+ * @bytes: volume size in bytes
+ * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
+ * @padding: reserved for future, not used
+ * @name_len: volume name length
+ * @name: volume name
+ *
+ * This structure is used by userspace programs when creating new volumes. The
+ * @used_bytes field is only necessary when creating static volumes.
+ *
+ * The @alignment field specifies the required alignment of the volume logical
+ * eraseblock. This means, that the size of logical eraseblocks will be aligned
+ * to this number, i.e.,
+ *     (UBI device logical eraseblock size) mod (@alignment) = 0.
+ *
+ * To put it differently, the logical eraseblock of this volume may be slightly
+ * shortened in order to make it properly aligned. The alignment has to be
+ * multiple of the flash minimal input/output unit, or %1 to utilize the entire
+ * available space of logical eraseblocks.
+ *
+ * The @alignment field may be useful, for example, when one wants to maintain
+ * a block device on top of an UBI volume. In this case, it is desirable to fit
+ * an integer number of blocks in logical eraseblocks of this UBI volume. With
+ * alignment it is possible to update this volume using plane UBI volume image
+ * BLOBs, without caring about how to properly write them.
+ */
+struct ubi_mkvol_req {
+       int32_t vol_id;
+       int32_t alignment;
+       int64_t bytes;
+       int8_t vol_type;
+       int8_t padding[9];
+       int16_t name_len;
+       __user const char *name;
+} __attribute__ ((packed));
+
+/**
+ * struct ubi_rsvol_req - a data structure used in volume re-size requests.
+ *
+ * @vol_id: ID of the volume to re-size
+ * @bytes: new size of the volume in bytes
+ * 
+ * Re-sizing is possible for both dynamic and static volumes. But while dynamic
+ * volumes may be re-sized arbitrarily, static volumes cannot be made to be
+ * smaller then the number of bytes they bear. To arbitrarily shrink a static
+ * volume, it must be wiped out first (by means of volume update operation with
+ * zero number of bytes).
+ */
+struct ubi_rsvol_req {
+       int64_t bytes;
+       int32_t vol_id;
+} __attribute__ ((packed));
+
+#endif /* __UBI_USER_H__ */
index 686aa60ec5ce760f28d8556cc59b4d47c33b5f94..307da31245adaa2c407b727b09b26d885d8d299a 100644 (file)
@@ -1,79 +1,89 @@
 #
-# This makefile simplifies the build process for a toolchain user.
-# A toolchain developer should prefer a manual build process which
-# fits to his original needs.
+# Makefile for ubi-utils
 #
 
-X86_PREFIX?=/usr/local
-x86_path=./build_x86
-x86_status=$(x86_path)/config.status
+HOST_OS_NAME := $(shell uname -s)
+HOST_VERSION_NAME := $(shell uname -r)
+BUILD_CPU := $(shell uname -m)
+BUILD_OS := $(shell uname -o)
 
-PPC_PREFIX?=/opt/ppcnf/crossroot
-ppc_path=./build_ppc
-ppc_status=$(ppc_path)/config.status
+KERNELHDR := ../include                # mtd-utils private headers
+DESTDIR := /usr/local          # default installation
+SBINDIR := bin                 # default directory for binaries
 
-all: x86 ppc
+CC := $(CROSS)gcc
+CFLAGS := -I./inc -I./src -I$(KERNELHDR) -O2 -g -Wall -Werror \
+       -Wwrite-strings -W -std=gnu99 \
+        -DHOST_OS_NAME=\"$(HOST_OS_NAME)\" \
+        -DHOST_VERSION_NAME=\"$(HOST_VERSION_NAME)\" \
+       -DBUILD_CPU=\"$(BUILD_CPU)\" -DBUILD_OS=\"$(BUILD_OS)\"
 
-install: install_x86 install_ppc
-uninstall: uninstall_x86 uninstall_ppc
+PERLPROGS = mkpfi ubicrc32.pl
+TARGETS = ubiupdatevol ubimkvol ubirmvol pfiflash pddcustomize ubimirror \
+       bin2nand nand2bin ubigen mkbootenv unubi pfi2bin
 
-install_x86: x86
-       make -C $(x86_path) install
+vpath   %.c ./src
 
-install_ppc: ppc 
-       make -C $(ppc_path) install
+%: %.o
+       $(CC) $(LDFLAGS) -g -o $@ $^
 
+%.o: %.c
+       $(CC) $(CFLAGS) -g -c -o $@ $< -g -Wp,-MD,.$(shell basename $<).dep
 
-uninstall_x86: x86
-       make -C $(x86_path) uninstall
+all: $(TARGETS)
 
-uninstall_ppc: ppc 
-       make -C $(ppc_path) uninstall
+IGNORE=${wildcard .*.c.dep}
+-include ${IGNORE}
 
+clean:
+       rm -rf *.o $(TARGETS) .*.c.dep
 
+ubiupdatevol: ubiupdatevol.o error.o libubi.o libubi_sysfs.o
+       $(CC) $(LDFLAGS) -o $@ $^
 
-x86: $(x86_status)
-       make -C $(x86_path)
+ubimkvol: ubimkvol.o error.o libubi.o libubi_sysfs.o
+       $(CC) $(LDFLAGS) -o $@ $^
 
-ppc:  $(ppc_status)
-       make -C $(ppc_path)
+ubirmvol: ubirmvol.o error.o libubi.o libubi_sysfs.o
+       $(CC) $(LDFLAGS) -o $@ $^
 
-$(x86_status): $(x86_path) Makefile.in
-       cd $(x86_path) && ./config.status || ../configure \
-                               --prefix=$(X86_PREFIX)
+pddcustomize: pddcustomize.o error.o libubimirror.o bootenv.o hashmap.o \
+               libubi.o libubi_sysfs.o
+       $(CC) $(LDFLAGS) -o $@ $^
 
-$(ppc_status): $(ppc_path) Makefile.in
-       cd $(ppc_path) && ./config.status || ../configure \
-                               --build=i686-pc-linux-gnu \
-                               --host=ppc-linux \
-                               --prefix=$(PPC_PREFIX) \
-                               --exec-prefix=$(PPC_PREFIX)
+pfiflash: pfiflash.o libpfiflash.o list.o reader.o error.o libubimirror.o \
+               bootenv.o hashmap.o pfi.o libubi.o libubi_sysfs.o
+       $(CC) $(LDFLAGS) -o $@ $^
 
-Makefile.in: Makefile.am
-       ./bootstrap
+ubimirror: ubimirror.o error.o libubimirror.o bootenv.o hashmap.o \
+               libubi.o libubi_sysfs.o
+       $(CC) $(LDFLAGS) -o $@ $^
 
-$(x86_path):
-       mkdir -p $(x86_path)
+nand2bin: nand2bin.o nandecc.o nandcorr.o
+       $(CC) $(LDFLAGS) -o $@ $^
 
-$(ppc_path):
-       mkdir -p $(ppc_path)
+bin2nand: bin2nand.o error.o nandecc.o
+       $(CC) $(LDFLAGS) -o $@ $^
 
-clean:
-       rm -rf depcomp install-sh missing .deps \
-               config.log config.status \
-               inc/Makefile.in lib/Makefile.in
-       find . -type f -name "*~" -print | xargs $(RM)
-       rm -f Makefile.in
-       rm -f aclocal.m4
-       rm -rf autom4te.cache
-       rm -f config.guess
-       rm -f config.sub
-       rm -f configure
-       rm -f depcomp
-       rm -f install-sh
-       rm -f ltmain.sh
-       rm -f missing
-       rm -f lib/Makefile.in
-       rm -f inc/Makefile.in
-       rm -rf $(x86_path)
-       rm -rf $(ppc_path)
+ubigen: ubigen.o libubigen.o crc32.o
+       $(CC) $(LDFLAGS) -o $@ $^
+
+mkbootenv: mkbootenv.o bootenv.o hashmap.o error.o
+       $(CC) $(LDFLAGS) -o $@ $^
+
+unubi: unubi.o crc32.o
+       $(CC) $(LDFLAGS) -o $@ $^
+
+pfi2bin: pfi2bin.o peb.o error.o list.o crc32.o libubigen.o bootenv.o \
+               hashmap.o reader.o pfi.o
+       $(CC) $(LDFLAGS) -o $@ $^
+
+install: ${TARGETS}
+       mkdir -p ${DESTDIR}/${SBINDIR}
+       install -m0755 ${TARGETS} ${DESTDIR}/${SBINDIR}/
+       (cd perl && install ${PERLPROGS} ${DESTDIR}/${SBINDIR}/)
+
+uninstall:
+       for file in ${TARGETS} ${PERLPROGS}; do \
+               $(RM) ${DESTDIR}/${SBINDIR}/$$file; \
+       done
diff --git a/ubi-utils/Makefile.am b/ubi-utils/Makefile.am
deleted file mode 100644 (file)
index a5c9252..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-AUTOMAKE_OPTIONS = foreign
-SUBDIRS=lib inc  
-
-
-# -----------------------------------------------------------------------------
-#  Scripts (Perl/Bash) which shall be installed.
-#
-bin_SCRIPTS            = $(top_srcdir)/src/mkpfi/mkpfi
-
-# -----------------------------------------------------------------------------
-#  C programs which shall be build and installed.
-#  
-INCLUDES=-I$(top_srcdir)/inc -I$(top_srcdir)/../../kernel/include
-
-bin_PROGRAMS           = bin/pfi2bin \
-                         bin/bin2nand \
-                         bin/ubicrc32 \
-                         bin/mkbootenv \
-                         bin/ubimirror \
-                         bin/ubimkvol \
-                         bin/ubirmvol \
-                         bin/ubiwritevol \
-                         bin/pfiflash \
-                         bin/pddcustomize \
-                         bin/ubiinfo \
-                         bin/nand2bin \
-                         bin/unubi
-
-# -----------------------------------------------------------------------------
-#  C programs which shall be build and NOT installed. (FLD dependency...)
-#  
-noinst_PROGRAMS        =         bin/ubigen
-
-bin_ubigen_SOURCES     = $(top_srcdir)/src/ubigen/ubigen_main.c
-bin_ubigen_LDADD       = $(top_builddir)/lib/libubigen.la \
-                         $(top_builddir)/lib/libcrc32.la 
-
-bin_pfiflash_SOURCES   = $(top_srcdir)/src/pfiflash/pfiflash.c 
-bin_pfiflash_LDADD     = $(top_builddir)/lib/libpfiflash.la \
-                         $(top_builddir)/lib/liberror.la 
-bin_pfiflash_LDFLAGS   = -static
-
-bin_pddcustomize_SOURCES= $(top_srcdir)/src/pddcustomize/pddcustomize.c 
-bin_pddcustomize_LDADD = $(top_builddir)/lib/libbootenv.la \
-                         $(top_builddir)/lib/liberror.la \
-                         $(top_builddir)/lib/libubi.la \
-                         $(top_builddir)/lib/libubimirror.la
-bin_pddcustomize_LDFLAGS= -static
-
-bin_pfi2bin_SOURCES    = $(top_srcdir)/src/pfi2bin/pfi2bin.c
-bin_pfi2bin_LDADD      = $(top_builddir)/lib/libubigen.la \
-                         $(top_builddir)/lib/liberror.la \
-                         $(top_builddir)/lib/liblist.la \
-                         $(top_builddir)/lib/libreader.la 
-
-bin_bin2nand_SOURCES   = $(top_srcdir)/src/bin2nand/bin2nand.c \
-                         $(top_srcdir)/src/bin2nand/nandecc.c 
-bin_bin2nand_LDADD     = $(top_builddir)/lib/liberror.la 
-
-
-bin_ubicrc32_SOURCES   = $(top_srcdir)/src/ubicrc32/ubicrc32.c 
-bin_ubicrc32_LDADD     = $(top_builddir)/lib/libcrc32.la 
-
-bin_mkbootenv_SOURCES  = $(top_srcdir)/src/mkbootenv/mkbootenv.c 
-bin_mkbootenv_LDADD    = $(top_builddir)/lib/libbootenv.la \
-                         $(top_builddir)/lib/liberror.la 
-
-
-bin_ubimirror_SOURCES  = $(top_srcdir)/src/ubimirror/ubimirror.c 
-bin_ubimirror_LDADD    = $(top_builddir)/lib/liberror.la \
-                         $(top_builddir)/lib/libubimirror.la 
-bin_ubimirror_LDFLAGS= -static
-
-bin_ubimkvol_SOURCES   = $(top_srcdir)/src/ubimkvol/ubimkvol.c 
-bin_ubimkvol_LDADD     = $(top_builddir)/lib/libubi.la 
-bin_ubimkvol_LDFLAGS   = -static
-
-bin_ubirmvol_SOURCES   = $(top_srcdir)/src/ubirmvol/ubirmvol.c 
-bin_ubirmvol_LDADD     = $(top_builddir)/lib/libubi.la
-bin_ubirmvol_LDFLAGS   = -static
-
-bin_ubiwritevol_SOURCES        = $(top_srcdir)/src/ubiwritevol/ubiwritevol.c 
-bin_ubiwritevol_LDADD   = $(top_builddir)/lib/libubi.la 
-bin_ubiwritevol_LDFLAGS        = -static
-
-bin_ubiinfo_SOURCES    = $(top_srcdir)/src/ubiinfo/ubiinfo.c
-
-bin_nand2bin_SOURCES   = $(top_srcdir)/src/nand2bin/nand2bin.c \
-                         $(top_srcdir)/src/bin2nand/nandecc.c \
-                         $(top_srcdir)/src/nand2bin/nandcorr.c
-
-bin_unubi_SOURCES      = $(top_srcdir)/src/unubi/unubi.c
-bin_unubi_LDADD        = $(top_builddir)/lib/libcrc32.la 
-
-clean-local:
-       rm -rf bin/ 
diff --git a/ubi-utils/bootstrap b/ubi-utils/bootstrap
deleted file mode 100755 (executable)
index f543912..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-LIBTOOLM4="/usr/local/share/libtool/libltdl"
-
-if test -d "$LIBTOOLM4"; then
-       echo "+ aclocal ${LIBTOOLM4}"
-       aclocal -I ${LIBTOOLM4}
-else
-       echo "+ aclocal"
-       aclocal
-fi
-set -x
-libtoolize --force
-autoheader
-automake --foreign --add-missing --copy
-autoconf
diff --git a/ubi-utils/configure.ac b/ubi-utils/configure.ac
deleted file mode 100644 (file)
index 9f45176..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-# Don't remove this check.
-AC_PREREQ(2.59)
-
-# AC_INIT: Package, Version, Bugs
-AC_INIT([flashutils],[0.1],[arnez@de.ibm.com])
-AC_CONFIG_HEADERS([inc/config.h:inc/config-h.in])
-AC_CANONICAL_SYSTEM
-AM_INIT_AUTOMAKE([1.8 foreign])
-AM_MAINTAINER_MODE
-
-# Check debug options
-AS_HELP_STRING
-AC_ARG_ENABLE([debug],
-             AS_HELP_STRING([--enable-debug],
-                            [build with debug information [default=yes]]),,enable_debug="yes")
-
-# Check for programs.
-AM_PROG_LIBTOOL
-AC_PROG_CC
-AC_PROG_INSTALL
-AC_PROG_MAKE_SET
-
-# Checks for header files.
-AC_HEADER_STDC
-# FIXME: Use AC_CHECK_HEADERS for UBI stuff.
-# AC_CHECK_HEADERS([errno.h mtd/ubi-user.h])
-AC_CHECK_HEADERS([errno.h])
-
-# Set build flags
-if test "x$enable_debug" = "xyes"; then
-       CFLAGS="$CFLAGS -g -DDEBUG "
-fi
-
-AC_DEFINE_UNQUOTED(HOST_OS, "${host}", [Host OS])
-AC_DEFINE_UNQUOTED(HOST_CPU, "${host_os}", [Host CPU])
-AC_DEFINE_UNQUOTED(BUILD_OS, "${build_os}", [Build OS])
-AC_DEFINE_UNQUOTED(BUILD_CPU, "${build_cpu}", [Build CPU])
-
-# Additional Config
-AC_C_BIGENDIAN
-
-# CFLAGS
-CFLAGS="-std=gnu99 -Wundef -Wall $CFLAGS"
-
-# Init output.
-AC_CONFIG_FILES([
-          Makefile
-          lib/Makefile
-          inc/Makefile
-])
-
-AC_OUTPUT
diff --git a/ubi-utils/inc/Makefile.am b/ubi-utils/inc/Makefile.am
deleted file mode 100644 (file)
index ca22c37..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-AUTOMAKE_OPTIONS = foreign
-
-# You can export headers if necessary:
-nobase_include_HEADERS = pfiflash.h \
-                        libubi.h
diff --git a/ubi-utils/inc/config-h.in b/ubi-utils/inc/config-h.in
deleted file mode 100644 (file)
index ce4998b..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/* inc/config-h.in.  Generated from configure.ac by autoheader.  */
-
-/* Build CPU */
-#undef BUILD_CPU
-
-/* Build OS */
-#undef BUILD_OS
-
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#undef HAVE_DLFCN_H
-
-/* Define to 1 if you have the <errno.h> header file. */
-#undef HAVE_ERRNO_H
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define to 1 if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define to 1 if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
-
-/* Host CPU */
-#undef HOST_CPU
-
-/* Host OS */
-#undef HOST_OS
-
-/* Name of package */
-#undef PACKAGE
-
-/* Define to the address where bug reports for this package should be sent. */
-#undef PACKAGE_BUGREPORT
-
-/* Define to the full name of this package. */
-#undef PACKAGE_NAME
-
-/* Define to the full name and version of this package. */
-#undef PACKAGE_STRING
-
-/* Define to the one symbol short name of this package. */
-#undef PACKAGE_TARNAME
-
-/* Define to the version of this package. */
-#undef PACKAGE_VERSION
-
-/* Define to 1 if you have the ANSI C header files. */
-#undef STDC_HEADERS
-
-/* Version number of package */
-#undef VERSION
-
-/* Define to 1 if your processor stores words with the most significant byte
-   first (like Motorola and SPARC, unlike Intel and VAX). */
-#undef WORDS_BIGENDIAN
index 901714888708183180e689b9a59746df3f487693..622ec7ef19223558ab88e02d769277263822d3b0 100755 (executable)
@@ -10,7 +10,7 @@ export PATH=$PATH:~/bin:/usr/local/bin:/home/dedekind/work/prj/ubi/tools/flashut
 
 UBIMKVOL=ubimkvol
 UBIRMVOL=ubirmvol
-UBIWRITEVOL=ubiwritevol
+UBIWRITEVOL=ubiupdateevol
 
 # 128 KiB 131072
 # 256 KiB 262144
index 43fc2bbd7dc6c64a214070f2f7c827632d3e21ac..9163e0caf535f6d5b3366fcf67668551f5bcfb89 100755 (executable)
@@ -12,7 +12,7 @@ export PATH=$PATH:~/bin:/usr/local/bin:/home/dedekind/work/prj/ubi/tools/flashut
 
 UBIMKVOL=ubimkvol
 UBIRMVOL=ubirmvol
-UBIWRITEVOL=ubiwritevol
+UBIWRITEVOL=ubiupdatevol
 PFIFLASH=pfiflash
 CMP=cmp
 
similarity index 88%
rename from ubi-utils/src/bin2nand/bin2nand.c
rename to ubi-utils/src/bin2nand.c
index 5224e3b7b0725af480216ec139f09d93717a8156..168f7dd803a70ebd7c2a776b1b4f3a684b95bb4a 100644 (file)
  *
  * History:
  *     1.0:    Initial release (tglx)
- *
  *     1.1:    Understands hex and dec input parameters (tglx)
  *     1.2:    Generates separated OOB data, if needed. (oloh)
  *     1.3:    Padds data/oob to a given size. (oloh)
- *
  */
 
 #include <unistd.h>
@@ -77,33 +75,48 @@ static const char copyright [] __attribute__((unused)) =
        "FIXME: insert license type."; /* FIXME */
 
 static struct argp_option options[] = {
-       { name: "copyright", key: 'c', arg: NULL, flags: 0,
-         doc: "Print copyright information.",
-         group: 1 },
-
-       { name: "pagesize", key: 'p', arg: "<num>", flags: 0,
-         doc: "Pagesize in Byte/Mi/ki. Default: 2048",
-         group: 1 },
-
-       { name: "padding", key: 'j', arg: "<num>", flags: 0,
-         doc: "Padding in Byte/Mi/ki. Default: no padding",
-         group: 1 },
-
-       /* Output options */
-       { name: NULL, key: 0, arg: NULL, flags: 0,
-         doc: "Output settings:",
-         group: 2 },
-
-       { name: "output", key: 'o', arg: "<fname>", flags: 0,
-         doc: "Output filename. Interleaved Data/OOB if output-oob not "
+       { .name = "copyright",
+         .key = 'c',
+         .arg = NULL,
+         .flags = 0,
+         .doc = "Print copyright information.",
+         .group = 1 },
+
+       { .name = "pagesize",
+         .key = 'p',
+         .arg = "<num>",
+         .flags = 0,
+         .doc = "Pagesize in Byte/Mi/ki. Default = 2048",
+         .group = 1 },
+
+       { .name = "padding",
+         .key = 'j',
+         .arg = "<num>",
+         .flags = 0,
+         .doc = "Padding in Byte/Mi/ki. Default = no padding",
+         .group = 1 },
+
+       { .name = "output",
+         .key = 'o',
+         .arg = "<fname>",
+         .flags = 0,
+         .doc = "Output filename. Interleaved Data/OOB if output-oob not "
               "specified.",
-         group: 2 },
-
-       { name: "output-oob", key: 'q', arg: "<fname>", flags: 0,
-         doc: "Write OOB data in separate file.",
-         group: 2 },
-
-       { name: NULL, key: 0, arg: NULL, flags: 0, doc: NULL, group: 0 },
+         .group = 2 },
+
+       { .name = "output-oob",
+         .key = 'q',
+         .arg = "<fname>",
+         .flags = 0,
+         .doc = "Write OOB data in separate file.",
+         .group = 2 },
+
+       { .name = NULL,
+         .key = 0,
+         .arg = NULL,
+         .flags = 0,
+         .doc = NULL,
+         .group = 0 },
 };
 
 typedef struct myargs {
@@ -254,8 +267,8 @@ int main (int argc, char** argv)
                .pagesize = PAGESIZE,
                .padding  = PADDING,
                .fp_in    = NULL,
-               .file_out_data = "",
-               .file_out_oob = "",
+               .file_out_data = NULL,
+               .file_out_oob = NULL,
        };
 
        FILE* fp_out_data = stdout;
diff --git a/ubi-utils/src/bin2nand/nandecc.h b/ubi-utils/src/bin2nand/nandecc.h
deleted file mode 100644 (file)
index 8ae8a66..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * NAND ecc functions
- */
-#ifndef _NAND_ECC_H
-#define _NAND_ECC_H
-
-#include <stdint.h>
-
-extern int nand_calculate_ecc(const uint8_t *dat, uint8_t *ecc_code);
-
-#endif
similarity index 97%
rename from ubi-utils/src/libbootenv/bootenv.c
rename to ubi-utils/src/bootenv.c
index b6a1191be01de4c8c47ab5f1ad9464af825d33f4..8871d90685c27e85b146ea6271b21f2a3ddc507a 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/stat.h>
 #include <bootenv.h>
 
+#include "config.h"
 #include "hashmap.h"
 #include "error.h"
 
@@ -390,7 +391,7 @@ err:
 
 static int
 fill_output_buffer(bootenv_t env, char *buf, size_t buf_size_max,
-               size_t *written)
+                  size_t *written)
 {
        int rc = 0;
        size_t keys_size, i;
@@ -403,7 +404,7 @@ fill_output_buffer(bootenv_t env, char *buf, size_t buf_size_max,
                goto err;
 
        for (i = 0; i < keys_size; i++) {
-               if (wr > BOOTENV_MAXSIZE) {
+               if (wr > buf_size_max) {
                        rc = -ENOSPC;
                        goto err;
                }
@@ -412,7 +413,7 @@ fill_output_buffer(bootenv_t env, char *buf, size_t buf_size_max,
                if (rc != 0)
                        goto err;
 
-               wr += snprintf(buf + wr, BOOTENV_MAXSIZE - wr,
+               wr += snprintf(buf + wr, buf_size_max - wr,
                                "%s=%s", keys[i], val);
                wr++; /* for \0 */
        }
@@ -514,7 +515,7 @@ err:
 }
 
 int
-bootenv_valid(bootenv_t env)
+bootenv_valid(bootenv_t env __unused)
 {
        /* @FIXME No sanity check implemented. */
        return 0;
@@ -574,7 +575,8 @@ err:
 
 int
 bootenv_pdd_keep(bootenv_t env_old, bootenv_t env_new, bootenv_t *env_res,
-               int *warnings, char *err_buf, size_t err_buf_size)
+                int *warnings, char *err_buf __unused,
+                size_t err_buf_size __unused)
 {
        bootenv_list_t l_old = NULL;
        bootenv_list_t l_new = NULL;
@@ -683,8 +685,8 @@ err:
 
 int
 bootenv_pdd_overwrite(bootenv_t env_old, bootenv_t env_new,
-                     bootenv_t *env_res, int *warnings,
-                     char *err_buf, size_t err_buf_size)
+                     bootenv_t *env_res, int *warnings __unused,
+                     char *err_buf __unused, size_t err_buf_size __unused)
 {
        if ((env_old == NULL) || (env_new == NULL) || (env_res == NULL))
                return -EINVAL;
@@ -694,7 +696,7 @@ bootenv_pdd_overwrite(bootenv_t env_old, bootenv_t env_new,
 
 int
 bootenv_pdd_merge(bootenv_t env_old, bootenv_t env_new, bootenv_t *env_res,
-               int *warnings, char *err_buf, size_t err_buf_size)
+                 int *warnings __unused, char *err_buf, size_t err_buf_size)
 {
        if ((env_old == NULL) || (env_new == NULL) || (env_res == NULL))
                return -EINVAL;
diff --git a/ubi-utils/src/config.h b/ubi-utils/src/config.h
new file mode 100644 (file)
index 0000000..746fa3c
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __CONFIG_H__
+#define __CONFIG_H__
+/*
+ * Copyright (c) International Business Machines Corp., 2006
+ *
+ * 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.
+ *
+ * Author: Frank Haverkamp
+ */
+
+#define PACKAGE_VERSION     "1.0"
+#define PACKAGE_BUGREPORT   "dedekind@oktetlabs.ru, haver@vnet.ibm.com, or tglx@linutronix.de"
+
+#define __unused __attribute__((unused))
+
+#endif
similarity index 100%
rename from ubi-utils/inc/crc32.h
rename to ubi-utils/src/crc32.h
similarity index 99%
rename from ubi-utils/inc/error.h
rename to ubi-utils/src/error.h
index 25a1cee1d256d6cdd5753568dfa397a7a78cd217..e8d7137e710c354ea973d9d3279a8ac4c885b818 100644 (file)
@@ -36,7 +36,7 @@ void info_msg(const char *fmt, ...);
        __err_msg("[%s. FILE: %s FUNC: %s LINE: %d]\n",         \
                str, __FILE__, __FUNCTION__, __LINE__);         \
 } while (0)
-#elif
+#else
 #define __loc_msg(str)
 #endif
 
@@ -77,7 +77,7 @@ void info_msg(const char *fmt, ...);
        __loc_msg("DbgMsg");                                    \
        __err_msg(fmt, ##__VA_ARGS__);                          \
 } while (0)
-#elif
+#else
 #define dbg_msg(fmt, ...)
 #endif
 
similarity index 97%
rename from ubi-utils/src/libpfiflash/pfiflash.c
rename to ubi-utils/src/libpfiflash.c
index 0859a22b7e11aa231ef3d8489c23ff08714d6093..ed2af3c885d5539b07a29b4958af24dbe3962cf4 100644 (file)
@@ -40,8 +40,9 @@
 #include <libubi.h>
 #include <pfiflash.h>
 
-#include <mtd/ubi-user.h>      /* FIXME Is this ok here!!?? */
+//#include <mtd/ubi-user.h>    /* FIXME Is this ok here!!?? */
 
+#include "config.h"
 #include "ubimirror.h"
 #include "error.h"
 #include "reader.h"
@@ -158,7 +159,8 @@ my_ubi_mkvol(int devno, int s, pfi_ubi_t u, char *err_buf, size_t err_buf_size)
  * If the volume does not exist, the function will return success.
  */
 static int
-my_ubi_rmvol(int devno, uint32_t id, char *err_buf, size_t err_buf_size)
+my_ubi_rmvol(int devno, uint32_t id,
+            char *err_buf __unused, size_t err_buf_size __unused)
 {
        int rc = 0;
        ubi_lib_t ulib = NULL;
@@ -321,7 +323,7 @@ write_bootenv_volume(int devno, uint32_t id, bootenv_t bootenv_old,
 
 static int
 write_normal_volume(int devno, uint32_t id, size_t update_size, FILE* fp_in,
-                   char *err_buf, size_t err_buf_size)
+                   char *err_buf __unused, size_t err_buf_size __unused)
 {
        int rc = 0;
        ubi_lib_t ulib = NULL;
@@ -386,7 +388,7 @@ process_ubi_volumes(FILE* pfi, int seqnum, list_t pfi_ubis,
 
        foreach(u, ptr, pfi_ubis) {
                int s = seqnum;
-               if (seqnum > (u->ids_size - 1)) {
+               if (seqnum > ((int)u->ids_size - 1)) {
                        s = 0; /* per default use the first */
                }
                u->curr_seqnum = s;
@@ -585,7 +587,7 @@ pfiflash(FILE* pfi, int complete, int seqnum, pdd_handling_t pdd_handling,
                }
        }
 
-       if ((pdd_handling >= 0) && (pdd_handling < PDD_HANDLING_NUM)) {
+       if (((int)pdd_handling >= 0) && (pdd_handling < PDD_HANDLING_NUM)) {
                pdd_f = pdd_funcs[pdd_handling];
        }
        else {
similarity index 97%
rename from ubi-utils/src/libubi/libubi_int.h
rename to ubi-utils/src/libubi_int.h
index 16400107745069ac9bfa8b875379501606ef5451..ab387f5f01153897e87edfbf178ea7d11a091d45 100644 (file)
                fprintf(stderr, "UBI Library Error at %s: ", __func__); \
                fprintf(stderr, fmt, ##__VA_ARGS__);                    \
                fprintf(stderr, "\n");                                  \
-       } while(0)
+       } while (0)
 
 #ifdef UBILIB_DEBUG
 #define ubi_dbg(fmt, ...) do {                                         \
                fprintf(stderr, "UBI Debug: %s: ", __func__);           \
                fprintf(stderr, fmt, ##__VA_ARGS__);                    \
                fprintf(stderr, "\n");                                  \
-       } while(0)
+       } while (0)
 
 #else
-#define ubi_dbg(fmt, ...)
+#define ubi_dbg(fmt, ...) do { } while (0)
 #endif
 
 /**
similarity index 96%
rename from ubi-utils/src/libubi/libubi_sysfs.c
rename to ubi-utils/src/libubi_sysfs.c
index f7ecebc27ec23ca21a2234730f249f4b9c332698..95fd3deca636b510aededa6b65c492ff98450c93 100644 (file)
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include <stdarg.h>
 
+#include "config.h"
 #include "libubi_int.h"
 
 int
@@ -128,7 +129,7 @@ sysfs_read_dev_subst(const char *patt, unsigned int *major,
 }
 
 static int
-sysfs_read_ull(const char *file, unsigned long long *num)
+sysfs_read_ull(const char *file __unused, unsigned long long *num __unused)
 {
        return 0;
 }
@@ -147,7 +148,7 @@ sysfs_read_ull_subst(const char *patt, unsigned long long *num, int n, ...)
 }
 
 static int
-sysfs_read_uint(const char *file, unsigned int *num)
+sysfs_read_uint(const char *file __unused, unsigned int *num __unused)
 {
        return 0;
 }
similarity index 99%
rename from ubi-utils/src/libubigen/ubigen.c
rename to ubi-utils/src/libubigen.c
index 0cfa687b2cf400ef335bff5a72affa301f053601..258e555f439b46a9598756a66d816fd94d2ad74a 100644 (file)
@@ -247,7 +247,7 @@ ubigen_write_broken_update(ubi_info_t u, uint32_t blk)
 }
 
 void
-dump_info(ubi_info_t u)
+dump_info(ubi_info_t u __unused)
 {
 #ifdef DEBUG
        int err = 0;
similarity index 95%
rename from ubi-utils/src/libubimirror/ubimirror.c
rename to ubi-utils/src/libubimirror.c
index bf6b37c61bb37c55272bf54816ca474006ae6cdf..e5715fcb0f4110c4fe393204c24e1032b3496b1f 100644 (file)
@@ -48,7 +48,7 @@ enum {
  * Read len number of bytes from fd.
  * Return 0 on EOF, -1 on error.
  */
-static ssize_t fill_buffer(int fd, unsigned char *buf, size_t len)
+static ssize_t fill_buffer(int fd, unsigned char *buf, ssize_t len)
 {
        ssize_t got, have = 0;
 
@@ -65,7 +65,7 @@ static ssize_t fill_buffer(int fd, unsigned char *buf, size_t len)
  * Write len number of bytes to fd.
  * Return bytes written (>= 0), -1 on error.
  */
-static ssize_t flush_buffer(int fd, unsigned char *buf, size_t len)
+static ssize_t flush_buffer(int fd, unsigned char *buf, ssize_t len)
 {
        ssize_t done, have = 0;
 
@@ -150,7 +150,7 @@ copy_files(int fd_in, int fd_out)
 }
 
 int
-ubimirror(uint32_t devno, int seqnum, uint32_t *ids, size_t ids_size,
+ubimirror(uint32_t devno, int seqnum, uint32_t *ids, ssize_t ids_size,
          char *err_buf, size_t err_buf_size)
 {
        int rc = 0;
similarity index 100%
rename from ubi-utils/inc/list.h
rename to ubi-utils/src/list.h
similarity index 96%
rename from ubi-utils/src/nand2bin/nand2bin.c
rename to ubi-utils/src/nand2bin.c
index a728fb552415545a534b5c7bad96029b05ec6181..a5e8bca84d9f4df949b7a41ec623a7822f7dd905 100644 (file)
@@ -34,6 +34,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include "config.h"
 #include "nandecc.h"
 
 #define MAXPATH                1024
@@ -59,10 +60,10 @@ static struct args myargs = {
 
 static error_t parse_opt (int key, char *arg, struct argp_state *state);
 
-const char *argp_program_bug_address = "<haver@vnet.ibm.com>";
+const char *argp_program_bug_address = PACKAGE_BUGREPORT;
 
-static char doc[] = "\nVersion: " VERSION "\n\t"
-       HOST_OS" "HOST_CPU" at "__DATE__" "__TIME__"\n"
+static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\t"
+       BUILD_OS" "BUILD_CPU" at "__DATE__" "__TIME__"\n"
        "\nSplit data and OOB.\n";
 
 static struct argp_option options[] = {
@@ -197,7 +198,7 @@ static int calc_oobsize(size_t pagesize)
 }
 
 static inline void
-hexdump(FILE *fp, const uint8_t *buf, size_t size)
+hexdump(FILE *fp, const uint8_t *buf, ssize_t size)
 {
        int k;
 
similarity index 100%
rename from ubi-utils/inc/peb.h
rename to ubi-utils/src/peb.h
similarity index 100%
rename from ubi-utils/inc/pfi.h
rename to ubi-utils/src/pfi.h
similarity index 99%
rename from ubi-utils/src/pfiflash/pfiflash.c
rename to ubi-utils/src/pfiflash.c
index 18b3aa2696e6ee2a36c0a4280ae6209b2780a526..04f62dffefe367ff1f00b2123c00ae3a689cc830 100644 (file)
@@ -155,7 +155,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
                break;
        case 'p':
                args->pdd_handling = get_pdd_handling(arg);
-               if (args->pdd_handling < 0) {
+               if ((int)args->pdd_handling < 0) {
                        err_quit("Unknown PDD handling: %s.\n"
                                 "Please use either 'keep', 'merge' or"
                                 "'overwrite'.\n'");
similarity index 95%
rename from ubi-utils/src/libreader/reader.c
rename to ubi-utils/src/reader.c
index c8242df116b3a76dacca1e44711cc98c1a7437ba..e4a8cebf4f9418856e484a01a7030a94df30749a 100644 (file)
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <errno.h>
 
+#include "config.h"
 #include "bootenv.h"
 #include "reader.h"
 
@@ -112,8 +113,13 @@ read_pdd_data(FILE* fp_pdd, pdd_data_t* pdd_data,
        return rc;
 }
 
+/**
+ * FIXME enhance flasing raw PFI content e.g. IPLs for NAND and NOR.
+ * Here is one of the only places where the flash type and its special
+ * handling is exposed to the users.
+ */
 int
-read_pfi_raw(pfi_header pfi_hd, FILE* fp_pfi, pfi_raw_t* pfi_raw,
+read_pfi_raw(pfi_header pfi_hd, FILE* fp_pfi __unused, pfi_raw_t* pfi_raw,
             const char* label, char* err_buf, size_t err_buf_size)
 {
        int rc = 0;
@@ -169,8 +175,12 @@ read_pfi_raw(pfi_header pfi_hd, FILE* fp_pfi, pfi_raw_t* pfi_raw,
        return rc;
 }
 
+/**
+ * FIXME Enhance reading raw PFI sections, e.g. IPL. See comment at
+ * write_pfi_ubi.
+ */
 int
-read_pfi_ubi(pfi_header pfi_hd, FILE* fp_pfi, pfi_ubi_t* pfi_ubi,
+read_pfi_ubi(pfi_header pfi_hd, FILE* fp_pfi __unused, pfi_ubi_t* pfi_ubi,
             const char *label, char* err_buf, size_t err_buf_size)
 {
        int rc = 0;
diff --git a/ubi-utils/src/ubiinfo/ubiflash.h b/ubi-utils/src/ubiinfo/ubiflash.h
deleted file mode 100644 (file)
index 6883879..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-#ifndef _UBI_FLASH_H
-#define _UBI_FLASH_H
-/*
- * Copyright (c) International Business Machines Corp., 2006
- *
- * 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.
- */
-
-/*
- * FLASH related data structures and constants for UBI.
- * UBI scan analysis.
- *
- * IPL Initial Program Loader
- * SPL Secondary Program Loader
- */
-
-#include <stdint.h>
-#include <asm/byteorder.h>
-#include <mtd/ubi-header.h>
-
-#define UBI_BLOCK_IDENT_MAX  16
-
-/* Block status information constants */
-enum blockstat {
-       /* IO Error */
-       STAT_IO_FAILED  = 1,    /* 0xffffffff */
-       /* Block is bad */
-       STAT_BLOCK_BAD  = 2,    /* 0xfffffffe */
-       /* ECC unrecoverable error */
-       STAT_ECC_ERROR  = 3,    /* 0xfffffffd */
-       /* CRC checksum failed */
-       STAT_CRC_ERROR  = 4,    /* 0xfffffffc */
-       /* Magic number not available */
-       STAT_NO_MAGIC   = 5,    /* 0xfffffffb */
-       /* No image available */
-       STAT_NO_IMAGE   = 6,
-       /* Image is invalid */
-       STAT_INVALID_IMAGE      = 7,
-       /* Image is defect */
-       STAT_DEFECT_IMAGE       = 8,
-};
-
-/*
- * Flash types
- */
-enum flashtypes {
-       FLASH_TYPE_NAND = 1,
-       FLASH_TYPE_NOR,
-};
-
-/* Nand read buffer size: 2KiB + 64byte spare */
-#define NAND_READ_BUF_SIZE     (2048 + 64)
-
-/* Size of the CRC table */
-#define CRC32_TABLE_SIZE       256
-
-/* Image is not available marker for image offs */
-#define UBI_IMAGE_NOT_AVAILABLE        0xFFFFFFFF
-
-/* Increment this number, whenever you change the structure */
-#define UBI_SCAN_INFO_VERSION  2
-
-/* Time measurement as far as the code size allows us to do this */
-#define UBI_TIMESTAMPS         16
-
-/**
- * struct ubi_scan_info - RAM table filled by IPL scan
- *
- * @version:           Version of the structure
- * @bootstatus:                Boot status of the current boot
- * @flashtype:         Flash type (NAND/NOR)
- * @flashid:           ID of the flash chip
- * @flashmfr:          Manufacturer ID of the flash chip
- * @flashsize:         Size of the FLASH
- * @blocksize:         Eraseblock size
- * @blockshift:                Shift count to calc block number from offset
- * @nrblocks:          Number of erase blocks on flash
- * @pagesize:          Pagesize (NAND)
- * @blockinfo:         Pointer to an array of block status information
- *                     filled by FLASH scan
- * @images:            Pointer to FLASH block translation table sorted
- *                     by image type and load order
- * @imageblocks:       Number of blocks found per image
- * @imageoffs:         Offset per imagetype to the first
- *                     block in the translation table
- * @imagedups          duplicate blocks (max. one per volume)
- * @imagelen:          Length of the loaded image
- * @crc32_table:       CRC32 table buffer
- * @page_buf:          Page buffer for NAND FLASH
- */
-struct ubi_scan_info {
-       int                     version;
-       unsigned int            bootstatus;
-       unsigned int            flashtype;
-       unsigned int            flashid;
-       unsigned int            flashmfr;
-       unsigned int            flashsize;
-       unsigned int            blocksize;
-       unsigned int            blockshift;
-       unsigned int            nrblocks;
-       unsigned int            pagesize;
-
-       struct ubi_vid_hdr      *blockinfo;
-       struct ubi_vid_hdr      **images;
-       unsigned int            imageblocks[UBI_BLOCK_IDENT_MAX];
-       unsigned int            imageoffs[UBI_BLOCK_IDENT_MAX];
-       struct ubi_vid_hdr      *imagedups[UBI_BLOCK_IDENT_MAX];
-       unsigned int            imagelen;
-       uint32_t                crc32_table[CRC32_TABLE_SIZE];
-       uint8_t                 page_buf[NAND_READ_BUF_SIZE];
-       unsigned int            times[UBI_TIMESTAMPS];
-};
-
-/* External function definition */
-extern int flash_read(void *buf, unsigned int offs, int len);
-extern int flash_read_slice(struct ubi_scan_info *fi, void *buf,
-                           unsigned int offs, int len);
-extern void ipl_main(struct ubi_scan_info *fi);
-
-#ifndef CFG_EXAMPLE_IPL
-extern int ipl_scan(struct ubi_scan_info *fi);
-extern int ipl_load(struct ubi_scan_info *fi, int nr, uint8_t *loadaddr);
-
-#define IPL_STATIC
-
-#else
-#define IPL_STATIC static
-#endif
-
-/**
- * get_boot_status - get the boot status register
- *
- * Shift the lower 16 bit into the upper 16 bit and return
- * the result.
- */
-uint32_t get_boot_status(void);
-
-/**
- * set_boot_status - Set the boot status register
- *
- * @status:    The status value to set
- *
- */
-void set_boot_status(uint32_t status);
-
-static inline unsigned int ubi_vid_offset(struct ubi_scan_info *fi)
-{
-       if (fi->flashtype == FLASH_TYPE_NOR)
-               return UBI_EC_HDR_SIZE;
-       else
-               return fi->pagesize - UBI_VID_HDR_SIZE;
-}
-
-static inline unsigned int ubi_data_offset(struct ubi_scan_info *fi)
-{
-       if (fi->flashtype == FLASH_TYPE_NOR)
-               return UBI_EC_HDR_SIZE + UBI_VID_HDR_SIZE;
-       else
-               return fi->pagesize;
-}
-
-/**
- * IPL checkpoints
- */
-#define CHKP_HWINIT            0x3030
-#define CHKP_IPLSCAN_FAILED    0x3034
-#define CHKP_SPL_START         0x3037
-#define CHKP_SPLLOAD_STATUS    0x3130
-
-extern void checkpoint(uint32_t cpoint);
-extern void switch_watchdog(void);
-
-#endif
diff --git a/ubi-utils/src/ubiinfo/ubiinfo.c b/ubi-utils/src/ubiinfo/ubiinfo.c
deleted file mode 100644 (file)
index 6f7443b..0000000
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- * Copyright (c) International Business Machines Corp., 2006
- *
- * 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.
- */
-
-/*
- * Print out information about the UBI table this IPL is using.  This
- * can be used afterwards to analyze misbehavior of the IPL code.  The
- * input this program requires is the last 1 MiB DDRAM of our system
- * where the scanning table is placed into.
- *
- * Author: Frank Haverkamp <haver@vnet.ibm.com>
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <time.h>
-#include <argp.h>
-#include <getopt.h>
-#include <stdint.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-
-#define __unused __attribute__((unused))
-
-/* This should hopefully be constant and the same in all
- * configurations.
- */
-#define CFG_IPLSIZE    512
-#define CFG_SPLCODE    512
-#define MEMTOP         0x06600000 /* Sunray 102 MiB */
-#define MEMSIZE                0x00100000 /* 1 MiB */
-#define CODE_SIZE      (64 * 1024)
-
-/* FIXME Except of the memory size this should be defined via
- * parameters
- *
- * CFG_MEMTOP_BAMBOO  0x02000000
- * CFG_MEMTOP_SUNRAY  0x06600000
- */
-
-#include "ubiipl.h"
-#include "ubiflash.h"
-
-#define MIN(x,y) ((x)<(y)?(x):(y))
-
-#define ERR_RET(rc) {                                             \
-               fprintf(stderr, "%s:%d failed rc=%d\n", __func__,       \
-                       __LINE__, (rc));                                \
-               return (rc);                                        \
-       }
-
-#define VERSION "1.3"
-
-static error_t parse_opt (int key, char *arg, struct argp_state *state);
-const char *argp_program_version = VERSION;
-const char *argp_program_bug_address = "<haver@vnet.ibm.com>";
-
-static char doc[] = "\nVersion: " VERSION "\n\t"
-       " at "__DATE__" "__TIME__"\n"
-       "\n"
-       "Test program\n";
-
-static struct argp_option options[] = {
-       /* common settings */
-       { .name = "verbose",
-         .key = 'v',
-         .arg = "<level>",
-         .flags = 0,
-         .doc = "Set verbosity level to <level>",
-         .group = OPTION_ARG_OPTIONAL },
-
-       { .name = "memtop",
-         .key = 'm',
-         .arg = "<memtop>",
-         .flags = 0,
-         .doc = "Set top of memory, 102 MiB for Sunray and 16 MiB for Bamboo",
-         .group = OPTION_ARG_OPTIONAL },
-
-       { .name = NULL,
-         .key = 0,
-         .arg = NULL,
-         .flags = 0,
-         .doc = NULL,
-         .group = 0 },
-};
-
-typedef struct test_args {
-       int verbose;
-       unsigned long memtop;
-       char *arg1;
-       char **options;
-} test_args;
-
-static struct test_args g_args = {
-       .memtop = MEMTOP,
-       .verbose = 0,
-       .arg1 = NULL,
-       .options = NULL,
-};
-
-static struct argp argp = {
-       options:     options,
-       parser:      parse_opt,
-       args_doc:    "[last_1MiB_memory.bin]",
-       doc:     doc,
-       children:    NULL,
-       help_filter: NULL,
-       argp_domain: NULL,
-};
-
-static int verbose = 0;
-
-/**
- * @brief Parse the arguments passed into the test case.
- *
- * @param key      The parameter.
- * @param arg      Argument passed to parameter.
- * @param state          Location to put information on parameters.
- *
- * @return error_t
- */
-static error_t
-parse_opt(int key, char *arg, struct argp_state *state)
-{
-       /* Get the `input' argument from `argp_parse', which we
-          know is a pointer to our arguments structure. */
-       test_args *args = state->input;
-
-       switch (key) {
-               /* common settings */
-       case 'v': /* --verbose=<level> */
-               verbose = args->verbose = strtoul(arg, (char **)NULL, 0);
-               break;
-
-       case 'm': /* --memtop */
-               args->memtop = strtoul(arg, (char **)NULL, 0);
-               break;
-
-       case ARGP_KEY_NO_ARGS:
-               /* argp_usage(state); */
-               break;
-
-       case ARGP_KEY_ARG:
-               args->arg1 = arg;
-               /* Now we consume all the rest of the arguments.
-                  `state->next' is the index in `state->argv' of the
-                  next argument to be parsed, which is the first STRING
-                  we're interested in, so we can just use
-                  `&state->argv[state->next]' as the value for
-                  arguments->strings.
-
-                  _In addition_, by setting `state->next' to the end
-                  of the arguments, we can force argp to stop parsing
-                  here and return. */
-
-               args->options = &state->argv[state->next];
-               state->next = state->argc;
-               break;
-
-       case ARGP_KEY_END:
-               /* print out message if no arguments are given but PFI
-                  write should be done */
-               break;
-
-       default:
-               return(ARGP_ERR_UNKNOWN);
-       }
-       return 0;
-}
-
-static void
-hexdump(const char *buf, int len)
-{
-       char line[16];
-       char str[256];
-       char dummy[256];
-       int j = 0;
-
-       while (len > 0) {
-               int i;
-
-               strcpy(str, " ");
-
-               for (j = 0; j < MIN(16, len); j++)
-                       line[j] = *buf++;
-
-               for (i = 0; i < j; i++) {
-                       if (!(i & 3)) {
-                               sprintf(dummy, " %.2x", line[i] & 0xff);
-                               strcat(str, dummy);
-                       } else {
-                               sprintf(dummy, "%.2x", line[i] & 0xff);
-                               strcat(str, dummy);
-                       }
-               }
-
-               /* Print empty space */
-               for (; i < 16; i++)
-                       if (!(i & 1))
-                               strcat(str, "   ");
-                       else
-                               strcat(str, "  ");
-
-               strcat(str, "  ");
-               for (i = 0; i < j; i++) {
-                       if (isprint(line[i])) {
-                               sprintf(dummy, "%c", line[i]);
-                               strcat(str, dummy);
-                       } else {
-                               strcat(str, ".");
-                       }
-               }
-               printf("%s\n", str);
-               len -= 16;
-       }
-}
-
-static void
-print_status_help(void)
-{
-       printf("Error Codes from IPL\n");
-       printf("   IO Error          %d\n", STAT_IO_FAILED);
-       printf("   Block is bad      %d\n", STAT_BLOCK_BAD);
-       printf("   ECC unrec error   %d\n", STAT_ECC_ERROR);
-       printf("   CRC csum failed   %d\n", STAT_CRC_ERROR);
-       printf("   Magic not avail   %d\n", STAT_NO_MAGIC);
-       printf("   No image avail    %d\n", STAT_NO_IMAGE);
-       printf("   Image is invalid  %d\n", STAT_INVALID_IMAGE);
-       printf("   Image is defect   %d\n\n", STAT_DEFECT_IMAGE);
-
-}
-
-static void
-print_ubi_scan_info(struct ubi_scan_info *fi)
-{
-       int i;
-
-       printf("ubi_scan_info\n");
-       printf("    version      %08x\n", ntohl(fi->version));
-       printf("    bootstatus   %08x\n", ntohl(fi->bootstatus));
-       printf("    flashtype    %08x\n", ntohl(fi->flashtype));
-       printf("    flashid      %08x\n", ntohl(fi->flashid));
-       printf("    flashmfgr    %08x\n", ntohl(fi->flashmfr));
-       printf("    flashsize    %d bytes (%dM)\n",
-              ntohl(fi->flashsize), ntohl(fi->flashsize) / (1024 * 1024));
-       printf("    blocksize    %d bytes\n", ntohl(fi->blocksize));
-       printf("    blockshift   %d\n", ntohl(fi->blockshift));
-       printf("    nrblocks     %d\n", ntohl(fi->nrblocks));
-       printf("    pagesize     %d\n", ntohl(fi->pagesize));
-       printf("    imagelen     %d\n", ntohl(fi->imagelen));
-       printf("    blockinfo    %08x\n", ntohl((int)fi->blockinfo));
-
-       printf("  nr    imageblocks  imageoffs\n");
-       for (i = 0; i < UBI_BLOCK_IDENT_MAX; i++)
-               printf("    [%2d]   %08x   %08x\n", i,
-                      ntohl(fi->imageblocks[i]),
-                      ntohl(fi->imageoffs[i]));
-
-       for (i = 0; i < UBI_TIMESTAMPS; i++) {
-               if (!ntohl(fi->times[i]))
-                       continue;
-               printf("time[%3d] = %08x %.3f sec\n", i, ntohl(fi->times[i]),
-                      (double)ntohl(fi->times[i]) / 500000000.0);
-       }
-
-       printf("crc32_table\n");
-       hexdump((char *)&fi->crc32_table, sizeof(fi->crc32_table));
-       printf("\npage_buf\n");
-       hexdump((char *)&fi->page_buf, sizeof(fi->page_buf));
-
-       printf("\n");
-
-}
-
-static void
-print_ubi_block_info(struct ubi_scan_info *fi,
-                    struct ubi_vid_hdr *bi, int nr)
-{
-       int i;
-       int unknown = 0;
-
-       printf("\nBINFO\n");
-
-       for (i = 0; i < nr; i++) {
-               if ((int)ubi32_to_cpu(bi[i].magic) != UBI_VID_HDR_MAGIC) {
-                       printf("block=%d %08x\n",
-                              i, i * ntohl(fi->blocksize));
-#if 0
-                       printf(".");
-                       if ((unknown & 0x3f) == 0x3f)
-                               printf("\n");
-                       unknown++;
-#else
-                       hexdump((char *)&bi[i],
-                               sizeof(struct ubi_vid_hdr));
-#endif
-               } else {
-                       if (unknown)
-                               printf("\n");
-                       printf("block=%d %08x\n"
-                              "    leb_ver=0x%x data_size=%d "
-                              "lnum=%d used_ebs=0x%x\n"
-                              "    data_crc=%08x hdr_crc=%08x\n",
-                              i, i * ntohl(fi->blocksize),
-                              ubi32_to_cpu(bi[i].leb_ver),
-                              ubi32_to_cpu(bi[i].data_size),
-                              ubi32_to_cpu(bi[i].lnum),
-                              ubi32_to_cpu(bi[i].used_ebs),
-                              ubi32_to_cpu(bi[i].data_crc),
-                              ubi32_to_cpu(bi[i].hdr_crc));
-                       hexdump((char *)&bi[i],
-                               sizeof(struct ubi_vid_hdr));
-                       unknown = 0;
-               }
-       }
-}
-
-static int do_read(unsigned int memtop, char *buf, int buf_len __unused)
-{
-       unsigned long finfo_addr;
-       unsigned long binfo_addr;
-       unsigned long images_addr;
-       unsigned long nrblocks;
-       unsigned long bi_size;
-       unsigned long images_size;
-       struct ubi_scan_info *fi;
-       struct ubi_vid_hdr *bi;
-       char *images;
-       unsigned long memaddr = memtop - MEMSIZE;
-
-       print_status_help();
-
-       /* Read and print FINFO */
-       finfo_addr = MEMSIZE - CFG_IPLSIZE * 1024;
-
-       printf("read info at addr %08lx\n", finfo_addr);
-       fi = (struct ubi_scan_info *)(buf + finfo_addr);
-
-       binfo_addr  = ntohl((unsigned long)fi->blockinfo) - memaddr;
-       images_addr = ntohl((unsigned long)fi->images) - memaddr;
-       nrblocks    = ntohl(fi->nrblocks);
-
-       printf("BINFO %08lx\n", binfo_addr);
-
-       bi_size = nrblocks * sizeof(struct ubi_vid_hdr);
-       images_size = nrblocks * sizeof(unsigned int);
-
-       printf("FINFO\n");
-       print_ubi_scan_info(fi);
-       /* hexdump((char *)fi, sizeof(*fi)); */
-
-       /* Read and print BINFO */
-       bi = (struct ubi_vid_hdr *)(buf + binfo_addr);
-       print_ubi_block_info(fi, bi, nrblocks);
-
-       /* Read and print IMAGES */
-       images = buf + images_addr;
-       printf("\nIMAGES\n");
-       hexdump(images, images_size);
-
-       return 0;
-}
-
-int main(int argc, char *argv[])
-{
-       char buf[MEMSIZE];
-       FILE *fp;
-       int rc;
-
-       argp_parse(&argp, argc, argv, ARGP_IN_ORDER, 0, &g_args);
-
-       if (!g_args.arg1) {
-               fprintf(stderr, "Please specify a file "
-                       "name for memory dump!\n");
-               exit(EXIT_FAILURE);
-       }
-
-       memset(buf, 0xAB, sizeof(buf));
-
-       fp = fopen(g_args.arg1, "r");
-       if (!fp)
-               exit(EXIT_FAILURE);
-       rc = fread(buf, 1, sizeof(buf), fp);
-       if (rc != sizeof(buf))
-               exit(EXIT_FAILURE);
-       fclose(fp);
-       do_read(g_args.memtop, buf, sizeof(buf));
-
-       exit(EXIT_SUCCESS);
-}
diff --git a/ubi-utils/src/ubiinfo/ubiipl.h b/ubi-utils/src/ubiinfo/ubiipl.h
deleted file mode 100644 (file)
index 3a8b900..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-#ifndef _UBI_IPL_H
-#define _UBI_IPL_H
-/*
- * Copyright (c) International Business Machines Corp., 2006
- *
- * 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.
- */
-
-/*
- * Constants calculated from the CFG_XXX defines
- *
- * Declaration of the loader function which is invoked by the
- * assembler part of the IPL
- */
-
-/* Size of IPL - is 4K for NAND and can also be 4K for NOR */
-#define IPL_SIZE          4096
-
-/* Needed in asm code to upload the data, needed in C-code for CRC32 */
-#define IPL_RAMADDR       (CFG_MEMTOP - IPL_SIZE)
-
-#if !defined(__ASSEMBLY__)
-
-#include <stdint.h>
-#include <mtd/ubi-header.h>
-
-/* Address of the flash info structure */
-#define FINFO_ADDR (struct ubi_scan_info *) (CFG_MEMTOP - CFG_IPLSIZE * 1024)
-
-/* Size of the flash info structure */
-#define FINFO_SIZE sizeof(struct ubi_scan_info)
-
-/* Blockinfo array address */
-#define BINFO_ADDR (struct ubi_vid_hdr *) ((void *)FINFO_ADDR + FINFO_SIZE)
-
-/* Number of erase blocks */
-#define NR_ERASE_BLOCKS        ((CFG_FLASHSIZE * 1024) / CFG_BLOCKSIZE)
-
-/* Blockinfo size */
-#define BINFO_SIZE (NR_ERASE_BLOCKS * sizeof(struct ubi_vid_hdr))
-
-/* Images array address */
-#define IMAGES_ADDR (struct ubi_vid_hdr **) ((void *)BINFO_ADDR + BINFO_SIZE)
-
-/* Images array size */
-#define IMAGES_SIZE (NR_ERASE_BLOCKS * sizeof(unsigned int))
-
-/* Total size of flash info + blockinfo + images */
-#define INFO_SIZE ((FINFO_SIZE + BINFO_SIZE + IMAGES_SIZE) / sizeof(uint32_t))
-
-/* Load address of the SPL */
-#define SPL_ADDR (void *) ((void *)FINFO_ADDR - CFG_SPLCODE * 1024)
-
-#define IPL_SIZE_CRC32    (IPL_SIZE - sizeof(uint32_t))
-#define IPL_RAMADDR_CRC32  ((void *)(IPL_RAMADDR + sizeof(uint32_t)))
-
-/*
- * Linker script magic to ensure that load_spl() is linked to the
- * right place
- */
-#define __crc32         __attribute__((__section__(".crc32")))
-#define __entry         __attribute__((__section__(".entry.text")))
-#define __unused __attribute__((unused))
-
-#define MIN(x,y) ((x)<(y)?(x):(y))
-
-#define stop_on_error(x) \
-       { while (1); }
-
-void __entry load_spl(void);
-void hardware_init(void);
-
-#endif /* __ASSEMBLY__ */
-
-#endif
similarity index 96%
rename from ubi-utils/inc/ubimirror.h
rename to ubi-utils/src/ubimirror.h
index 893f5ce9662399b28ddc1989059a7b473115dedc..d7ae2adf4db7776a99819222490cfff08ad0fa2a 100644 (file)
@@ -60,7 +60,7 @@
  * @post The content of the UBI volume which was defined as source volume
  *      equals the content of the volumes which were defined as destination.
  */
-int ubimirror(uint32_t devno, int seqnum, uint32_t* ids, size_t ids_size,
+int ubimirror(uint32_t devno, int seqnum, uint32_t* ids, ssize_t ids_size,
              char *err_buf, size_t err_buf_size);
 
 #endif /* __UBIMIRROR_H__ */
similarity index 97%
rename from ubi-utils/src/ubimkvol/ubimkvol.c
rename to ubi-utils/src/ubimkvol.c
index f929252dc2a0b32218e3201aca72d5b6dd4c9d3f..30c569c121328ca4be9820fefab0a7b30cf59c53 100644 (file)
 #include <string.h>
 #include <errno.h>
 
+#include "config.h"
 #include <libubi.h>
 
-#define VERSION "1.1"
-
 static void usage(void);
 static int param_sanity_check(ubi_lib_t lib);
 static int parse_options(int argc, char * const argv[]);
@@ -214,13 +213,13 @@ static int param_sanity_check(ubi_lib_t lib)
        if (err)
                return -1;
 
-       if (devn >= ubi.dev_count) {
+       if (devn >= (int)ubi.dev_count) {
                fprintf(stderr, "Device %d does not exist\n", devn);
                goto out;
        }
 
        len = strlen(name);
-       if (len > ubi.nlen_max) {
+       if (len > (int)ubi.nlen_max) {
                fprintf(stderr, "Too long name (%d symbols), max is %d\n",
                        len, ubi.nlen_max);
                goto out;
@@ -236,7 +235,7 @@ out:
 static void usage(void)
 {
        printf("Usage: ubi_mkvol OPTIONS\n"
-              "Version: " VERSION "\n"
+              "Version: " PACKAGE_VERSION "\n"
               "The command line options:\n"
               "\t-h - this help message\n"
               "\t-d - UBI device number\n"
similarity index 98%
rename from ubi-utils/src/ubirmvol/ubirmvol.c
rename to ubi-utils/src/ubirmvol.c
index fc5ada5523b876e07024a800cea611a244b65daa..cb47b6cb029427ab49546b4757dbaee70609fad8 100644 (file)
@@ -28,6 +28,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+
+#include "config.h"
 #include <libubi.h>
 
 static void usage(void);
@@ -150,7 +152,7 @@ static int param_sanity_check(ubi_lib_t lib)
        if (err)
                return -1;
 
-       if (devn >= ubi.dev_count) {
+       if (devn >= (int)ubi.dev_count) {
                fprintf(stderr, "Device %d does not exist\n", devn);
                goto out;
        }
similarity index 97%
rename from ubi-utils/src/ubiwritevol/ubiwritevol.c
rename to ubi-utils/src/ubiupdatevol.c
index 8fdbe3704cdc60730aec04b6de19bf13eec84023..28e1e8f0f61e4dca105b1cd76c0da96ab65b60ff 100644 (file)
@@ -68,10 +68,10 @@ static int verbose = 0;
 
 static error_t parse_opt (int key, char *arg, struct argp_state *state);
 
-const char *argp_program_bug_address = "<haver@vnet.ibm.com>";
+const char *argp_program_bug_address = PACKAGE_BUGREPORT;
 
-static char doc[] = "\nVersion: " VERSION "\n\t"
-       HOST_OS" "HOST_CPU" at "__DATE__" "__TIME__"\n"
+static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\t"
+       BUILD_OS" "BUILD_CPU" at "__DATE__" "__TIME__"\n"
        "\nWrite to UBI Volume.\n";
 
 static struct argp_option options[] = {
similarity index 96%
rename from ubi-utils/src/unubi/unubi.c
rename to ubi-utils/src/unubi.c
index 9cb1354e045dc77e6d250c8e25b68eb3cb825aa1..6d877e70f52d64748084fec40b4d09d6ea6ac534 100644 (file)
@@ -65,10 +65,11 @@ static struct args myargs = {
 
 static error_t parse_opt (int key, char *arg, struct argp_state *state);
 
-const char *argp_program_bug_address = "<haver@vnet.ibm.com>";
+const char *argp_program_bug_address =
+       "... uuuh, lets wait until it looks nicer";
 
-static char doc[] = "\nVersion: " VERSION "\n\t"
-       HOST_OS" "HOST_CPU" at "__DATE__" "__TIME__"\n"
+static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\t"
+       BUILD_OS" "BUILD_CPU" at "__DATE__" "__TIME__"\n"
        "\nWrite to UBI Volume.\n";
 
 static struct argp_option options[] = {
@@ -204,7 +205,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
 }
 
 static inline void
-hexdump(FILE *fp, const void *p, size_t size)
+hexdump(FILE *fp, const void *p, ssize_t size)
 {
        int k;
        const uint8_t *buf = p;
@@ -271,7 +272,7 @@ static int extract_volume(struct args *args, const uint8_t *buf,
                if (crc != ubi32_to_cpu(vid_hdr->hdr_crc))
                        continue;
 
-               if (volume == ubi32_to_cpu(vid_hdr->vol_id)) {
+               if (volume == (int)ubi32_to_cpu(vid_hdr->vol_id)) {
 
                        printf("****** block %4d volume %2d **********\n",
                               i, volume);