From: Lukasz Majewski <l.majewski@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] dfu: mmc: Provide support for eMMC boot partition access
Date: Fri, 09 May 2014 16:58:15 +0200 [thread overview]
Message-ID: <1399647495-27205-1-git-send-email-l.majewski@samsung.com> (raw)
In-Reply-To: <1396255729-6573-2-git-send-email-l.majewski@samsung.com>
Before this patch it was only possible to access the default eMMC HW
partition. By partition selection I mean the access to eMMC via the
ext_csd[179] register programming.
It sometimes happens that it is necessary to write to other partitions.
This patch adds extra attribute to "raw" sub type of the dfu_alt_info
environment variable (e.g. boot-mmc.bin raw 0x0 0x200 mmcpart 1;)
It saves the original boot value and restores it after storing the file.
Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
---
Changes for v2:
- Adjust the code to be applicable on top of newest u-boot-usb branch
---
drivers/dfu/dfu_mmc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
include/dfu.h | 3 +++
2 files changed, 49 insertions(+)
diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
index 5e10ea7..63cc876 100644
--- a/drivers/dfu/dfu_mmc.c
+++ b/drivers/dfu/dfu_mmc.c
@@ -18,11 +18,29 @@ static unsigned char __aligned(CONFIG_SYS_CACHELINE_SIZE)
dfu_file_buf[CONFIG_SYS_DFU_MAX_FILE_SIZE];
static long dfu_file_buf_len;
+static int mmc_access_part(struct dfu_entity *dfu, struct mmc *mmc, int part)
+{
+ int ret;
+
+ if (part == mmc->part_num)
+ return 0;
+
+ ret = mmc_switch_part(dfu->dev_num, part);
+ if (ret) {
+ error("Cannot switch to partition %d\n", part);
+ return ret;
+ }
+ mmc->part_num = part;
+
+ return 0;
+}
+
static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu,
u64 offset, void *buf, long *len)
{
struct mmc *mmc = find_mmc_device(dfu->dev_num);
u32 blk_start, blk_count, n = 0;
+ int ret, part_num_bkp = 0;
/*
* We must ensure that we work in lba_blk_size chunks, so ALIGN
@@ -39,6 +57,13 @@ static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu,
return -EINVAL;
}
+ if (dfu->data.mmc.hw_partition >= 0) {
+ part_num_bkp = mmc->part_num;
+ ret = mmc_access_part(dfu, mmc, dfu->data.mmc.hw_partition);
+ if (ret)
+ return ret;
+ }
+
debug("%s: %s dev: %d start: %d cnt: %d buf: 0x%p\n", __func__,
op == DFU_OP_READ ? "MMC READ" : "MMC WRITE", dfu->dev_num,
blk_start, blk_count, buf);
@@ -57,9 +82,17 @@ static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu,
if (n != blk_count) {
error("MMC operation failed");
+ if (dfu->data.mmc.hw_partition >= 0)
+ mmc_access_part(dfu, mmc, part_num_bkp);
return -EIO;
}
+ if (dfu->data.mmc.hw_partition >= 0) {
+ ret = mmc_access_part(dfu, mmc, part_num_bkp);
+ if (ret)
+ return ret;
+ }
+
return 0;
}
@@ -194,6 +227,8 @@ int dfu_read_medium_mmc(struct dfu_entity *dfu, u64 offset, void *buf,
* 2nd and 3rd:
* lba_start and lba_size, for raw write
* mmc_dev and mmc_part, for filesystems and part
+ * 4th (optional):
+ * mmcpart <num> (access to HW eMMC partitions)
*/
int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
{
@@ -233,11 +268,22 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
return -ENODEV;
}
+ dfu->data.mmc.hw_partition = -EINVAL;
if (!strcmp(entity_type, "raw")) {
dfu->layout = DFU_RAW_ADDR;
dfu->data.mmc.lba_start = second_arg;
dfu->data.mmc.lba_size = third_arg;
dfu->data.mmc.lba_blk_size = mmc->read_bl_len;
+
+ /*
+ * Check for an extra entry at dfu_alt_info env variable
+ * specifying the mmc HW defined partition number
+ */
+ if (s)
+ if (!strcmp(strsep(&s, " "), "mmcpart"))
+ dfu->data.mmc.hw_partition =
+ simple_strtoul(s, NULL, 0);
+
} else if (!strcmp(entity_type, "part")) {
disk_partition_t partinfo;
block_dev_desc_t *blk_dev = &mmc->block_dev;
diff --git a/include/dfu.h b/include/dfu.h
index 986598e..26ffbc8 100644
--- a/include/dfu.h
+++ b/include/dfu.h
@@ -43,6 +43,9 @@ struct mmc_internal_data {
unsigned int lba_size;
unsigned int lba_blk_size;
+ /* eMMC HW partition access */
+ int hw_partition;
+
/* FAT/EXT */
unsigned int dev;
unsigned int part;
--
1.7.10.4
next prev parent reply other threads:[~2014-05-09 14:58 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-31 8:48 [U-Boot] [PATCH 0/3] dfu: Several enhancements for dfu subsystem Lukasz Majewski
2014-03-31 8:48 ` [U-Boot] [PATCH 1/3] dfu: mmc: Provide support for eMMC boot partition access Lukasz Majewski
2014-03-31 8:59 ` Marek Vasut
2014-03-31 9:14 ` Lukasz Majewski
2014-05-09 14:58 ` Lukasz Majewski [this message]
2014-05-14 22:24 ` [U-Boot] [PATCH v2] " Marek Vasut
2014-03-31 8:48 ` [U-Boot] [PATCH 2/3] dfu: add static alt num count in dfu_config_entities() Lukasz Majewski
2014-03-31 9:01 ` Marek Vasut
2014-03-31 9:15 ` Lukasz Majewski
2014-04-01 6:47 ` Przemyslaw Marczak
2014-04-01 6:49 ` Marek Vasut
2014-04-01 7:45 ` Lukasz Majewski
2014-03-31 8:48 ` [U-Boot] [PATCH 3/3] dfu: Introduction of the "dfu_checksum_method" env variable for checksum method setting Lukasz Majewski
2014-03-31 9:04 ` Marek Vasut
2014-03-31 9:24 ` Lukasz Majewski
2014-03-31 9:29 ` Marek Vasut
2014-03-31 9:49 ` Lukasz Majewski
2014-03-31 11:19 ` Pantelis Antoniou
2014-03-31 12:04 ` Lukasz Majewski
2014-03-31 12:10 ` Pantelis Antoniou
2014-03-31 12:16 ` Pantelis Antoniou
2014-03-31 18:05 ` Tom Rini
2014-03-31 18:15 ` Marek Vasut
2014-03-31 18:26 ` Tom Rini
2014-03-31 20:44 ` Lukasz Majewski
2014-03-31 21:04 ` Tom Rini
2014-04-01 9:05 ` Lukasz Majewski
2014-03-31 21:44 ` Tormod Volden
2014-04-01 9:00 ` Lukasz Majewski
2014-04-01 9:15 ` Stefan Schmidt
2014-04-01 11:31 ` Lukasz Majewski
2014-05-05 13:16 ` [U-Boot] [PATCH v2] " Lukasz Majewski
2014-05-05 17:47 ` Marek Vasut
2014-05-08 12:27 ` [U-Boot] [PATCH v3] dfu: Introduction of the "dfu_hash_algo" " Lukasz Majewski
2014-05-08 13:07 ` Marek Vasut
2014-05-09 4:27 ` Wolfgang Denk
2014-05-09 6:52 ` Lukasz Majewski
2014-05-09 8:31 ` Wolfgang Denk
2014-05-09 9:54 ` Lukasz Majewski
2014-05-12 14:45 ` Tom Rini
2014-05-15 7:09 ` Lukasz Majewski
2014-05-15 9:27 ` Heiko Schocher
2014-05-15 11:19 ` Wolfgang Denk
2014-05-15 13:43 ` Lukasz Majewski
2014-05-15 14:07 ` Wolfgang Denk
2014-05-16 6:08 ` Lukasz Majewski
2014-05-16 8:58 ` Lukasz Majewski
2014-05-19 14:02 ` Heiko Schocher
2014-05-20 17:22 ` Lukasz Majewski
2014-05-22 9:46 ` Lukasz Majewski
2014-05-12 8:43 ` [U-Boot] [PATCH v4] " Lukasz Majewski
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=1399647495-27205-1-git-send-email-l.majewski@samsung.com \
--to=l.majewski@samsung.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