From: Christoph Niedermaier <cniedermaier@dh-electronics.com>
To: Marek Vasut <marex@denx.de>,
"u-boot@lists.denx.de" <u-boot@lists.denx.de>
Cc: NXP i.MX U-Boot Team <uboot-imx@nxp.com>,
Fabio Estevam <festevam@gmail.com>,
Stefano Babic <sbabic@denx.de>, Tom Rini <trini@konsulko.com>,
u-boot <u-boot@dh-electronics.com>
Subject: RE: [PATCH 2/2] arm64: imx8mp: Read item and serial number from EEPROM ID page on DH i.MX8MP DHCOM
Date: Fri, 25 Oct 2024 15:36:08 +0000 [thread overview]
Message-ID: <56fc53e544314a9eb63c668cb01088db@dh-electronics.com> (raw)
In-Reply-To: <c9d142f6-05ca-4fab-8016-3f545e6538d0@denx.de>
From: Marek Vasut <marex@denx.de>
Sent: Wednesday, October 23, 2024 4:05 PM
> On 10/23/24 3:20 PM, Christoph Niedermaier wrote:
>> From: Marek Vasut <marex@denx.de>
>> Sent: Wednesday, October 23, 2024 2:41 PM
>>> On 10/23/24 2:18 PM, Christoph Niedermaier wrote:
>>>
>>> [...]
>>>
>>>>> You do not, the following automatically reserves space on stack when
>>>>> called and frees it up upon function return:
>>>>>
>>>>> function foo() {
>>>>> u8 array[12];
>>>>> ...
>>>>> stuff(array);
>>>>> ...
>>>>> }
>>>>
>>>> Sorry, I expressed myself incorrectly here. Of course I meant that
>>>> I don't want to reserve memory on the stack for the EEPROM ID page
>>>> in the board_init() function.
>>>
>>> Why ?
>>
>> It's about structuring the software. I want to isolate the function which
>> is responsible for evaluate the EEPROM from the caller function. I wanted
>> to avoid entangling the two. This means that I, as the caller of the function,
>> do not have to worry about the internal structure of the EEPROM ID page.
>
> You are only passing in a block of unstructured memory allocated on
> stack, u8 block[64].
>
>>>>>> I want to handle
>>>>>> size and caching in the function dh_get_value_from_eeprom_id_page(). So I don't
>>>>>> want to deal with size and structure in the function board_init(). For me, the use
>>>>>> of a static variable is OK, but you don't like it. Do you know how I can do this
>>>>>> without assigning a static variable, but not allocate the memory somewhere in a
>>>>>> caller function?
>>>>> Even the static variable space is allocated somewhere, either in .bss or
>>>>> .data section, except with static variable(s) the memory persists
>>>>> throughout the lifetime of U-Boot because their content has to be
>>>>> retained even when the function using their content returns.
>>>>>
>>>>> With variable(s) allocated on stack (which is majority of variable), the
>>>>> memory allocation happens on entry to the function and the memory is
>>>>> automatically freed on exit from the function.
>>>>>
>>>>> It is perfectly fine to call some wrapper superfunction from
>>>>> board_init() which holds the array on stack and calls all the EEPROM
>>>>> parser/handler functions:
>>>>>
>>>>> eeprom_superwrapper() {
>>>>> u8 eeprom[64];
>>>>> ...
>>>>> eeprom_do_stuff1(eeprom);
>>>>> eeprom_do_stuff2(eeprom);
>>>>> ...
>>>>> }
>>>>>
>>>>> board_init() {
>>>>> ...
>>>>> eeprom_superwrapper();
>>>>> ...
>>>>> }
>>>>
>>>> That's not what I'm looking for. Do you have another solution?
>>> No. I do not understand what is the problem with allocating 64 Bytes on
>>> stack ?
>>
>> There is no problem with the reservation of the EEPROM buffer on the
>> stack. I wanted to isolate the evaluation function from the caller
>> function, so that I have no dependencies on the caller. Since there
>> seems to be no better solution, I will add the variable to the
>> board_init() function in V2.
> There seem to be multiple functions using the same data, so you have to
> pass pointer to those data around.
I will make a V2 with this approach, but unfortunately I can't work on
it next week. So the week after I will send V2.
Regards
Christoph
next prev parent reply other threads:[~2024-10-25 15:37 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-10 13:23 [PATCH 1/2] arm64: imx8mp: Read MAC address from M24C32-D write-lockable page on DH i.MX8MP DHCOM if available Christoph Niedermaier
2024-10-10 13:23 ` [PATCH 2/2] arm64: imx8mp: Read item and serial number from EEPROM ID page on DH i.MX8MP DHCOM Christoph Niedermaier
2024-10-12 20:55 ` Marek Vasut
2024-10-16 12:31 ` Christoph Niedermaier
2024-10-17 0:22 ` Marek Vasut
2024-10-17 11:55 ` Christoph Niedermaier
2024-10-17 18:35 ` Marek Vasut
2024-10-21 15:38 ` Christoph Niedermaier
2024-10-21 23:00 ` Marek Vasut
2024-10-22 9:31 ` Christoph Niedermaier
2024-10-22 11:57 ` Marek Vasut
2024-10-23 12:18 ` Christoph Niedermaier
2024-10-23 12:41 ` Marek Vasut
2024-10-23 13:20 ` Christoph Niedermaier
2024-10-23 14:04 ` Marek Vasut
2024-10-25 15:36 ` Christoph Niedermaier [this message]
2024-10-12 20:42 ` [PATCH 1/2] arm64: imx8mp: Read MAC address from M24C32-D write-lockable page on DH i.MX8MP DHCOM if available Marek Vasut
2024-10-16 11:57 ` Christoph Niedermaier
2024-10-16 12:15 ` Marek Vasut
2024-10-17 11:09 ` Christoph Niedermaier
2024-10-17 14:01 ` Marek Vasut
2024-10-21 15:08 ` Christoph Niedermaier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56fc53e544314a9eb63c668cb01088db@dh-electronics.com \
--to=cniedermaier@dh-electronics.com \
--cc=festevam@gmail.com \
--cc=marex@denx.de \
--cc=sbabic@denx.de \
--cc=trini@konsulko.com \
--cc=u-boot@dh-electronics.com \
--cc=u-boot@lists.denx.de \
--cc=uboot-imx@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox