-static void
-print_header (image_header_t *hdr)
-{
- time_t timestamp;
- uint32_t size;
-
- timestamp = (time_t)image_get_time (hdr);
- size = image_get_data_size (hdr);
-
- printf ("Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr));
- printf ("Created: %s", ctime(×tamp));
- printf ("Image Type: "); print_type(hdr);
- printf ("Data Size: %d Bytes = %.2f kB = %.2f MB\n",
- size, (double)size / 1.024e3, (double)size / 1.048576e6 );
- printf ("Load Address: 0x%08X\n", image_get_load (hdr));
- printf ("Entry Point: 0x%08X\n", image_get_ep (hdr));
-
- if (image_check_type (hdr, IH_TYPE_MULTI) ||
- image_check_type (hdr, IH_TYPE_SCRIPT)) {
- int i, ptrs;
- uint32_t pos;
- uint32_t *len_ptr = (uint32_t *) (
- (unsigned long)hdr + image_get_header_size ()
- );
-
- /* determine number of images first (to calculate image offsets) */
- for (i=0; len_ptr[i]; ++i) /* null pointer terminates list */
- ;
- ptrs = i; /* null pointer terminates list */
-
- pos = image_get_header_size () + ptrs * sizeof(long);
- printf ("Contents:\n");
- for (i=0; len_ptr[i]; ++i) {
- size = uimage_to_cpu (len_ptr[i]);
-
- printf (" Image %d: %8d Bytes = %4d kB = %d MB\n",
- i, size, size>>10, size>>20);
- if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) {
- /*
- * the user may need to know offsets
- * if planning to do something with
- * multiple files
- */
- printf (" Offset = %08X\n", pos);
- }
- /* copy_file() will pad the first files to even word align */
- size += 3;
- size &= ~3;
- pos += size;
- }
- }
-}
-
-
-static void
-print_type (image_header_t *hdr)
-{
- printf ("%s %s %s (%s)\n",
- put_arch (image_get_arch (hdr)),
- put_os (image_get_os (hdr)),
- put_type (image_get_type (hdr)),
- put_comp (image_get_comp (hdr))
- );
-}
-
-static char *put_arch (int arch)
-{
- return (put_table_entry(arch_name, "Unknown Architecture", arch));
-}
-
-static char *put_os (int os)
-{
- return (put_table_entry(os_name, "Unknown OS", os));
-}
-
-static char *put_type (int type)
-{
- return (put_table_entry(type_name, "Unknown Image", type));
-}
-
-static char *put_comp (int comp)
-{
- return (put_table_entry(comp_name, "Unknown Compression", comp));
-}
-
-static char *put_table_entry (table_entry_t *table, char *msg, int type)
-{
- for (; table->val>=0; ++table) {
- if (table->val == type)
- return (table->lname);
- }
- return (msg);
-}
-
-static int get_arch(char *name)
-{
- return (get_table_entry(arch_name, "CPU", name));
-}
-
-
-static int get_comp(char *name)
-{
- return (get_table_entry(comp_name, "Compression", name));
-}
-
-
-static int get_os (char *name)
-{
- return (get_table_entry(os_name, "OS", name));
-}
-
-
-static int get_type(char *name)
-{
- return (get_table_entry(type_name, "Image", name));
-}
-
-static int get_table_entry (table_entry_t *table, char *msg, char *name)
-{
- table_entry_t *t;
- int first = 1;
-
- for (t=table; t->val>=0; ++t) {
- if (t->sname && strcasecmp(t->sname, name)==0)
- return (t->val);
- }
- fprintf (stderr, "\nInvalid %s Type - valid names are", msg);
- for (t=table; t->val>=0; ++t) {
- if (t->sname == NULL)
- continue;
- fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
- first = 0;
- }
- fprintf (stderr, "\n");
- return (-1);