Skip to content
Snippets Groups Projects
Commit c0a05bd1 authored by Nico's avatar Nico
Browse files

flash debugging

parent 5a0466e2
Branches
No related tags found
No related merge requests found
From: Nico <github@nicoboehr.de>
Date: Sun, 9 Mar 2025 11:05:38 +0000
Subject: add patch for flash debugging
diff --git a/target/linux/ath79/patches-6.6/910-flashdebug.patch b/target/linux/ath79/patches-6.6/910-flashdebug.patch
new file mode 100644
index 0000000000000000000000000000000000000000..239cc92b973a8989ac65aa8ebd7447823b01ee6a
--- /dev/null
+++ b/target/linux/ath79/patches-6.6/910-flashdebug.patch
@@ -0,0 +1,141 @@
+--- a/drivers/mtd/mtdcore.c
++++ b/drivers/mtd/mtdcore.c
+@@ -6,6 +6,7 @@
+ * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
+ * Copyright © 2006 Red Hat UK Limited
+ */
++#define DEBUG
+
+ #include <linux/module.h>
+ #include <linux/kernel.h>
+@@ -2299,20 +2300,29 @@ EXPORT_SYMBOL_GPL(mtd_lock);
+ int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+ {
+ struct mtd_info *master = mtd_get_master(mtd);
++ int r;
+
+- if (!master->_unlock)
++ if (!master->_unlock) {
++ printk("mtd: no unlock operation for %s\n", mtd->name);
+ return -EOPNOTSUPP;
+- if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
++ }
++ if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs) {
++ printk("mtd: unlock out of band for %s\n", mtd->name);
+ return -EINVAL;
+- if (!len)
++ }
++ if (!len) {
++ printk("mtd: zero length %s\n", mtd->name);
+ return 0;
++ }
+
+ if (mtd->flags & MTD_SLC_ON_MLC_EMULATION) {
+ ofs = (loff_t)mtd_div_by_eb(ofs, mtd) * master->erasesize;
+ len = (u64)mtd_div_by_eb(len, mtd) * master->erasesize;
+ }
+
+- return master->_unlock(master, mtd_get_master_ofs(mtd, ofs), len);
++ r = master->_unlock(master, mtd_get_master_ofs(mtd, ofs), len);
++ printk("mtd_unlock: %s return %d\n", mtd->name, r);
++ return r;
+ }
+ EXPORT_SYMBOL_GPL(mtd_unlock);
+
+--- a/drivers/mtd/spi-nor/core.c
++++ b/drivers/mtd/spi-nor/core.c
+@@ -6,6 +6,7 @@
+ * Copyright (C) 2005, Intec Automation Inc.
+ * Copyright (C) 2014, Freescale Semiconductor, Inc.
+ */
++#define DEBUG
+
+ #include <linux/err.h>
+ #include <linux/errno.h>
+--- a/fs/jffs2/build.c
++++ b/fs/jffs2/build.c
+@@ -119,12 +119,12 @@ static int jffs2_build_filesystem(struct
+
+ if (c->flags & (1 << 7)) {
+ printk("%s(): unlocking the mtd device... ", __func__);
+- mtd_unlock(c->mtd, 0, c->mtd->size);
+- printk("done.\n");
++ ret = mtd_unlock(c->mtd, 0, c->mtd->size);
++ printk("unlock done with ret=%d.\n", ret);
+
+ printk("%s(): erasing all blocks after the end marker... ", __func__);
+- jffs2_erase_pending_blocks(c, -1);
+- printk("done.\n");
++ ret = jffs2_erase_pending_blocks(c, -1);
++ printk("erase done with ret=%d.\n", ret);
+ }
+
+ dbg_fsbuild("pass 1 starting\n");
+--- a/drivers/mtd/spi-nor/swp.c
++++ b/drivers/mtd/spi-nor/swp.c
+@@ -253,15 +253,21 @@ static int spi_nor_sr_unlock(struct spi_
+ bool can_be_top = true, can_be_bottom = nor->flags & SNOR_F_HAS_SR_TB;
+ bool use_top;
+
++ printk("nor->flags = %x\n", nor->flags);
++
+ ret = spi_nor_read_sr(nor, nor->bouncebuf);
+- if (ret)
++ if (ret) {
++ printk("spi_nor_sr_unlock: spi_no_read_sr() failed with %d\n", ret);
+ return ret;
++ }
+
+ status_old = nor->bouncebuf[0];
+
+ /* If nothing in our range is locked, we don't need to do anything */
+- if (spi_nor_is_unlocked_sr(nor, ofs, len, status_old))
++ if (spi_nor_is_unlocked_sr(nor, ofs, len, status_old)) {
++ printk("spi_nor_sr_unlock: already unlocked");
+ return 0;
++ }
+
+ /* If anything below us is locked, we can't use 'top' protection */
+ if (!spi_nor_is_unlocked_sr(nor, 0, ofs, status_old))
+@@ -272,8 +278,10 @@ static int spi_nor_sr_unlock(struct spi_
+ status_old))
+ can_be_bottom = false;
+
+- if (!can_be_bottom && !can_be_top)
++ if (!can_be_bottom && !can_be_top) {
++ printk("spi_nor_sr_unlock: ofs=%lld len=%llu mtd->size=%llu\n", ofs, len, mtd->size);
+ return -EINVAL;
++ }
+
+ /* Prefer top, if both are valid */
+ use_top = can_be_top;
+@@ -295,8 +303,10 @@ static int spi_nor_sr_unlock(struct spi_
+ val = (val & ~SR_BP3) | SR_BP3_BIT6;
+
+ /* Some power-of-two sizes are not supported */
+- if (val & ~mask)
++ if (val & ~mask) {
++ printk("spi_nor_sr_unlock: unsupported power of two: val=%x mask=%x\n", val, mask);
+ return -EINVAL;
++ }
+ }
+
+ status_new = (status_old & ~mask & ~tb_mask) | val;
+@@ -313,10 +323,15 @@ static int spi_nor_sr_unlock(struct spi_
+ return 0;
+
+ /* Only modify protection if it will not lock other areas */
+- if ((status_new & mask) > (status_old & mask))
++ if ((status_new & mask) > (status_old & mask)) {
++ printk("spi_nor_sr_unlock: status_new=%x status_old=%x\n", status_new, status_old);
+ return -EINVAL;
++ }
+
+- return spi_nor_write_sr_and_check(nor, status_new);
++ ret = spi_nor_write_sr_and_check(nor, status_new);
++ if (ret)
++ printk("spi_nor_sr_unlock: spi_nor_write_sr_and_check failed with %d\n", ret);
++ return ret;
+ }
+
+ /*
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment