[freenos] r395 committed - Modified libboot to support an ISIDLE boot_prog_t flag....

  • From: freenos@xxxxxxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Mon, 18 Oct 2010 23:31:25 +0000

Revision: 395
Author: nieklinnenbank
Date: Mon Oct 18 16:30:13 2010
Log: Modified libboot to support an ISIDLE boot_prog_t flag.
This flag may be used by the kernel such that it can recognize
the idle process from the boot image, and only schedule it when actually idleing.
Additionally the mkimage/dumpimage user programs have been modified
to support the change in libboot.

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

Modified:
 /branches/scratch/bin/dumpimage.c
 /branches/scratch/bin/mkimage.c
 /branches/scratch/lib/libboot/libboot.c
 /branches/scratch/lib/libboot/libboot.h

=======================================
--- /branches/scratch/bin/dumpimage.c   Sat Oct 16 13:09:21 2010
+++ /branches/scratch/bin/dumpimage.c   Mon Oct 18 16:30:13 2010
@@ -53,11 +53,12 @@
     while ((p = libboot_getprog()) != NULL)
     {
        printf("Cmdline: %s\r\n"
+              "Flags:   0x%x\r\n"
               "Entry:   0x%x\r\n"
               "Segments Index: %u\r\n"
               "Segments Count: %u\r\n"
               "Stack Segment Index: %u\r\n\r\n",
-               p->path, p->entry,
+               p->path, p->flags, p->entry,
                p->segments_index, p->segments_count,
                p->stack_index);

=======================================
--- /branches/scratch/bin/mkimage.c     Sat Oct 16 18:50:46 2010
+++ /branches/scratch/bin/mkimage.c     Mon Oct 18 16:30:13 2010
@@ -33,6 +33,7 @@
 {
     int i,j;
     char path[1024];
+    unsigned short flags = 0;
     program_t *program;

     /* Initialize libraries. */
@@ -52,10 +53,16 @@
            printf("libexec_read() failed: %s\r\n", libexec_error());
            continue;
        }
+       /* Look for the idle flag. */
+       if (libconfig_find(conf->root, "root:%s:isidle",
+                          conf->root->childs[i]->name))
+       {
+           flags |= BOOTPROG_ISIDLE;
+       }
        /* Add it to the boot image. */
        libboot_addprog(libconfig_find(conf->root, "root:%s:cmd",
                                       conf->root->childs[i]->name),
-                       program->entry);
+                       program->entry, flags);

         /* Add all it's memory regions. */
        for (j = 0; j < program->num_regions; j++)
@@ -65,6 +72,7 @@
                           program->regions[j].data);
        }
        libexec_free(program);
+       flags = 0;
     }
     /* Write the final image. */
     libboot_write(image_path);
=======================================
--- /branches/scratch/lib/libboot/libboot.c     Sat Oct 16 13:11:25 2010
+++ /branches/scratch/lib/libboot/libboot.c     Mon Oct 18 16:30:13 2010
@@ -103,6 +103,14 @@
     }
     return NULL;
 }
+
+void libboot_repeat_prog(void)
+{
+    if (cur_prog > 0)
+    {
+       cur_prog--;
+    }
+}

 boot_seg_t * libboot_getseg(void)
 {
@@ -124,7 +132,8 @@
     return NULL;
 }

