This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RedBoot: Auto-detection of gzipped/non-gzipped images


Hi,
 
In November 2007 I posted a patch (on the wrong mailing list) for
auto-detecting whether an image is flat or gzipped
(http://ecos.sourceware.org/ml/ecos-devel/2007-11/msg00003.html).
Recently, I imported the latest eCos to our own repository, and found
that the patch I posted back then was not in place.
So I had a hard time merging the latest and greatest with what we have
in our own repository, but finally succeeded. Here's the new patch for
flash.c followed by the required patch for the CDL file.

Regards,
Rene Schipp von Branitz Nielsen
Vitesse Semiconductors
P.S. My Copyright Assignment was transferred from eCosCentric to FSF in
December 2007.

Index: flash.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/flash.c,v
retrieving revision 1.86
diff -u -p -r1.86 flash.c
--- flash.c	29 Jan 2009 17:50:04 -0000	1.86
+++ flash.c	11 Feb 2009 10:29:34 -0000
@@ -100,6 +100,10 @@ local_cmd_entry("delete",
 static char fis_load_usage[] = 
 #ifdef CYGPRI_REDBOOT_ZLIB_FLASH
                       "[-d] "
+
+#ifdef CYGOPT_REDBOOT_ZLIB_FLASH_AUTO_DETECT
+                      "[-a] "
+#endif
 #endif
                       "[-b <memory_load_address>] [-c] name";
 
@@ -165,6 +169,7 @@ RedBoot_nested_cmd("fis", 
 cyg_flashaddr_t flash_start, flash_end;
 size_t flash_block_size;
 cyg_uint32 flash_num_blocks;
+char fis_name_of_latest_loaded_image[16];
 #ifdef CYGOPT_REDBOOT_FIS
 void *fis_work_block;
 cyg_flashaddr_t fis_addr;
@@ -1475,13 +1480,17 @@ fis_load(int argc, char *argv[])
     CYG_ADDRESS mem_addr;
     bool mem_addr_set = false;
     bool show_cksum = false;
-    struct option_info opts[3];
+    struct option_info opts[4];
 #if defined(CYGSEM_REDBOOT_FIS_CRC_CHECK)
     unsigned long cksum;
 #endif
     int num_options;
 #if defined(CYGPRI_REDBOOT_ZLIB_FLASH) ||
defined(CYGSEM_REDBOOT_FIS_CRC_CHECK)
     bool decompress = false;
+    int err = 0;
+#ifdef CYGOPT_REDBOOT_ZLIB_FLASH_AUTO_DETECT
+    bool decompress_auto_detect = false;
+#endif
 #endif
     cyg_flashaddr_t err_addr;
 
@@ -1494,6 +1503,11 @@ fis_load(int argc, char *argv[])
     init_opts(&opts[num_options], 'd', false, OPTION_ARG_TYPE_FLG, 
               (void *)&decompress, 0, "decompress");
     num_options++;
+#ifdef CYGOPT_REDBOOT_ZLIB_FLASH_AUTO_DETECT
+    init_opts(&opts[num_options], 'a', false, OPTION_ARG_TYPE_FLG, 
+              (void *)&decompress_auto_detect, 0, "auto-detect image
format");
+    num_options++;
+#endif
 #endif
 
     CYG_ASSERT(num_options <= NUM_ELEMS(opts), "Too many options");
@@ -1518,8 +1532,17 @@ fis_load(int argc, char *argv[])
     }
 #endif
 #ifdef CYGPRI_REDBOOT_ZLIB_FLASH
+#ifdef CYGOPT_REDBOOT_ZLIB_FLASH_AUTO_DETECT
     if (decompress) {
-        int err;
+        // -d takes precedence over -a
+        decompress_auto_detect = false;
+    }
+#endif
+    if (decompress
+#ifdef CYGOPT_REDBOOT_ZLIB_FLASH_AUTO_DETECT
+        || decompress_auto_detect
+#endif
+    ) {
         _pipe_t fis_load_pipe;
         _pipe_t* p = &fis_load_pipe;
         p->out_buf = (unsigned char*) mem_addr;
@@ -1535,11 +1558,22 @@ fis_load(int argc, char *argv[])
         // Free used resources, do final translation of
         // error value.
         err = (*_dc_close)(p, err);
+#ifdef CYGOPT_REDBOOT_ZLIB_FLASH_AUTO_DETECT
+        if(!decompress_auto_detect || err == 0) {
+#endif
+            if (0 != err && p->msg) {
+                diag_printf("decompression error: %s\n", p->msg);
+            } else {
+                diag_printf("Image loaded from %p-%p\n", (unsigned char
*)mem_addr, p->out_buf);
+            }
+#ifdef CYGOPT_REDBOOT_ZLIB_FLASH_AUTO_DETECT
+        }
+#endif
 
-        if (0 != err && p->msg) {
-            diag_printf("decompression error: %s\n", p->msg);
+        if(err != 0) {
+          entry_address = (unsigned long)NO_MEMORY;
         } else {
-            diag_printf("Image loaded from %p-%p\n", (unsigned char
*)mem_addr, p->out_buf);
+          entry_address = (unsigned long)img->entry_point;
         }
 
         // Set load address/top
@@ -1548,8 +1582,13 @@ fis_load(int argc, char *argv[])
 
         // Reload fis directory
         fis_read_directory();
+#ifdef CYGOPT_REDBOOT_ZLIB_FLASH_AUTO_DETECT
+    }
+    if(!decompress && (!decompress_auto_detect || err != 0))
+#else
     } else // dangling block
 #endif
+#endif // CYGPRI_REDBOOT_ZLIB_FLASH
     {
         cyg_flash_read(img->flash_base, (void *)mem_addr,
img->data_length, 
                        &err_addr);
@@ -1557,8 +1596,8 @@ fis_load(int argc, char *argv[])
         // Set load address/top
         load_address = mem_addr;
         load_address_end = mem_addr + img->data_length;
+        entry_address = (unsigned long)img->entry_point;
     }
-    entry_address = (unsigned long)img->entry_point;
 
 #ifdef CYGSEM_REDBOOT_FIS_CRC_CHECK
     cksum = cyg_crc32((unsigned char *)mem_addr, img->data_length);
@@ -1566,7 +1605,11 @@ fis_load(int argc, char *argv[])
         diag_printf("Checksum: 0x%08lx\n", cksum);
     }
     // When decompressing, leave CRC checking to decompressor
-    if (!decompress && img->file_cksum) {
+    if ((!decompress
+#ifdef CYGOPT_REDBOOT_ZLIB_FLASH_AUTO_DETECT    
+    && (!decompress_auto_detect || err)
+#endif
+    ) && img->file_cksum) {
         if (cksum != img->file_cksum) {
             diag_printf("** Warning - checksum failure.  stored:
0x%08lx, computed: 0x%08lx\n",
                         img->file_cksum, cksum);
@@ -1574,6 +1617,12 @@ fis_load(int argc, char *argv[])
         }
     }
 #endif
+    // Used in hal_if.c
+    if(entry_address == (unsigned long)NO_MEMORY) {
+        fis_name_of_latest_loaded_image[0] = '\0';
+    } else {
+        strcpy(fis_name_of_latest_loaded_image, name); // name is
guaranteed to be within 16 bytes, since fis_lookup() would otherwise
fail
+    }
 }
 #endif // CYGOPT_REDBOOT_FIS
 
Index: redboot.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/cdl/redboot.cdl,v
retrieving revision 1.83
diff -r1.83 redboot.cdl
227a228,242
> 
>             cdl_option CYGOPT_REDBOOT_ZLIB_FLASH_AUTO_DETECT {
>                  display       "Support auto-detection of compressed
images"
>                  active_if     CYGPKG_REDBOOT_FLASH
>                  active_if     !CYGSEM_IO_FLASH_READ_INDIRECT
>                  flavor        bool
>                  default_value 0
>                  description   "
>                         Enable this option to support the -a option
with
>                         the fis load command. When using the -a
option,
>                         first a gzip/zlib decompression will be
attempted.
>                         If that one fails, a simple copy of the image
to
>                         RAM will be performed.
>                         Only used if CYGPRI_REDBOOT_ZLIB_FLASH is
active."
>             }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]