From: Tomasz Figa <tomasz.figa@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/1] jffs2: Fix zero sector_size when not using CONFIG_JFFS2_CMDLINE
Date: Tue, 30 Dec 2008 18:35:57 +0100 [thread overview]
Message-ID: <200812301835.57435.tomasz.figa@gmail.com> (raw)
This patch fixes a bug (?) introduced after inclusion of the new JFFS2 code.
When not using CONFIG_JFFS2_CMDLINE, the code in cmd_jffs2.c doesn't fill in
part->sector_size (keeping it as 0), but a correct value is needed by the code
in jffs2_1pass.c. This causes all JFFS2 accesses to be in the same place of the
memory, what obviously means impossibility to use the JFFS2 partition.
This problem is fixed in this patch by including sector size calculation in
non-CONFIG_JFFS2_CMDLINE mtdparts_init variant.
Signed-off-by: Tomasz Figa <tomasz.figa_at_gmail.com>
---
diff --git a/common/cmd_jffs2.c b/common/cmd_jffs2.c
index 7866c80..fe0f8d7 100644
--- a/common/cmd_jffs2.c
+++ b/common/cmd_jffs2.c
@@ -1778,6 +1778,96 @@ int mtdparts_init(void)
*/
/**
+ * Calculate sector size.
+ *
+ * @return sector size
+ */
+static inline u32 get_part_sector_size_nand(struct mtdids *id)
+{
+#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
+#if defined(CONFIG_NAND_LEGACY)
+ extern struct nand_chip nand_dev_desc[CONFIG_SYS_MAX_NAND_DEVICE];
+
+ return nand_dev_desc[id->num].erasesize;
+#else
+ nand_info_t *nand;
+
+ nand = &nand_info[id->num];
+
+ return nand->erasesize;
+#endif
+#else
+ BUG();
+ return 0;
+#endif
+}
+
+static inline u32 get_part_sector_size_nor(struct mtdids *id, struct
part_info *part)
+{
+#if defined(CONFIG_CMD_FLASH)
+ extern flash_info_t flash_info[];
+
+ u32 end_phys, start_phys, sector_size = 0, size = 0;
+ int i;
+ flash_info_t *flash;
+
+ flash = &flash_info[id->num];
+
+ start_phys = flash->start[0] + part->offset;
+ end_phys = start_phys + part->size;
+
+ for (i = 0; i < flash->sector_count; i++) {
+ if (flash->start[i] >= end_phys)
+ break;
+
+ if (flash->start[i] >= start_phys) {
+ if (i == flash->sector_count - 1) {
+ size = flash->start[0] + flash->size - flash->start[i];
+ } else {
+ size = flash->start[i+1] - flash->start[i];
+ }
+
+ if (sector_size < size)
+ sector_size = size;
+ }
+ }
+
+ return sector_size;
+#else
+ BUG();
+ return 0;
+#endif
+}
+
+static inline u32 get_part_sector_size_onenand(void)
+{
+#if defined(CONFIG_CMD_ONENAND)
+ struct mtd_info *mtd;
+
+ mtd = &onenand_mtd;
+
+ return mtd->erasesize;
+#else
+ BUG();
+ return 0;
+#endif
+}
+
+static inline u32 get_part_sector_size(struct mtdids *id, struct part_info
*part)
+{
+ if (id->type == MTD_DEV_TYPE_NAND)
+ return get_part_sector_size_nand(id);
+ else if (id->type == MTD_DEV_TYPE_NOR)
+ return get_part_sector_size_nor(id, part);
+ else if (id->type == MTD_DEV_TYPE_ONENAND)
+ return get_part_sector_size_onenand();
+ else
+ DEBUGF("Error: Unknown device type.\n");
+
+ return 0;
+}
+
+/**
* Parse and initialize global mtdids mapping and create global
* device/partition list.
*
@@ -1846,6 +1936,8 @@ int mtdparts_init(void)
part->offset = 0x00000000;
#endif
+ part->sector_size = get_part_sector_size(id, part);
+
part->dev = current_dev;
INIT_LIST_HEAD(&part->link);
next reply other threads:[~2008-12-30 17:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-30 17:35 Tomasz Figa [this message]
2009-01-27 21:54 ` [U-Boot] [PATCH 1/1] jffs2: Fix zero sector_size when not using CONFIG_JFFS2_CMDLINE Wolfgang Denk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200812301835.57435.tomasz.figa@gmail.com \
--to=tomasz.figa@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox