[U-Boot] [PATCH v2] mmc: Update "mmc->part_num" when performing a partition switch

Fabio Estevam festevam at gmail.com
Tue Jun 4 22:45:28 CEST 2013


Hi Stephen,

On Tue, Jun 4, 2013 at 4:36 PM, Stephen Warren <swarren at wwwdotorg.org> wrote:

> That seems like a reasonable way for the code to work. However, you'd
> need to modify common/env_mmc.c:init_mmc_for_env() so that it saves off
> mmc->part_num before switching MMC partitions, so that
> fini_mmc_for_env() knows which partition to switch back to. Right now,
> it relies on the fact that mmc_switch_part() does not update
> mmc->part_num, and hence uses that value to save the previously selected
> partition ID.
>
> Also, if you make this change, I think you can update
> common/cmd_mmc.c:do_mmcops(), since it will no longer need to update
> mmc->part_num after a successful switch.

I understood your second suggestion and did the changes below, but I
am not sure on the first one regarding the change you proposed inside
init_mmc_for_env().

Here is what I did so far:

diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index 7d82469..20a2792 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -243,8 +243,6 @@ static int do_mmcops(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])

 			if (part != mmc->part_num) {
 				ret = mmc_switch_part(dev, part);
-				if (!ret)
-					mmc->part_num = part;

 				printf("switch to partions #%d, %s\n",
 						part, (!ret) ? "OK" : "ERROR");
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 0a2f535..e8d2ea6 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -702,14 +702,20 @@ static int mmc_change_freq(struct mmc *mmc)

 int mmc_switch_part(int dev_num, unsigned int part_num)
 {
+	int ret;
 	struct mmc *mmc = find_mmc_device(dev_num);

 	if (!mmc)
 		return -1;

-	return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF,
+	ret = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF,
 			  (mmc->part_config & ~PART_ACCESS_MASK)
 			  | (part_num & PART_ACCESS_MASK));
+
+	if (!ret)
+		mmc->part_num = part_num;
+
+	return ret;
 }

 int mmc_getcd(struct mmc *mmc)
-- 
1.8.1.2

Could you please explain the change you proposed for saving
mmc->part_num inside init_mmc_for_env() ?


More information about the U-Boot mailing list