Always assume that the top lmb is the u-boot region. Set *uptop to
0 to avoid printing meaningless Gap size, as it ends at the end of
memory, just like the `code` region.

Signed-off-by: Shiji Yang <[email protected]>
---

Before(one lmb):
Region                Base          Size           End           Gap
--------------------------------------------------------------------
code              83fa0000         5c858      83ffc858
malloc            83b9e000        402000      83fa0000             0
board_info        83b9dfd0            28      83b9dff8             8
global_data       83b9df10            c0      83b9dfd0             0
devicetree        83b9cd10          11fa      83b9df0a             6
stack             8339c000        800000      83b9c000           d10
lmb               8339c000        c64000      84000000      ff39c000  <-- wrong 
meaningless Gap size
free              80000000       339c000      8339c000             0

After(one lmb):
Region                Base          Size           End           Gap
--------------------------------------------------------------------
code              83fa0000         5c858      83ffc858
malloc            83b9e000        402000      83fa0000             0
board_info        83b9dfd0            28      83b9dff8             8
global_data       83b9df10            c0      83b9dfd0             0
devicetree        83b9cd10          11fa      83b9df0a             6
stack             8339c000        800000      83b9c000           d10
lmb               8339c000        c64000      84000000
free              80000000       339c000      8339c000             0


Before(two lmb):
Region                Base          Size           End           Gap
--------------------------------------------------------------------
code              83fa0000         5c858      83ffc858
malloc            83b9e000        402000      83fa0000             0
board_info        83b9dfd0            28      83b9dff8             8
global_data       83b9df10            c0      83b9dfd0             0
devicetree        83b9cd10          11fa      83b9df0a             6
stack             8339c000        800000      83b9c000           d10
lmb               8339c000             0      8339c000             0  <-- 
strange zero length lmb region
lmb               82000000       139c000      8339c000             0
free              80000000       2000000      82000000             0

After(two lmb):
Region                Base          Size           End           Gap
--------------------------------------------------------------------
code              83fa0000         5c858      83ffc858
malloc            83b9e000        402000      83fa0000             0
board_info        83b9dfd0            28      83b9dff8             8
global_data       83b9df10            c0      83b9dfd0             0
devicetree        83b9cd10          11fa      83b9df0a             6
stack             8339c000        800000      83b9c000           d10
lmb               8339c000        c64000      84000000
lmb               82000000       139c000      8339c000             0
free              80000000       2000000      82000000             0
 cmd/meminfo.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/cmd/meminfo.c b/cmd/meminfo.c
index 69a5b1b51a2..3063cb92d3d 100644
--- a/cmd/meminfo.c
+++ b/cmd/meminfo.c
@@ -40,15 +40,14 @@ static void show_lmb(const struct lmb *lmb, ulong *uptop)
                const struct lmb_region *rgn = alist_get(&lmb->used_mem, i,
                                                         struct lmb_region);
 
-               /*
-                * Assume that the top lmb region is the U-Boot region, so just
-                * take account of the memory not already reported
-                */
-               if (lmb->used_mem.count - 1)
+               /* Assume that the top lmb region is the U-Boot region */
+               if (i == lmb->used_mem.count - 1) {
+                       *uptop = 0;
+                       print_region("lmb", rgn->base, rgn->size, uptop);
+               } else {
                        print_region("lmb", rgn->base, *uptop - rgn->base,
                                     uptop);
-               else
-                       print_region("lmb", rgn->base, rgn->size, uptop);
+               }
                *uptop = rgn->base;
        }
 }
-- 
2.53.0

Reply via email to