-int libboot_addprog(char *cmd, unsigned int entry)
+int libboot_addprog(char *cmd, unsigned int entry,
+                              unsigned short flags)
 {
     /* Enlarge boot_entry_t array by one. */
     if (!(entries = realloc(entries, sizeof(boot_entry_t) *
@@ -140,6 +149,7 @@

     /* Fill the boot_prog_t. */
     snprintf(entries[num-1].prog.path, BOOTIMAGE_PATH, "%s", cmd);
+    entries[num-1].prog.flags = flags;
     entries[num-1].prog.entry = entry;

     /* Done. */
@@ -194,6 +204,10 @@
     FILE *fp;
     boot_image_t image;
     int i, j, nsegs = 0, data_off = 0;
+    char zero[BOOTIMAGE_ALIGN];
+
+    /* Initialize variables. */
+    memset(zero, 0, sizeof(zero));

     /*
      * 1) align program segments at PAGE_SIZE boundaries.
@@ -221,8 +235,9 @@
     image.seg_table_count  = total_segs;

     /* Memory segment data starts after the segment tables. */
-    data_off = image.seg_table_off +
-             (image.seg_table_count * sizeof(boot_seg_t));
+    data_off  = image.seg_table_off +
+              (image.seg_table_count * sizeof(boot_seg_t));
+    data_off += BOOTIMAGE_ALIGN - (data_off % BOOTIMAGE_ALIGN);

     /* Write header to final image. */
     if (fseek(fp, 0, SEEK_SET) != 0 ||
@@ -281,9 +296,22 @@
                fclose(fp);
                return -1;
            }
+           data_off += entries[i].segs[j].size;
+
+           /* Append NULL-bytes to enforce alignment. */
+           if (fseek(fp, data_off, SEEK_SET) != 0 ||
+               fwrite(zero, BOOTIMAGE_ALIGN - (data_off % BOOTIMAGE_ALIGN),
+                         1, fp) != 1)
+           {
+               snprintf(err_buf, sizeof(err_buf),
+                       "failed to append boot_seg_t zeroes: %s",
+                        strerror(errno));
+               fclose(fp);
+               return -1;
+           }
            /* Increment counters. */
+           data_off += BOOTIMAGE_ALIGN - (data_off % BOOTIMAGE_ALIGN);
            nsegs++;
-           data_off += entries[i].segs[j].size;
        }
     }
     /* All done. */
=======================================
--- /branches/scratch/lib/libboot/libboot.h     Sat Oct 16 13:11:25 2010
+++ /branches/scratch/lib/libboot/libboot.h     Mon Oct 18 16:30:13 2010
@@ -38,6 +38,24 @@
 /** Maximum length of the command in a BootProgram. */
 #define BOOTIMAGE_PATH         128

+/** Alignment of memory segment data. */
+#define BOOTIMAGE_ALIGN                4096
+
+/**
+ * @brief Boot Program Flags.
+ * @{
+ */
+
+/**
+ * Only schedule if no other programs are ready.
+ * One copy is started on each CPU.
+ */
+#define BOOTPROG_ISIDLE (1 << 1)
+
+/**
+ * @}
+ */
+
 /**
  * BootImage contains executable programs to be loaded at system bootup.
  */
@@ -72,6 +90,7 @@
 typedef struct boot_prog
 {
     char path[BOOTIMAGE_PATH];     /**<< Path to the program. */
+    unsigned short flags;         /**<< Flags for this boot program. */
     unsigned int entry;           /**<< Program entry point. */
     unsigned int segments_index;   /**<< Index of the program segments
                                         in the segments table. */
@@ -124,6 +143,11 @@
  */
 extern boot_prog_t * libboot_getprog(void);

+/**
+ * Indicates to repeat reading the current program.
+ */
+extern void libboot_repeat_prog(void);
+
 /**
  * Read the next memory segment for the current boot program.
  * @return Pointer to a boot_seg_t.
@@ -140,9 +164,11 @@
  * Insert a new program in the boot image for writing.
  * @param cmd Full command of the program including arguments.
  * @param entry Entry point of the program.
+ * @param flags Optional boot program flags.
  * @return Zero on success and non-zero on failure.
  */
-extern int libboot_addprog(char *cmd, unsigned int entry);
+extern int libboot_addprog(char *cmd, unsigned int entry,
+                                     unsigned short flags);

 /**
  * Add a memory region to a boot program.

Other related posts:

  • » [freenos] r395 committed - Modified libboot to support an ISIDLE boot_prog_t flag.... - freenos