aboutsummaryrefslogtreecommitdiff
path: root/common/env_mmc.c
diff options
context:
space:
mode:
authorStephen Warren2015-12-07 11:38:49 -0700
committerTom Rini2016-01-13 21:05:19 -0500
commit873cc1d7775ed5de07e6722c7ff423080c2e8f71 (patch)
tree6540fea6fcf0edf8da6904f168e2dbd75259dc56 /common/env_mmc.c
parent7c4213f6a52f35ff6ba2d97aa4eb04cbfc963b86 (diff)
mmc: store hwpart in the block device
This will allow us to have multiple block device structs each referring to the same eMMC device, yet different HW partitions. For now, there is still a single block device per eMMC device. As before, this block device always accesses whichever HW partition was most recently selected. Clients wishing to make use of multiple block devices referring to different HW partitions can simply take a copy of this block device once it points at the correct HW partition, and use each one as they wish. This feature will be used by the next patch. In the future, perhaps get_device() could be enhanced to return a dynamically allocated block device struct, to avoid the client needing to copy it in order to maintain multiple block devices. However, this would require all users to be updated to free those block device structs at some point, which is rather a large change. Most callers of mmc_switch_part() wish to permanently switch the default MMC block device's HW partition. Enhance mmc_switch_part() so that it does this. This removes the need for callers to do this. However, common/env_mmc.c needs to save and restore the current HW partition. Make it do this more explicitly. Replace use of mmc_switch_part() with mmc_select_hwpart() in order to remove duplicate code that skips the call if that HW partition is already selected. Signed-off-by: Stephen Warren <swarren@nvidia.com> Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'common/env_mmc.c')
-rw-r--r--common/env_mmc.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/common/env_mmc.c b/common/env_mmc.c
index f182749e8b8..15aa43d5e16 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -69,6 +69,8 @@ __weak uint mmc_get_env_part(struct mmc *mmc)
return CONFIG_SYS_MMC_ENV_PART;
}
+static unsigned char env_mmc_orig_hwpart;
+
static int mmc_set_env_part(struct mmc *mmc)
{
uint part = mmc_get_env_part(mmc);
@@ -79,11 +81,10 @@ static int mmc_set_env_part(struct mmc *mmc)
dev = 0;
#endif
- if (part != mmc->part_num) {
- ret = mmc_switch_part(dev, part);
- if (ret)
- puts("MMC partition switch failed\n");
- }
+ env_mmc_orig_hwpart = mmc->block_dev.hwpart;
+ ret = mmc_select_hwpart(dev, part);
+ if (ret)
+ puts("MMC partition switch failed\n");
return ret;
}
@@ -113,8 +114,7 @@ static void fini_mmc_for_env(struct mmc *mmc)
#ifdef CONFIG_SPL_BUILD
dev = 0;
#endif
- if (mmc_get_env_part(mmc) != mmc->part_num)
- mmc_switch_part(dev, mmc->part_num);
+ mmc_select_hwpart(dev, env_mmc_orig_hwpart);
#endif
}