public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] blk: Invalidate block cache when switching hwpart
@ 2019-07-11  7:10 Weijie Gao
  2019-07-19  0:00 ` Tom Rini
  2019-08-22 13:58 ` Felix Brack
  0 siblings, 2 replies; 7+ messages in thread
From: Weijie Gao @ 2019-07-11  7:10 UTC (permalink / raw)
  To: u-boot

Some storage devices have multiple hw partitions and both address from
zero, for example eMMC.
However currently block cache invalidation only applies to block
write/erase.
This can cause a problem that data of current hw partition is cached
before switching to another hw partition. And the following read
operation of the latter hw partition will get wrong data when reading
from the addresses that have been cached previously.

To solve this problem, invalidate block cache after a successful
select_hwpart operation.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
---
 drivers/block/blk-uclass.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index baaf431e5e0..c23b6682a6c 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -208,7 +208,11 @@ int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart)
 	if (ret)
 		return ret;
 
-	return blk_select_hwpart(dev, hwpart);
+	ret = blk_select_hwpart(dev, hwpart);
+	if (!ret)
+		blkcache_invalidate(if_type, devnum);
+
+	return ret;
 }
 
 int blk_list_part(enum if_type if_type)
@@ -348,7 +352,13 @@ int blk_select_hwpart(struct udevice *dev, int hwpart)
 
 int blk_dselect_hwpart(struct blk_desc *desc, int hwpart)
 {
-	return blk_select_hwpart(desc->bdev, hwpart);
+	int ret;
+
+	ret = blk_select_hwpart(desc->bdev, hwpart);
+	if (!ret)
+		blkcache_invalidate(desc->if_type, desc->devnum);
+
+	return ret;
 }
 
 int blk_first_device(int if_type, struct udevice **devp)
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-08-27  7:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-11  7:10 [U-Boot] [PATCH] blk: Invalidate block cache when switching hwpart Weijie Gao
2019-07-19  0:00 ` Tom Rini
2019-08-22 13:58 ` Felix Brack
2019-08-26  8:19   ` Weijie Gao
2019-08-26 12:43     ` Felix Brack
2019-08-27  3:07       ` Weijie Gao
2019-08-27  7:46         ` Felix Brack

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox