public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
To: David Woodhouse <dwmw2@infradead.org>,
	Brian Norris <computersforpeace@gmail.com>,
	linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Cc: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Subject: [PATCH] mtd: Expose partition offset to the drivers
Date: Mon,  2 Feb 2015 17:22:32 +0100	[thread overview]
Message-ID: <1422894152-29362-1-git-send-email-ricardo.ribalda@gmail.com> (raw)

Currently, there is no way to find out the offset of an mtd partition by
a driver. This might be needed by external hardware.

For example, a flash containing the firmware of an external device that
is also accessible by the main cpu/kernel.

The flash is big enough to have two partitions with 2 versions of the
firmware, so we can have a safe upgrade.

Once the flash has been updated we need the real offset, so we can write
it on the external device registers.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/mtd/mtdpart.c          | 8 ++++++++
 include/linux/mtd/partitions.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index a3e3a7d..8047e74 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -784,3 +784,11 @@ uint64_t mtd_get_device_size(const struct mtd_info *mtd)
 	return PART(mtd)->master->size;
 }
 EXPORT_SYMBOL_GPL(mtd_get_device_size);
+
+uint64_t mtd_get_device_offset(const struct mtd_info *mtd){
+	if (!mtd_is_partition(mtd))
+		return 0;
+
+	return PART(mtd)->offset;
+}
+EXPORT_SYMBOL_GPL(mtd_get_device_offset);
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index 6a35e6d..2b953b4 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -84,5 +84,6 @@ int mtd_add_partition(struct mtd_info *master, const char *name,
 		      long long offset, long long length);
 int mtd_del_partition(struct mtd_info *master, int partno);
 uint64_t mtd_get_device_size(const struct mtd_info *mtd);
+uint64_t mtd_get_device_offset(const struct mtd_info *mtd);
 
 #endif
-- 
2.1.4

             reply	other threads:[~2015-02-02 16:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-02 16:22 Ricardo Ribalda Delgado [this message]
2015-02-02 19:17 ` [PATCH] mtd: Expose partition offset to the drivers Richard Weinberger
2015-02-02 19:33   ` Ricardo Ribalda Delgado
2015-02-02 19:37     ` Richard Weinberger
2015-02-02 19:51       ` Ricardo Ribalda Delgado

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=1422894152-29362-1-git-send-email-ricardo.ribalda@gmail.com \
    --to=ricardo.ribalda@gmail.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    /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