[PATCH 05/10] mtd: utils: apply macros for message printouts
mtd-utils have a few macros for printouts. Provide the wrappers to make it easier to import them. Signed-off-by: Wolfram Sang --- include/mtd/utils.h | 27 +++ 1 file changed, 27 insertions(+) diff --git a/include/mtd/utils.h b/include/mtd/utils.h index 229fb34..05a3405 100644 --- a/include/mtd/utils.h +++ b/include/mtd/utils.h @@ -17,6 +17,33 @@ #ifndef INCLUDE_MTD_UTILS_H # define INCLUDE_MTD_UTILS_H +/* Messages as used in mtd-utils */ + +#define bareverbose(verbose, fmt, ...) do {\ + if (verbose) \ + printf(fmt, ##__VA_ARGS__);\ +} while(0) +#define verbose(verbose, fmt, ...) \ + bareverbose(verbose, "%s: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__) + +#define normsg_cont(fmt, ...) do { \ + printf("%s: " fmt, PROGRAM_NAME, ##__VA_ARGS__); \ +} while(0) + +#define normsg(fmt, ...) do { \ + normsg_cont(fmt "\n", ##__VA_ARGS__); \ +} while(0) + +#define errmsg(fmt, ...) ({\ + printf("%s: error!: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__); \ + -1; \ +}) +#define sys_errmsg errmsg + +#define warnmsg(fmt, ...) do {\ + fprintf(stderr, "%s: warning!: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__); \ +} while(0) + static inline int is_power_of_2(unsigned long n) { return (n != 0 && ((n & (n - 1)) == 0)); -- 1.7.10.4 ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
[PATCH 00/10] add ubiformat command
Hi, here is the ubiformat series rebased against v2012.12.0. All comments I have received have been addressed. The command has been tested on a MX35 based board. Please help testing. Regards, Wolfram Sang Wolfram Sang (10): mtd: move is_power_of_2() to a public place ubi: consolidate ubi-media.h ubi: bump ubi-media.h to newest version devfs & mtd: add MEMERASE ioctl support mtd: utils: apply macros for message printouts lib: add ubiutils-common lib: add libscan lib: add libubigen lib: add barebox version of libmtd commands: add ubiformat commands/Kconfig |9 + commands/Makefile |1 + commands/ubi.c|2 +- commands/ubiformat.c | 794 + drivers/mtd/core.c| 68 ++-- drivers/mtd/ubi/ubi-barebox.h |5 +- drivers/mtd/ubi/ubi-media.h | 369 --- drivers/mtd/ubi/ubi.h |3 +- fs/devfs-core.c |3 +- include/mtd/libmtd.h | 154 include/mtd/libscan.h | 105 ++ include/mtd/libubigen.h | 186 ++ include/mtd/ubi-media.h | 378 include/mtd/ubiutils-common.h | 26 ++ include/mtd/utils.h | 52 +++ include/ubi-media.h | 370 --- lib/Kconfig | 12 + lib/Makefile |4 + lib/libmtd.c | 371 +++ lib/libscan.c | 223 lib/libubigen.c | 316 lib/ubiutils-common.c | 122 +++ 22 files changed, 2794 insertions(+), 779 deletions(-) create mode 100644 commands/ubiformat.c delete mode 100644 drivers/mtd/ubi/ubi-media.h create mode 100644 include/mtd/libmtd.h create mode 100644 include/mtd/libscan.h create mode 100644 include/mtd/libubigen.h create mode 100644 include/mtd/ubi-media.h create mode 100644 include/mtd/ubiutils-common.h create mode 100644 include/mtd/utils.h delete mode 100644 include/ubi-media.h create mode 100644 lib/libmtd.c create mode 100644 lib/libscan.c create mode 100644 lib/libubigen.c create mode 100644 lib/ubiutils-common.c -- 1.7.10.4 ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
[PATCH 03/10] ubi: bump ubi-media.h to newest version
Needed for ubiformat, we are interested in image_seq especially. Signed-off-by: Wolfram Sang --- include/mtd/ubi-media.h | 57 +++ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/include/mtd/ubi-media.h b/include/mtd/ubi-media.h index cd1bd8e..08bec3e 100644 --- a/include/mtd/ubi-media.h +++ b/include/mtd/ubi-media.h @@ -11,6 +11,9 @@ * 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 Bityutskiy (Битюцкий Артём) * Thomas Gleixner @@ -95,10 +98,11 @@ enum { * Compatibility constants used by internal volumes. * * @UBI_COMPAT_DELETE: delete this internal volume before anything is written - * to the flash + * to the flash * @UBI_COMPAT_RO: attach this device in read-only mode * @UBI_COMPAT_PRESERVE: preserve this internal volume - do not touch its - * physical eraseblocks, don't allow the wear-leveling unit to move them + * physical eraseblocks, don't allow the wear-leveling + * sub-system to move them * @UBI_COMPAT_REJECT: reject this UBI image */ enum { @@ -120,18 +124,19 @@ enum { * struct ubi_ec_hdr - UBI erase counter header. * @magic: erase counter header magic number (%UBI_EC_HDR_MAGIC) * @version: version of UBI implementation which is supposed to accept this - * UBI image + * UBI image * @padding1: reserved for future, zeroes * @ec: the erase counter * @vid_hdr_offset: where the VID header starts * @data_offset: where the user data start + * @image_seq: image sequence number * @padding2: reserved for future, zeroes * @hdr_crc: 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 + * work with this UBI image. If @version is greater than the current UBI * version, the image is rejected. This may be useful in future if something * is changed radically. This field is duplicated in the volume identifier * header. @@ -140,6 +145,14 @@ enum { * volume identifier header and user data, relative to the beginning of the * physical eraseblock. These values have to be the same for all physical * eraseblocks. + * + * The @image_seq field is used to validate a UBI image that has been prepared + * for a UBI device. The @image_seq value can be any value, but it must be the + * same on all eraseblocks. UBI will ensure that all new erase counter headers + * also contain this value, and will check the value when scanning at start-up. + * One way to make use of @image_seq is to increase its value by one every time + * an image is flashed over an existing image, then, if the flashing does not + * complete, UBI will detect the error when scanning. */ struct ubi_ec_hdr { __be32 magic; @@ -148,7 +161,8 @@ struct ubi_ec_hdr { __be64 ec; /* Warning: the current limit is 31-bit anyway! */ __be32 vid_hdr_offset; __be32 data_offset; - __u8padding2[36]; + __be32 image_seq; + __u8padding2[32]; __be32 hdr_crc; } __attribute__ ((packed)); @@ -156,24 +170,23 @@ struct ubi_ec_hdr { * 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) + * image (%UBI_VERSION) * @vol_type: volume type (%UBI_VID_DYNAMIC or %UBI_VID_STATIC) * @copy_flag: if this logical eraseblock was copied from another physical - * eraseblock (for wear-leveling reasons) + * eraseblock (for wear-leveling reasons) * @compat: compatibility of this volume (%0, %UBI_COMPAT_DELETE, - * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT) + * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT) * @vol_id: ID of this volume * @lnum: logical eraseblock number - * @leb_ver: version of this logical eraseblock (IMPORTANT: obsolete, to be - * removed, kept only for not breaking older UBI users) + * @padding1: reserved for future, zeroes * @data_size: how many bytes of data this logical eraseblock contains * @used_ebs: total number of used logical eraseblocks in this volume * @data_pad: how many bytes at the end of this physical eraseblock are not - * used + *used * @data_crc: CRC checksum of the data stored in this logical eraseblock - * @padding1: reserved for futur
[PATCH 01/10] mtd: move is_power_of_2() to a public place
Will need this later for ubiformat. Signed-off-by: Wolfram Sang --- drivers/mtd/ubi/ubi-barebox.h |5 + include/mtd/utils.h | 25 + 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 include/mtd/utils.h diff --git a/drivers/mtd/ubi/ubi-barebox.h b/drivers/mtd/ubi/ubi-barebox.h index 72f29a6..919dc50 100644 --- a/drivers/mtd/ubi/ubi-barebox.h +++ b/drivers/mtd/ubi/ubi-barebox.h @@ -25,6 +25,7 @@ #include #include #include +#include #define crc32(seed, data, length) crc32_no_comp(seed, (unsigned char const *)data, length) @@ -53,10 +54,6 @@ do { \ #define put_device(...) #define ubi_sysfs_init(...)0 #define ubi_sysfs_close(...) do { } while (0) -static inline int is_power_of_2(unsigned long n) -{ - return (n != 0 && ((n & (n - 1)) == 0)); -} /* FIXME */ #define MKDEV(...) 0 diff --git a/include/mtd/utils.h b/include/mtd/utils.h new file mode 100644 index 000..229fb34 --- /dev/null +++ b/include/mtd/utils.h @@ -0,0 +1,25 @@ +/* + * mtd/utils.h - helper functions for various MTD utilities + * + * Copyright (C) 2012 by Wolfram Sang + * + * 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. + */ + +#ifndef INCLUDE_MTD_UTILS_H +# define INCLUDE_MTD_UTILS_H + +static inline int is_power_of_2(unsigned long n) +{ + return (n != 0 && ((n & (n - 1)) == 0)); +} + +#endif /* INCLUDE_MTD_UTILS_H */ -- 1.7.10.4 ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
[PATCH 04/10] devfs & mtd: add MEMERASE ioctl support
To make that, we need to shift mtd_erase before mtd_ioctl. ubi-utils need that, especially ubiformat. Signed-off-by: Wolfram Sang --- drivers/mtd/core.c | 68 +++- fs/devfs-core.c|3 ++- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c index 8601787..83e1a39 100644 --- a/drivers/mtd/core.c +++ b/drivers/mtd/core.c @@ -123,7 +123,37 @@ static ssize_t mtd_write(struct cdev* cdev, const void *buf, size_t _count, out: return ret ? ret : _count; } -#endif + +static int mtd_erase(struct cdev *cdev, size_t count, loff_t offset) +{ + struct mtd_info *mtd = cdev->priv; + struct erase_info erase; + int ret; + + memset(&erase, 0, sizeof(erase)); + erase.mtd = mtd; + erase.addr = offset; + erase.len = mtd->erasesize; + + while (count > 0) { + dev_dbg(cdev->dev, "erase %d %d\n", erase.addr, erase.len); + + ret = mtd_block_isbad(mtd, erase.addr); + if (ret > 0) { + printf("Skipping bad block at 0x%08x\n", erase.addr); + } else { + ret = mtd->erase(mtd, &erase); + if (ret) + return ret; + } + + erase.addr += mtd->erasesize; + count -= count > mtd->erasesize ? mtd->erasesize : count; + } + + return 0; +} +#endif /* CONFIG_MTD_WRITE */ int mtd_ioctl(struct cdev *cdev, int request, void *buf) { @@ -134,6 +164,7 @@ int mtd_ioctl(struct cdev *cdev, int request, void *buf) struct mtd_ecc_stats *ecc = buf; #endif struct region_info_user *reg = buf; + struct erase_info_user *ei = buf; loff_t *offset = buf; switch (request) { @@ -146,6 +177,9 @@ int mtd_ioctl(struct cdev *cdev, int request, void *buf) dev_dbg(cdev->dev, "MEMSETBADBLOCK: 0x%08llx\n", *offset); ret = mtd->block_markbad(mtd, *offset); break; + case MEMERASE: + ret = mtd_erase(cdev, ei->length, ei->start + cdev->offset); + break; #endif case MEMGETINFO: user->type = mtd->type; @@ -183,38 +217,6 @@ int mtd_ioctl(struct cdev *cdev, int request, void *buf) return ret; } -#ifdef CONFIG_MTD_WRITE -static int mtd_erase(struct cdev *cdev, size_t count, loff_t offset) -{ - struct mtd_info *mtd = cdev->priv; - struct erase_info erase; - int ret; - - memset(&erase, 0, sizeof(erase)); - erase.mtd = mtd; - erase.addr = offset; - erase.len = mtd->erasesize; - - while (count > 0) { - dev_dbg(cdev->dev, "erase %d %d\n", erase.addr, erase.len); - - ret = mtd_block_isbad(mtd, erase.addr); - if (ret > 0) { - printf("Skipping bad block at 0x%08x\n", erase.addr); - } else { - ret = mtd->erase(mtd, &erase); - if (ret) - return ret; - } - - erase.addr += mtd->erasesize; - count -= count > mtd->erasesize ? mtd->erasesize : count; - } - - return 0; -} -#endif - static struct file_operations mtd_ops = { .read = mtd_read, #ifdef CONFIG_MTD_WRITE diff --git a/fs/devfs-core.c b/fs/devfs-core.c index 0d2f75a..262e0a2 100644 --- a/fs/devfs-core.c +++ b/fs/devfs-core.c @@ -152,13 +152,14 @@ static int partition_ioctl(struct cdev *cdev, int request, void *buf) break; #if (defined(CONFIG_NAND_ECC_HW) || defined(CONFIG_NAND_ECC_SOFT)) case ECCGETSTATS: +#endif + case MEMERASE: if (!cdev->ops->ioctl) { ret = -EINVAL; break; } ret = cdev->ops->ioctl(cdev, request, buf); break; -#endif #ifdef CONFIG_PARTITION case MEMGETREGIONINFO: if (cdev->mtd) { -- 1.7.10.4 ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
[PATCH 08/10] lib: add libubigen
Imported from mtd-utils and stripped down to needed functionality. Signed-off-by: Wolfram Sang --- include/mtd/libubigen.h | 186 lib/Kconfig |3 + lib/Makefile|1 + lib/libubigen.c | 316 +++ 4 files changed, 506 insertions(+) create mode 100644 include/mtd/libubigen.h create mode 100644 lib/libubigen.c diff --git a/include/mtd/libubigen.h b/include/mtd/libubigen.h new file mode 100644 index 000..5ebdb78 --- /dev/null +++ b/include/mtd/libubigen.h @@ -0,0 +1,186 @@ +/* + * Copyright (c) International Business Machines Corp., 2006 + * Copyright (C) 2008 Nokia Corporation + * + * 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. + */ + +/* + * Authors: Frank Haverkamp + * Artem Bityutskiy + */ + +#ifndef __LIBUBIGEN_H__ +#define __LIBUBIGEN_H__ + +#include + +/** + * struct ubigen_info - libubigen information. + * @leb_size: logical eraseblock size + * @peb_size: size of the physical eraseblock + * @min_io_size: minimum input/output unit size + * @vid_hdr_offs: offset of the VID header + * @data_offs: data offset + * @ubi_ver: UBI version + * @vtbl_size: volume table size + * @max_volumes: maximum amount of volumes + * @image_seq: UBI image sequence number + */ +struct ubigen_info +{ + int leb_size; + int peb_size; + int min_io_size; + int vid_hdr_offs; + int data_offs; + int ubi_ver; + int vtbl_size; + int max_volumes; + uint32_t image_seq; +}; + +/** + * struct ubigen_vol_info - information about a volume. + * @id: volume id + * @type: volume type (%UBI_VID_DYNAMIC or %UBI_VID_STATIC) + * @alignment: volume alignment + * @data_pad: how many bytes are unused at the end of the each physical + *eraseblock to satisfy the requested alignment + * @usable_leb_size: LEB size accessible for volume users + * @name: volume name + * @name_len: volume name length + * @compat: compatibility of this volume (%0, %UBI_COMPAT_DELETE, + * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT) + * @used_ebs: total number of used logical eraseblocks in this volume (relevant + *for static volumes only) + * @bytes: size of the volume contents in bytes (relevant for static volumes + * only) + * @flags: volume flags (%UBI_VTBL_AUTORESIZE_FLG) + */ +struct ubigen_vol_info +{ + int id; + int type; + int alignment; + int data_pad; + int usable_leb_size; + const char *name; + int name_len; + int compat; + int used_ebs; + long long bytes; + uint8_t flags; +}; + +/** + * ubigen_info_init - initialize libubigen. + * @ui: libubigen information + * @peb_size: flash physical eraseblock size + * @min_io_size: flash minimum input/output unit size + * @subpage_size: flash sub-page, if present (has to be equivalent to + *@min_io_size if does not exist) + * @vid_hdr_offs: offset of the VID header + * @ubi_ver: UBI version + * @image_seq: UBI image sequence number + */ +void ubigen_info_init(struct ubigen_info *ui, int peb_size, int min_io_size, + int subpage_size, int vid_hdr_offs, int ubi_ver, + uint32_t image_seq); + +/** + * ubigen_create_empty_vtbl - creates empty volume table. + * @ui: libubigen information + * + * This function creates an empty volume table and returns a pointer to it in + * case of success and %NULL in case of failure. The returned object has to be + * freed with 'free()' call. + */ +struct ubi_vtbl_record *ubigen_create_empty_vtbl(const struct ubigen_info *ui); + +/** + * ubigen_init_ec_hdr - initialize EC header. + * @ui: libubigen information + * @hdr: the EC header to initialize + * @ec: erase counter value + */ +void ubigen_init_ec_hdr(const struct ubigen_info *ui, + struct ubi_ec_hdr *hdr, long long ec); + +/** + * ubigen_init_vid_hdr - initialize VID header. + * @ui: libubigen information + * @vi: volume information + * @hdr: the VID header to initialize + * @lnum: logical eraseblock number + * @data: the contents of the LEB (static volumes only) + * @data_size: amount of data in this LEB (static volumes only) + * + * Note, @used_ebs, @data and @data_size are ignored in case of dynamic + * volum
[PATCH 06/10] lib: add ubiutils-common
Imported from mtd-utils and stripped down to needed functionality for ubiformat. Signed-off-by: Wolfram Sang --- include/mtd/ubiutils-common.h | 26 + lib/Kconfig |3 + lib/Makefile |1 + lib/ubiutils-common.c | 122 + 4 files changed, 152 insertions(+) create mode 100644 include/mtd/ubiutils-common.h create mode 100644 lib/ubiutils-common.c diff --git a/include/mtd/ubiutils-common.h b/include/mtd/ubiutils-common.h new file mode 100644 index 000..3a16617 --- /dev/null +++ b/include/mtd/ubiutils-common.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) Artem Bityutskiy, 2007, 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __UBI_UTILS_COMMON_H__ +#define __UBI_UTILS_COMMON_H__ + +long long ubiutils_get_bytes(const char *str); +void ubiutils_print_bytes(long long bytes, int bracket); + +#endif /* !__UBI_UTILS_COMMON_H__ */ + diff --git a/lib/Kconfig b/lib/Kconfig index 13ecab0..b2d72df 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -41,6 +41,9 @@ config QSORT config XYMODEM bool +config UBIUTILS + bool + source lib/gui/Kconfig endmenu diff --git a/lib/Makefile b/lib/Makefile index eb0af92..76ca1db 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -34,5 +34,6 @@ obj-$(CONFIG_UNCOMPRESS) += uncompress.o obj-$(CONFIG_BCH) += bch.o obj-$(CONFIG_BITREV) += bitrev.o obj-$(CONFIG_QSORT)+= qsort.o +obj-$(CONFIG_UBIUTILS) += ubiutils-common.o obj-y += gui/ obj-$(CONFIG_XYMODEM) += xymodem.o diff --git a/lib/ubiutils-common.c b/lib/ubiutils-common.c new file mode 100644 index 000..d01e723 --- /dev/null +++ b/lib/ubiutils-common.c @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2007, 2008 Nokia Corporation + * + * 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. + */ + +/* + * This file contains various common stuff used by UBI utilities. + * + * Authors: Artem Bityutskiy + * Adrian Hunter + */ + +#include +#include +#include + +/** + * get_multiplier - convert size specifier to an integer multiplier. + * @str: the size specifier string + * + * This function parses the @str size specifier, which may be one of + * 'KiB', 'MiB', or 'GiB' into an integer multiplier. Returns positive + * size multiplier in case of success and %-1 in case of failure. + */ +static int get_multiplier(const char *str) +{ + if (!str) + return 1; + + /* Remove spaces before the specifier */ + while (*str == ' ' || *str == '\t') + str += 1; + + if (!strcmp(str, "KiB")) + return 1024; + if (!strcmp(str, "MiB")) + return 1024 * 1024; + if (!strcmp(str, "GiB")) + return 1024 * 1024 * 1024; + + return -1; +} + +/** + * ubiutils_get_bytes - convert a string containing amount of bytes into an + * integer + * @str: string to convert + * + * This function parses @str which may have one of 'KiB', 'MiB', or 'GiB' + * size specifiers. Returns positive amount of bytes in case of success and %-1 + * in case of failure. + */ +long long ubiutils_get_bytes(const char *str) +{ + char *endp; + long long bytes = simple_strtoull(str, &endp, 0); + + if (endp == str || bytes < 0) { + fprintf(stderr, "incorrect amount of bytes: \"%s\"\n", str); + return -1; + } + + if (*endp != '\0') { + int mult = get_multiplier(endp); + + if (mult == -1) { + fprintf(stderr, "bad size specifier: \"%s\" - " + "should be 'KiB', 'MiB' or 'GiB'\n", endp); +
[PATCH 07/10] lib: add libscan
Imported from mtd-utils and stripped down to needed functionality. Add prefix to functions so we have a clean namespace. Signed-off-by: Wolfram Sang --- include/mtd/libscan.h | 105 +++ lib/Kconfig |3 + lib/Makefile |1 + lib/libscan.c | 223 + 4 files changed, 332 insertions(+) create mode 100644 include/mtd/libscan.h create mode 100644 lib/libscan.c diff --git a/include/mtd/libscan.h b/include/mtd/libscan.h new file mode 100644 index 000..193b07b --- /dev/null +++ b/include/mtd/libscan.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2008 Nokia Corporation + * + * 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: Artem Bityutskiy + * + * UBI scanning library. + */ + +#ifndef __LIBSCAN_H__ +#define __LIBSCAN_H__ + +#include + +/* + * If an eraseblock does not contain an erase counter, this value is used + * instead of the erase counter. + */ +#define NO_EC 0x + +/* + * If an eraseblock contains a corrupted erase counter, this value is used + * instead of the erase counter. + */ +#define CORRUPT_EC 0xFFFE + +/* + * If an eraseblock does not contain an erase counter, one of these values is + * used. + * + * @EB_EMPTY: the eraseblock appeared to be empty + * @EB_CORRUPTED: the eraseblock contains corrupted erase counter header + * @EB_ALIEN: the eraseblock contains some non-UBI data + * @EC_MAX: maximum allowed erase counter value + */ +enum +{ + EB_EMPTY = 0x, + EB_CORRUPTED = 0xFFFE, + EB_ALIEN = 0xFFFD, + EB_BAD = 0xFFFC, + EC_MAX = UBI_MAX_ERASECOUNTER, +}; + +/** + * struct ubi_scan_info - UBI scanning information. + * @ec: erase counters or eraseblock status for all eraseblocks + * @mean_ec: mean erase counter + * @ok_cnt: count of eraseblock with correct erase counter header + * @empty_cnt: count of supposedly eraseblocks + * @corrupted_cnt: count of eraseblocks with corrupted erase counter header + * @alien_cnt: count of eraseblock containing non-ubi data + * @bad_cnt: count of bad eraseblocks + * @bad_cnt: count of non-bad eraseblocks + * @vid_hdr_offs: volume ID header offset from the found EC headers (%-1 means + *undefined) + * @data_offs: data offset from the found EC headers (%-1 means undefined) + */ +struct ubi_scan_info +{ + uint32_t *ec; + long long mean_ec; + int ok_cnt; + int empty_cnt; + int corrupted_cnt; + int alien_cnt; + int bad_cnt; + int good_cnt; + int vid_hdr_offs; + int data_offs; +}; + +struct mtd_dev_info; + +/** + * ubi_scan - scan an MTD device. + * @mtd: information about the MTD device to scan + * @fd: MTD device node file descriptor + * @info: the result of the scanning is returned here + * @verbose: verbose mode: %0 - be silent, %1 - output progress information, + * 2 - debugging output mode + */ +int libscan_ubi_scan(struct mtd_dev_info *mtd, int fd, struct ubi_scan_info **info, +int verbose); + +/** + * ubi_scan_free - free scanning information. + * @si: scanning information to free + */ +void libscan_ubi_scan_free(struct ubi_scan_info *si); + +#endif /* __LIBSCAN_H__ */ diff --git a/lib/Kconfig b/lib/Kconfig index b2d72df..1a283d6 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -44,6 +44,9 @@ config XYMODEM config UBIUTILS bool +config LIBSCAN + bool + source lib/gui/Kconfig endmenu diff --git a/lib/Makefile b/lib/Makefile index 76ca1db..72306f8 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -35,5 +35,6 @@ obj-$(CONFIG_BCH) += bch.o obj-$(CONFIG_BITREV) += bitrev.o obj-$(CONFIG_QSORT)+= qsort.o obj-$(CONFIG_UBIUTILS) += ubiutils-common.o +obj-$(CONFIG_LIBSCAN) += libscan.o obj-y += gui/ obj-$(CONFIG_XYMODEM) += xymodem.o diff --git a/lib/libscan.c b/lib/libscan.c new file mode 100644 index 000..951e0e7 --- /dev/null +++ b/lib/libscan.c @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2008 Nokia Corporation + * + * 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 pr
[PATCH 09/10] lib: add barebox version of libmtd
Based on mtd-utils and stripped down to needed functionality and reworked to barebox interfaces. Signed-off-by: Wolfram Sang --- include/mtd/libmtd.h | 154 + lib/Kconfig |3 + lib/Makefile |1 + lib/libmtd.c | 371 ++ 4 files changed, 529 insertions(+) create mode 100644 include/mtd/libmtd.h create mode 100644 lib/libmtd.c diff --git a/include/mtd/libmtd.h b/include/mtd/libmtd.h new file mode 100644 index 000..6267dac --- /dev/null +++ b/include/mtd/libmtd.h @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2008, 2009 Nokia Corporation + * + * 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: Artem Bityutskiy + * + * MTD library. + */ + +#ifndef __LIBMTD_H__ +#define __LIBMTD_H__ + +/* Maximum MTD device name length */ +#define MTD_NAME_MAX 127 +/* Maximum MTD device type string length */ +#define MTD_TYPE_MAX 64 + +/** + * struct mtd_dev_info - information about an MTD device. + * @node: node pointing to device + * @type: flash type (constants like %MTD_NANDFLASH defined in mtd-abi.h) + * @type_str: static R/O flash type string + * @name: device name + * @size: device size in bytes + * @eb_cnt: count of eraseblocks + * @eb_size: eraseblock size + * @min_io_size: minimum input/output unit size + * @subpage_size: sub-page size + * @oob_size: OOB size (zero if the device does not have OOB area) + * @region_cnt: count of additional erase regions + * @writable: zero if the device is read-only + * @bb_allowed: non-zero if the MTD device may have bad eraseblocks + */ +struct mtd_dev_info +{ + const char *node; + int type; + const char type_str[MTD_TYPE_MAX + 1]; + long long size; + int eb_cnt; + int eb_size; + int min_io_size; + int subpage_size; + int oob_size; + int region_cnt; + unsigned int writable:1; + unsigned int bb_allowed:1; +}; + +/** + * mtd_get_dev_info - get information about an MTD device. + * @desc: MTD library descriptor + * @node: name of the MTD device node + * @mtd: the MTD device information is returned here + * + * This function gets information about MTD device defined by the @node device + * node file and saves this information in the @mtd object. Returns %0 in case + * of success and %-1 in case of failure. If MTD subsystem is not present in the + * system, or the MTD device does not exist, errno is set to @ENODEV. + */ +int mtd_get_dev_info(const char *node, struct mtd_dev_info *mtd); + +/** + * mtd_erase - erase an eraseblock. + * @desc: MTD library descriptor + * @mtd: MTD device description object + * @fd: MTD device node file descriptor + * @eb: eraseblock to erase + * + * This function erases eraseblock @eb of MTD device described by @fd. Returns + * %0 in case of success and %-1 in case of failure. + */ +int mtd_erase(const struct mtd_dev_info *mtd, int fd, int eb); + +/** + * mtd_torture - torture an eraseblock. + * @desc: MTD library descriptor + * @mtd: MTD device description object + * @fd: MTD device node file descriptor + * @eb: eraseblock to torture + * + * This function tortures eraseblock @eb. Returns %0 in case of success and %-1 + * in case of failure. + */ +int mtd_torture(const struct mtd_dev_info *mtd, int fd, int eb); + +/** + * mtd_is_bad - check if eraseblock is bad. + * @mtd: MTD device description object + * @fd: MTD device node file descriptor + * @eb: eraseblock to check + * + * This function checks if eraseblock @eb is bad. Returns %0 if not, %1 if yes, + * and %-1 in case of failure. + */ +int mtd_is_bad(const struct mtd_dev_info *mtd, int fd, int eb); + +/** + * mtd_mark_bad - mark an eraseblock as bad. + * @mtd: MTD device description object + * @fd: MTD device node file descriptor + * @eb: eraseblock to mark as bad + * + * This function marks eraseblock @eb as bad. Returns %0 in case of success and + * %-1 in case of failure. + */ +int mtd_mark_bad(const struct mtd_dev_info *mtd, int fd, int eb); + +/** + * mtd_read - read data from an MTD device. + * @mtd: MTD device description object + * @fd: MTD device node file descriptor + * @eb: eraseblock to read from + * @offs: offset withing the eraseblock to read from + * @buf: buffer to read data to + * @len: how many bytes to read + * + * This function reads @len bytes of data
[PATCH 02/10] ubi: consolidate ubi-media.h
We have two versions in the tree. Use the newer one, and put it into the mtd directory while we are at it. Signed-off-by: Wolfram Sang --- commands/ubi.c |2 +- drivers/mtd/ubi/ubi.h|3 +- {drivers/mtd/ubi => include/mtd}/ubi-media.h |0 include/ubi-media.h | 370 -- 4 files changed, 3 insertions(+), 372 deletions(-) rename {drivers/mtd/ubi => include/mtd}/ubi-media.h (100%) delete mode 100644 include/ubi-media.h diff --git a/commands/ubi.c b/commands/ubi.c index bf70071..1653eaa 100644 --- a/commands/ubi.c +++ b/commands/ubi.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include static int do_ubimkvol(int argc, char *argv[]) { diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index 97aed8f..964a3c4 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -45,7 +45,8 @@ #include #include -#include "ubi-media.h" +#include + #include "scan.h" #include "debug.h" diff --git a/drivers/mtd/ubi/ubi-media.h b/include/mtd/ubi-media.h similarity index 100% rename from drivers/mtd/ubi/ubi-media.h rename to include/mtd/ubi-media.h diff --git a/include/ubi-media.h b/include/ubi-media.h deleted file mode 100644 index 4edbbb2..000 --- a/include/ubi-media.h +++ /dev/null @@ -1,370 +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. - * - * - * Authors: Artem 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_MEDIA_H__ -#define __UBI_MEDIA_H__ - -#ifndef DOXYGEN_SHOULD_SKIP_THIS - -#include - -/* The version of UBI images supported by this implementation */ -#define UBI_VERSION 1 - -/* The highest erase counter value supported by this implementation */ -#define UBI_MAX_ERASECOUNTER 0x7FFF - -/* The initial CRC32 value used when calculating CRC checksums */ -#define UBI_CRC32_INIT 0xU - -/* Erase counter header magic number (ASCII "UBI#") */ -#define UBI_EC_HDR_MAGIC 0x55424923 -/* Volume identifier header magic number (ASCII "UBI!") */ -#define UBI_VID_HDR_MAGIC 0x55424921 - -/* - * Volume type constants used in the volume identifier header. - * - * @UBI_VID_DYNAMIC: dynamic volume - * @UBI_VID_STATIC: static volume - */ -enum { - UBI_VID_DYNAMIC = 1, - UBI_VID_STATIC = 2 -}; - -/* - * Volume flags used in the volume table record. - * - * @UBI_VTBL_AUTORESIZE_FLG: auto-resize this volume - * - * %UBI_VTBL_AUTORESIZE_FLG flag can be set only for one volume in the volume - * table. UBI automatically re-sizes the volume which has this flag and makes - * the volume to be of largest possible size. This means that if after the - * initialization UBI finds out that there are available physical eraseblocks - * present on the device, it automatically appends all of them to the volume - * (the physical eraseblocks reserved for bad eraseblocks handling and other - * reserved physical eraseblocks are not taken). So, if there is a volume with - * the %UBI_VTBL_AUTORESIZE_FLG flag set, the amount of available logical - * eraseblocks will be zero after UBI is loaded, because all of them will be - * reserved for this volume. Note, the %UBI_VTBL_AUTORESIZE_FLG bit is cleared - * after the volume had been initialized. - * - * The auto-resize feature is useful for device production purposes. For - * example, different NAND flash chips may have different amount of initial bad - * eraseblocks, depending of particular chip instance. Manufacturers of NAND - * chips usually guarantee that the amount of initial bad eraseblocks does not - * exceed certain percent, e.g. 2%. When one creates an UBI image which will be - * flashed to the end devices in production, he does not know the exact amount - * of good physical eraseblocks the NAND chip on the device will have, but this - * number is required to calculate the volume sized and put them to the volume - * table of the UBI image. In this case, one of the volumes (e.g., the one - * which will store the root file system) is marked as "auto-resizable", and - * UBI will adjust its size on the first boot if needed. - * - * Note, first UBI reserves some amount of physical eraseblocks for bad - * eraseblock handling, and then re-sizes the volume, not vice-versa.
[PATCH 10/10] commands: add ubiformat
Imported from mtd-utils and stripped down to needed functionality. Based on an older version (1.4.5.) since the newer do use MEMWRITE interfaces which we don't have in barebox (yet). Signed-off-by: Wolfram Sang --- commands/Kconfig |9 + commands/Makefile|1 + commands/ubiformat.c | 794 ++ 3 files changed, 804 insertions(+) create mode 100644 commands/ubiformat.c diff --git a/commands/Kconfig b/commands/Kconfig index ac9b797..b30e84e 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -347,6 +347,15 @@ config CMD_UBI depends on UBI prompt "ubimkvol, ubirmvol, ubiattach" +config CMD_UBIFORMAT + tristate + depends on UBI + select LIBMTD + select LIBSCAN + select LIBUBIGEN + select UBIUTILS + prompt "ubiformat" + endmenu diff --git a/commands/Makefile b/commands/Makefile index effc91b..359f566 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -57,6 +57,7 @@ obj-$(CONFIG_CMD_UNCOMPRESS) += uncompress.o obj-$(CONFIG_CMD_I2C) += i2c.o obj-$(CONFIG_CMD_SPI) += spi.o obj-$(CONFIG_CMD_UBI) += ubi.o +obj-$(CONFIG_CMD_UBIFORMAT)+= ubiformat.o obj-$(CONFIG_CMD_MENU) += menu.o obj-$(CONFIG_CMD_PASSWD) += passwd.o obj-$(CONFIG_CMD_LOGIN)+= login.o diff --git a/commands/ubiformat.c b/commands/ubiformat.c new file mode 100644 index 000..e6b0e0f --- /dev/null +++ b/commands/ubiformat.c @@ -0,0 +1,794 @@ +/* + * Copyright (C) 2008 Nokia Corporation + * + * 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. + */ + +/* + * An utility to format MTD devices into UBI and flash UBI images. + * + * Author: Artem Bityutskiy + */ + +/* + * Maximum amount of consequtive eraseblocks which are considered as normal by + * this utility. Otherwise it is assume that something is wrong with the flash + * or the driver, and eraseblocks are stopped being marked as bad. + */ +#define MAX_CONSECUTIVE_BAD_BLOCKS 4 + +#define PROGRAM_VERSION "1.5" +#define PROGRAM_NAME"ubiformat" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* The variables below are set by command line arguments */ +struct args { + unsigned int quiet:1; + unsigned int verbose:1; + unsigned int override_ec:1; + unsigned int novtbl:1; + unsigned int manual_subpage; + int subpage_size; + int vid_hdr_offs; + int ubi_ver; + uint32_t image_seq; + long long ec; + const char *image; + const char *node; + int node_fd; +}; + +static struct args args; + +static int parse_opt(int argc, char *argv[]) +{ + srand(get_time_ns()); + memset(&args, 0, sizeof(args)); + args.ubi_ver = 1; + args.image_seq = rand(); + + while (1) { + int key; + unsigned long int image_seq; + + key = getopt(argc, argv, "nyqve:x:s:O:f:S:"); + if (key == -1) + break; + + switch (key) { + case 's': + args.subpage_size = ubiutils_get_bytes(optarg); + if (args.subpage_size <= 0) + return errmsg("bad sub-page size: \"%s\"", optarg); + if (!is_power_of_2(args.subpage_size)) + return errmsg("sub-page size should be power of 2"); + break; + + case 'O': + args.vid_hdr_offs = simple_strtoul(optarg, NULL, 0); + if (args.vid_hdr_offs <= 0) + return errmsg("bad VID header offset: \"%s\"", optarg); + break; + + case 'e': + args.ec = simple_strtoull(optarg, NULL, 0); + if (args.ec < 0) + return errmsg("bad erase counter value: \"%s\"", optarg); + if (args.ec >= EC_MAX) + return errmsg("too high erase %llu, counter, max is %u", args.ec, EC_MAX); + ar
Re: v2012.12.0
On 22:54 Sat 08 Dec , Thomas Petazzoni wrote: > Hello, > > On Fri, 7 Dec 2012 08:49:25 +0100, Sascha Hauer wrote: > > > We have a december release. In number of patches this is the > > biggest Release we ever had: 275 non merge patches have gone into this > > release. Here's some statisitics over the releases we currently have: > > FWIW, I have published > http://www.emlinews.net/2012/12/barebox-2012-12-released/ that attempts > to summarize the most important changes in this release. please fix my name inside it's PLAGNIOL-VILLARD so PLAGNOL-VILLARD I'm not Marcel ;) Best Regards, J. ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
Re: v2012.12.0
Dear Jean-Christophe PLAGNIOL-VILLARD, On Mon, 10 Dec 2012 09:16:26 +0100, Jean-Christophe PLAGNIOL-VILLARD > > FWIW, I have published > > http://www.emlinews.net/2012/12/barebox-2012-12-released/ that attempts > > to summarize the most important changes in this release. > please fix my name inside > > it's PLAGNIOL-VILLARD so PLAGNOL-VILLARD > > I'm not Marcel ;) Indeed, sorry. I've fixed it now. Thanks, Thomas -- Thomas Petazzoni, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH] net: add multiple nameserver support
On Sun, 2012-09-23 at 15:57 +0200, Christoph Fritz wrote: > On Sun, 2012-09-23 at 15:29 +0200, Jean-Christophe PLAGNIOL-VILLARD > wrote: > > On 14:11 Sun 23 Sep , Christoph Fritz wrote: > > > Today limit it to 2 > > > > > > Update dhcp support as option 6 allow to get n nameserver > > > If more than 2 nameserver are provided by the DHCP server ignore them. > > I rethink about it and no I do not want wo check it the format here > > > > as I plan to make the globalvar more commoon and swtich net to it too > > > > I'm fine when the not modified version gets applied. > > You can add a > Tested-by: Christoph Fritz *ping*, has this patch gotten lost? ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
ethernet doesn't work after update to v2012.12.0
Hi All, after updating to the version 2012.12.0 ethernet doesn't work anymore. My system is iMX53, ethernet Interface: MII100. What could be the cause? devinfo output: ... ` imx_iim0 ` 0x-0x001f: /dev/imx_iim_bank0 ` 0x-0x001f: /dev/imx_iim_bank1 ` 0x-0x001f: /dev/imx_iim_bank2 ` 0x-0x001f: /dev/imx_iim_bank3 ` 0x-0x001f: /dev/imx_iim_bank4 ` 0x-0x001f: /dev/imx_iim_bank5 ` 0x-0x001f: /dev/imx_iim_bank6 ` 0x-0x001f: /dev/imx_iim_bank7 ... ` imx27-fec ` miibus0 ` eth0 ... imx_iim fec_imx Generic PHY ... Best Regards, Slawa ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
Re: ethernet doesn't work after update to v2012.12.0
On Mon, Dec 10, 2012 at 05:44:21PM +0100, Wjatscheslaw Stoljarski (Slawa) wrote: > Hi All, > > after updating to the version 2012.12.0 ethernet doesn't work > anymore. My system is iMX53, ethernet Interface: MII100. What could > be the cause? > Sorry, networking in the v2012.12.0 Release is broken with the generic phy driver. I will post a fixup patch tomorrow and a fixup release later this week. See this for background: http://www.spinics.net/lists/u-boot-v2/msg11501.html Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0| Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917- | ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
[PATCH] esdctl: fix reset default bug on i.MX27/31
The i.MX27/31 have the second chip select enabled by reset default. This can be considered as a hardware bug, because even boards which need this settings cannot work out of reset because of the missing initialization sequence. Detect this reset default setting and disable this chipselect then to be able to properly detect the SDRAM size. Signed-off-by: Sascha Hauer --- arch/arm/mach-imx/esdctl.c | 25 +++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-imx/esdctl.c b/arch/arm/mach-imx/esdctl.c index a40399a..dd70e6d 100644 --- a/arch/arm/mach-imx/esdctl.c +++ b/arch/arm/mach-imx/esdctl.c @@ -199,6 +199,27 @@ static void imx_esdctl_v2_add_mem(void *esdctlbase, struct imx_esdctl_data *data data->base1, imx_v2_sdram_size(esdctlbase, 1)); } +/* + * On i.MX27 and i.MX31 the second chipselect is enabled by reset default. + * This setting makes it impossible to detect the correct SDRAM size on + * these SoCs. We disable the chipselect if this reset default setting is + * found. This of course leads to incorrect SDRAM detection on boards which + * really have this reset default as a valid setting. If you have such a + * board drop a mail to search for a solution. + */ +#define ESDCTL1_RESET_DEFAULT 0x81120080 + +static void imx_esdctl_v2_bug_add_mem(void *esdctlbase, struct imx_esdctl_data *data) +{ + u32 ctlval = readl(esdctlbase + IMX_ESDCTL1); + + if (ctlval == ESDCTL1_RESET_DEFAULT) + writel(0x0, esdctlbase + IMX_ESDCTL1); + + add_mem(data->base0, imx_v2_sdram_size(esdctlbase, 0), + data->base1, imx_v2_sdram_size(esdctlbase, 1)); +} + static void imx_esdctl_v3_add_mem(void *esdctlbase, struct imx_esdctl_data *data) { add_mem(data->base0, imx_v3_sdram_size(esdctlbase, 0), @@ -245,13 +266,13 @@ static __maybe_unused struct imx_esdctl_data imx25_data = { static __maybe_unused struct imx_esdctl_data imx27_data = { .base0 = MX27_CSD0_BASE_ADDR, .base1 = MX27_CSD1_BASE_ADDR, - .add_mem = imx_esdctl_v2_add_mem, + .add_mem = imx_esdctl_v2_bug_add_mem, }; static __maybe_unused struct imx_esdctl_data imx31_data = { .base0 = MX31_CSD0_BASE_ADDR, .base1 = MX31_CSD1_BASE_ADDR, - .add_mem = imx_esdctl_v2_add_mem, + .add_mem = imx_esdctl_v2_bug_add_mem, }; static __maybe_unused struct imx_esdctl_data imx35_data = { -- 1.7.10.4 ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox