On Wed,  9 Sep 2015 14:53:25 +0200
Bernhard Nortmann <bernhard.nortm...@web.de> wrote:

> FEL version information and SoC-specific memory layout are used
> across several places in the fel utility code. To avoid having
> to retrieve this information repeatedly, this patch introduces
> suitable variables to the main() function scope.
> 
> Signed-off-by: Bernhard Nortmann <bernhard.nortm...@web.de>
> ---
>  fel.c | 41 +++++++++++++++++++----------------------
>  1 file changed, 19 insertions(+), 22 deletions(-)
> 
> diff --git a/fel.c b/fel.c
> index 3fe72dc..e3566fb 100644
> --- a/fel.c
> +++ b/fel.c
> @@ -222,13 +222,10 @@ void aw_fel_get_version(libusb_device_handle *usb, 
> struct aw_fel_version *buf)
>       buf->pad[1] = le32toh(buf->pad[1]);
>  }
>  
> -void aw_fel_print_version(libusb_device_handle *usb)
> +void aw_fel_print_version(struct aw_fel_version *buf)
>  {
> -     struct aw_fel_version buf;
> -     aw_fel_get_version(usb, &buf);
> -
>       const char *soc_name="unknown";
> -     switch (buf.soc_id) {
> +     switch (buf->soc_id) {
>       case 0x1623: soc_name="A10";break;
>       case 0x1625: soc_name="A13";break;
>       case 0x1633: soc_name="A31";break;
> @@ -241,9 +238,9 @@ void aw_fel_print_version(libusb_device_handle *usb)
>       }
>  
>       printf("%.8s soc=%08x(%s) %08x ver=%04x %02x %02x scratchpad=%08x %08x 
> %08x\n",
> -             buf.signature, buf.soc_id, soc_name, buf.unknown_0a,
> -             buf.protocol, buf.unknown_12, buf.unknown_13,
> -             buf.scratchpad, buf.pad[0], buf.pad[1]);
> +             buf->signature, buf->soc_id, soc_name, buf->unknown_0a,
> +             buf->protocol, buf->unknown_12, buf->unknown_13,
> +             buf->scratchpad, buf->pad[0], buf->pad[1]);
>  }
>  
>  void aw_fel_read(libusb_device_handle *usb, uint32_t offset, void *buf, 
> size_t len)
> @@ -501,19 +498,15 @@ soc_sram_info generic_sram_info = {
>       .swap_buffers = generic_sram_swap_buffers,
>  };
>  
> -soc_sram_info *aw_fel_get_sram_info(libusb_device_handle *usb)
> +soc_sram_info *aw_fel_get_sram_info(struct aw_fel_version *buf)
>  {
>       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)
> +             if (soc_sram_info_table[i].soc_id == buf->soc_id)
>                       return &soc_sram_info_table[i];
>  
>       printf("Warning: no 'soc_sram_info' data for your SoC (id=%04X)\n",
> -            buf.soc_id);
> +            buf->soc_id);
>       return &generic_sram_info;
>  }
>  
> @@ -728,9 +721,8 @@ void aw_restore_and_enable_mmu(libusb_device_handle *usb,
>  #define SPL_LEN_LIMIT 0x8000
>  
>  void aw_fel_write_and_execute_spl(libusb_device_handle *usb,
> -                               uint8_t *buf, size_t len)
> +             soc_sram_info *sram_info, uint8_t *buf, size_t len)
>  {
> -     soc_sram_info *sram_info = aw_fel_get_sram_info(usb);
>       sram_swap_buffers *swap_buffers;
>       char header_signature[9] = { 0 };
>       size_t i, thunk_size;
> @@ -922,13 +914,13 @@ void aw_fel_write_uboot_image(libusb_device_handle *usb,
>   * This function handles the common part of both "spl" and "uboot" commands.
>   */
>  void aw_fel_process_spl_and_uboot(libusb_device_handle *usb,
> -             const char *filename)
> +             soc_sram_info *sram_info, const char *filename)
>  {
>       /* load file into memory buffer */
>       size_t size;
>       uint8_t *buf = load_file(filename, &size);
>       /* write and execute the SPL from the buffer */
> -     aw_fel_write_and_execute_spl(usb, buf, size);
> +     aw_fel_write_and_execute_spl(usb, sram_info, buf, size);
>       /* check for optional main U-Boot binary (and transfer it, if 
> applicable) */
>       if (size > SPL_LEN_LIMIT)
>               aw_fel_write_uboot_image(usb, buf + SPL_LEN_LIMIT, size - 
> SPL_LEN_LIMIT);
> @@ -1044,6 +1036,11 @@ int main(int argc, char **argv)
>               exit(1);
>       }
>  
> +     /* retrieve persistent version information and sram_info */
> +     struct aw_fel_version fel_version;
> +     aw_fel_get_version(handle, &fel_version);
> +     soc_sram_info *sram_info = aw_fel_get_sram_info(&fel_version);
> +
>
>       if (argc > 1 && (strcmp(argv[1], "--verbose") == 0 ||
>                        strcmp(argv[1], "-v") == 0)) {
>               verbose = 1;
> @@ -1064,7 +1061,7 @@ int main(int argc, char **argv)
>                       aw_fel_execute(handle, strtoul(argv[2], NULL, 0));
>                       skip=3;
>               } else if (strncmp(argv[1], "ver", 3) == 0 && argc > 1) {
> -                     aw_fel_print_version(handle);
> +                     aw_fel_print_version(&fel_version);
>                       skip=1;
>               } else if (strcmp(argv[1], "write") == 0 && argc > 3) {
>                       double t1, t2;
> @@ -1093,10 +1090,10 @@ int main(int argc, char **argv)
>                       aw_fel_fill(handle, strtoul(argv[2], NULL, 0), 
> strtoul(argv[3], NULL, 0), (unsigned char)strtoul(argv[4], NULL, 0));
>                       skip=4;
>               } else if (strcmp(argv[1], "spl") == 0 && argc > 2) {
> -                     aw_fel_process_spl_and_uboot(handle, argv[2]);
> +                     aw_fel_process_spl_and_uboot(handle, sram_info, 
> argv[2]);
>                       skip=2;
>               } else if (strcmp(argv[1], "uboot") == 0 && argc > 2) {
> -                     aw_fel_process_spl_and_uboot(handle, argv[2]);
> +                     aw_fel_process_spl_and_uboot(handle, sram_info, 
> argv[2]);
>                       uboot_autostart = (uboot_entry > 0 && uboot_size > 0);
>                       if (!uboot_autostart)
>                               printf("Warning: \"uboot\" command failed to 
> detect image! Can't execute U-Boot.\n");

With this change, we are going to print "Warning: no 'soc_sram_info'
data for your SoC" message regardless of what kind of FEL command
is requested in the command line. Simple FEL commands don't need any
SoC-specific information, so we are going to be nagging the users
of the new SoC variants.

On the other hand, maybe this is not too bad?

-- 
Best regards,
Siarhei Siamashka

-- 
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 linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to