Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 78782C6FA83 for ; Mon, 12 Sep 2022 18:56:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 291BE84A73; Mon, 12 Sep 2022 20:56:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="LsHagMNg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B4CF384A71; Mon, 12 Sep 2022 20:56:17 +0200 (CEST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9844C84A73 for ; Mon, 12 Sep 2022 20:56:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0419361234; Mon, 12 Sep 2022 18:56:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A5D2C433C1; Mon, 12 Sep 2022 18:56:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663008972; bh=YICmIMEmNj7JDjGTPYPCoqrxPJXKJMbXlYrETM4L3TE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LsHagMNgeWFXm85ntbm+e9VZWEd97tx6DfxzrOIUAsMiXyEUtLtfiPz2qMiYhVXfb D+9uEGjmIvukzvWL1cf2SVN/tgYVzHgsDlr/nHNd/3VkG0Xy7dv0ND6PQ6o83CSWp0 QVKrrUvDd2pX4g3hIlmzisz5aYWIGc4hw7sgEkvSIByP64RPDfu3+tVW/gpKTJ/gYM LlXWMfivX64dxUMViSUAiwmSm6fqM6qVP0X1Cm1ZAeAEv0Ch3vnDz18nIRuUDviDQF a41iNJflsacK4xL3iBk4nKxZVXYziWBOTRq5Mm7e1+bqH3o4izN5AJPz+6hg5hTixT dWHYrtHzYjUMQ== Received: by pali.im (Postfix) id 004C811D3; Mon, 12 Sep 2022 20:56:08 +0200 (CEST) Date: Mon, 12 Sep 2022 20:56:08 +0200 From: Pali =?utf-8?B?Um9ow6Fy?= To: Simon Glass Cc: U-Boot Mailing List Subject: Re: [PATCH] board_f: show_dram_config: Print also real DRAM size Message-ID: <20220912185608.xenntthnl64xej3r@pali> References: <20220911093942.9570-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On Monday 12 September 2022 07:34:47 Simon Glass wrote: > Hi Pali, > > On Sun, 11 Sept 2022 at 03:39, Pali Rohár wrote: > > > > 32-bit U-Boot builds cannot use more than around 2 GB of DDR memory. But on > > some platforms/boards it is possible to connect also 4 GB SODIMM DDR memory. > > U-Boot currently prints only effective size of RAM which can use, which may > > be misleading as somebody would expect that this line prints total size of > > connected DDR modules. So change show_dram_config code to prints both real > > and effective DRAM size if they are different. If they are same then print > > just one number like before. It is possible that effective size is just few > > bytes smaller than the real size, so print both numbers only in case > > function print_size() prints formats them differently. > > > > Signed-off-by: Pali Rohár > > --- > > common/board_f.c | 31 ++++++++++++++++++++++++++++++- > > 1 file changed, 30 insertions(+), 1 deletion(-) > > > > diff --git a/common/board_f.c b/common/board_f.c > > index 9e34fbee147e..3131a06db940 100644 > > --- a/common/board_f.c > > +++ b/common/board_f.c > > @@ -54,6 +54,7 @@ > > #include > > #include > > #include > > +#include > > > > /* > > * Pointer to initial global data area > > @@ -213,6 +214,30 @@ static int announce_dram_init(void) > > return 0; > > } > > > > +/* > > + * Check if the sizes in their natural units written in decimal format with > > + * one fraction number are same. > > + */ > > +static int sizes_near(unsigned long long size1, unsigned long long size2) > > +{ > > + unsigned int size1_scale = ilog2(size1) / 10 * 10; > > + unsigned int size1_val = (10 * size1 + ((1ULL << size1_scale) >> 1)) >> size1_scale; > > + unsigned int size2_scale = ilog2(size2) / 10 * 10; > > + unsigned int size2_val = (10 * size2 + ((1ULL << size2_scale) >> 1)) >> size2_scale; > > Can you put that expression into a function with a comment, etc.? It > is a bit hard to understand. Ok. > > + > > + if (size1_val == 10240) { > > + size1_val = 10; > > + size1_scale += 10; > > + } > > + > > + if (size2_val == 10240) { > > + size2_val = 10; > > + size2_scale += 10; > > + } > > If you are doing the same thing to each, why bother? It should not > affect the expression below, should it? : This is interesting question, and the answer it that it is required and affects comparison expression below. For example for the case when size1 is below 1GB limit, size2 is above 1GB limit and both values are near. Imagine that size1 is approaching value 1GB from the left and size2 from the right side. > > + > > + return size1_scale == size2_scale && size1_val == size2_val; > > +} > > + > > static int show_dram_config(void) > > { > > unsigned long long size; > > @@ -229,7 +254,11 @@ static int show_dram_config(void) > > } > > debug("\nDRAM: "); > > > > - print_size(size, ""); > > + print_size(gd->ram_size, ""); > > + if (!sizes_near(gd->ram_size, size)) { > > + printf(" (effective "); > > + print_size(size, ")"); > > + } > > board_add_ram_info(0); > > putc('\n'); > > > > -- > > 2.20.1 > > > > Can we make this testable somehow? You could put the new code into a > lib/ function, perhaps, and call it from a C unit test in test/lib ? > > Regards, > Simon Meh... I do not know how to test such code. Due to size / optimization requirements it is not a good idea to make function outside of board_f.c file.