[freenos] r387 committed - Implemented libboot_getseg() in libboot. Fixed segment_index/count in ...

  • From: freenos@xxxxxxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Sat, 16 Oct 2010 20:14:03 +0000

Revision: 387
Author: nieklinnenbank
Date: Sat Oct 16 13:11:25 2010
Log: Implemented libboot_getseg() in libboot. Fixed segment_index/count in boot_prog_t entries.

http://code.google.com/p/freenos/source/detail?r=387

Modified:
 /branches/scratch/lib/libboot/libboot.c
 /branches/scratch/lib/libboot/libboot.h

=======================================
--- /branches/scratch/lib/libboot/libboot.c     Sat Oct 16 11:27:36 2010
+++ /branches/scratch/lib/libboot/libboot.c     Sat Oct 16 13:11:25 2010
@@ -94,17 +94,28 @@
 boot_prog_t * libboot_getprog(void)
 {
     unsigned char *img = (unsigned char *) image;
-    boot_prog_t *p = (boot_prog_t *) (img + (image->prog_table_off));
+    unsigned char *tab = (img + (image->prog_table_off));

     if (cur_prog < image->prog_table_count)
     {
-       return p + cur_prog++;
+       cur_seg = 0;
+       return ((boot_prog_t *) (tab)) + cur_prog++;
     }
     return NULL;
 }

 boot_seg_t * libboot_getseg(void)
 {
+    unsigned char *img  = (unsigned char *) image;
+    unsigned char *ptab = (img + (image->prog_table_off));
+    unsigned char *stab = (img + (image->seg_table_off));
+    boot_prog_t *p = ((boot_prog_t *) ptab) + (cur_prog - 1);
+
+    if (cur_seg < p->segments_count &&
+        cur_seg + p->segments_count < image->seg_table_count)
+    {
+       return ((boot_seg_t *) (stab)) + (p->segments_index + cur_seg++);
+    }
     return NULL;
 }

@@ -228,9 +239,27 @@
      */
     for (i = 0; i < num; i++)
     {
+       /* Update boot program entry. */
+       entries[i].prog.segments_index = nsegs;
+       entries[i].prog.segments_count = entries[i].num_segs;
+
+        /* Write the boot program table entry. */
+        if (fseek(fp, image.prog_table_off +
+                 (i * sizeof(boot_prog_t)), SEEK_SET) != 0 ||
+            fwrite(&entries[i].prog, sizeof(boot_prog_t), 1, fp) != 1)
+        {
+            snprintf(err_buf, sizeof(err_buf),
+                    "failed to write to boot_prog_t: %s",
+                     strerror(errno));
+           fclose(fp);
+            return -1;
+        }
        /* Loop program memory segments. */
        for (j = 0; j < entries[i].num_segs; j++)
        {
+           /* Update segment table entry. */
+           entries[i].segs[j].offset = data_off;
+
            /* Write segment table entry. */
            if (fseek(fp, image.seg_table_off +
                         (nsegs * sizeof(boot_seg_t)), SEEK_SET) != 0 ||
@@ -256,17 +285,6 @@
            nsegs++;
            data_off += entries[i].segs[j].size;
        }
-        /* Write the boot program table entry. */
-        if (fseek(fp, image.prog_table_off +
-                 (i * sizeof(boot_prog_t)), SEEK_SET) != 0 ||
-            fwrite(&entries[i].prog, sizeof(boot_prog_t), 1, fp) != 1)
-        {
-            snprintf(err_buf, sizeof(err_buf),
-                    "failed to write to boot_prog_t: %s",
-                     strerror(errno));
-           fclose(fp);
-            return -1;
-        }
     }
     /* All done. */
     fclose(fp);
=======================================
--- /branches/scratch/lib/libboot/libboot.h     Sat Oct 16 07:12:37 2010
+++ /branches/scratch/lib/libboot/libboot.h     Sat Oct 16 13:11:25 2010
@@ -46,11 +46,11 @@
unsigned int magic[2]; /**<< Magic numbers to detect a valid boot image. */ unsigned char revision; /**<< Version of the boot image layout. */ unsigned int checksum; /**<< Checksum used to verify integrity. */ - unsigned int var_table_off; /**<< Offset of the variables table. */ + unsigned int var_table_off; /**<< Offset of the variables table in bytes. */ unsigned short var_table_count; /**<< Number of entries in the variables table. */
-    unsigned int   prog_table_off;   /**<< Offset of the programs table. */
+ unsigned int prog_table_off; /**<< Offset of the programs table in bytes. */ unsigned short prog_table_count; /**<< Number of entries in the programs table. */
-    unsigned int   seg_table_off;    /**<< Offset of the segments table. */
+ unsigned int seg_table_off; /**<< Offset of the segments table in bytes. */ unsigned short seg_table_count; /**<< Number of entries in the segments table. */
 }
 boot_image_t;
@@ -73,11 +73,11 @@
 {
     char path[BOOTIMAGE_PATH];     /**<< Path to the program. */
     unsigned int entry;           /**<< Program entry point. */
-    unsigned int segments_off;     /**<< Offset of the program segments
+    unsigned int segments_index;   /**<< Index of the program segments
                                         in the segments table. */
     unsigned short segments_count; /**<< Number of contiguous entries
                                         in the segment table, including stack. 
*/
-    unsigned int stack_off;       /**<< Offset of the program stack segment
+    unsigned int stack_index;     /**<< Index of the program stack segment
                                          also in the segments table. */
 }
 boot_prog_t;

Other related posts:

  • » [freenos] r387 committed - Implemented libboot_getseg() in libboot. Fixed segment_index/count in ... - freenos