Information about the SoC-specific memory layout may be required across several places in the fel utility code. To avoid having to retrieve this information repeatedly, this patch modifies the aw_fel_get_sram_info() function to cache its result (via an internal static pointer).
This makes it safe to call aw_fel_get_sram_info() wherever needed, while avoiding additional aw_fel_get_version() lookups, and potential surplus "no 'soc_sram_info' data for your SoC" warnings. Signed-off-by: Bernhard Nortmann <[email protected]> --- fel.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/fel.c b/fel.c index 52b785f..71d56c3 100644 --- a/fel.c +++ b/fel.c @@ -503,18 +503,27 @@ soc_sram_info generic_sram_info = { soc_sram_info *aw_fel_get_sram_info(libusb_device_handle *usb) { - int i; - struct aw_fel_version buf; - - aw_fel_get_version(usb, &buf); - - for (i = 0; soc_sram_info_table[i].swap_buffers; i++) - if (soc_sram_info_table[i].soc_id == buf.soc_id) - return &soc_sram_info_table[i]; + /* persistent sram_info, retrieves result pointer once and caches it */ + static soc_sram_info *result = NULL; + if (result == NULL) { + int i; + + struct aw_fel_version buf; + aw_fel_get_version(usb, &buf); + + for (i = 0; soc_sram_info_table[i].swap_buffers; i++) + if (soc_sram_info_table[i].soc_id == buf.soc_id) { + result = &soc_sram_info_table[i]; + break; + } - printf("Warning: no 'soc_sram_info' data for your SoC (id=%04X)\n", - buf.soc_id); - return &generic_sram_info; + if (!result) { + printf("Warning: no 'soc_sram_info' data for your SoC (id=%04X)\n", + buf.soc_id); + result = &generic_sram_info; + } + } + return result; } static uint32_t fel_to_spl_thunk[] = { -- 2.4.6 -- You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
