We we get around to adding blobs to a LAR from within buildROM, we have
an interesting situation, best described with an example.

For Geode we need a VSA blob to operate correctly.  BuildROM wants to
download this blob from a website, and insert it into the the LAR
with a well known name, lets use 'vsa' for giggles.

This patch allows you to specify an arbitrary filename as well as a 
pathname for files in create & add mode in the following manner:

[flags]:[filename]:[pathname]

So instead of copying the  VSA binary into a local directory and renaming
it 'vsa' before adding it o a LAR, instead we use something like this:

./lar -a my.lar ../sources/vsa.bin:vsa

This puts the blob into the LAR, and names it 'vsa'.

(the -a functionality is coming in the next patch).

Jordan
[PATCH][LAR] Allow user to specify pathnames for create and add

Add another field to the filename specified for create and add operations
to specify the intended pathname for the blob.

Signed-off-by: Jordan Crouse <[EMAIL PROTECTED]>
Index: LinuxBIOSv3/util/lar/stream.c
===================================================================
--- LinuxBIOSv3.orig/util/lar/stream.c  2007-07-11 11:48:23.000000000 -0600
+++ LinuxBIOSv3/util/lar/stream.c       2007-07-11 11:48:51.000000000 -0600
@@ -436,6 +436,8 @@
 int lar_add_file(struct lar *lar, char *name)
 {
        char *filename, *ptr, *temp;
+       char *pathname;
+
        enum compalgo thisalgo;
        struct lar_header *header;
        int offset, ret, fd, hlen;
@@ -456,6 +458,18 @@
                thisalgo = none;
        }
 
+       pathname = strchr(filename, ':');
+
+       if (pathname != NULL) {
+         *pathname = '\0';
+         pathname++;
+
+         if (!strlen(pathname)) {
+           err("Invalid pathname specified.\n");
+           return -1;
+         }
+       }
+
        if (filename[0] == '.' && filename[1] == '/')
                filename += 2;
 
@@ -508,7 +522,7 @@
        munmap(ptr, s.st_size);
        close(fd);
 
-       pathlen = strlen(filename) + 1 > MAX_PATHLEN ? MAX_PATHLEN : 
strlen(filename) + 1;
+       pathlen = strlen(pathname) + 1 > MAX_PATHLEN ? MAX_PATHLEN : 
strlen(pathname) + 1;
 
        /* Figure out how big our header will be */
        hlen = sizeof(struct lar_header) + pathlen;
@@ -535,7 +549,7 @@
 
        /* Copy the path name */
        strncpy((char *) (lar->map + offset + sizeof(struct lar_header)),
-               filename, pathlen - 1);
+               pathname, pathlen - 1);
 
        /* Copy in the data */
        memcpy(lar->map + (offset + hlen), temp, complen);
Index: LinuxBIOSv3/util/lar/lib.c
===================================================================
--- LinuxBIOSv3.orig/util/lar/lib.c     2007-07-11 11:40:29.000000000 -0600
+++ LinuxBIOSv3/util/lar/lib.c  2007-07-11 11:49:00.000000000 -0600
@@ -148,16 +148,29 @@
 {
        struct stat filestat;
        int ret = -1;
-       const char *realname;
+       char *realname;
+       char *c;
+
+       realname = strdup(name);
+
+       if (realname == NULL) {
+         fprintf(stderr, "Out of memory.\n");
+         exit(1);
+       }
 
-       realname = name;
        if (strstr(name, "nocompress:") == name) {
-               realname = name + 11;
+               realname += 11;
        }
 
+       c = strchr(realname, ':');
+
+       if (c != NULL)
+         *c = '\0';
+
        /* printf("... add_files %s\n", name); */
        if (stat(realname, &filestat) == -1) {
                fprintf(stderr, "Error getting file attributes of %s\n", name);
+               free(realname);
                return -1;
        }
 
@@ -202,6 +215,7 @@
                ret = 0;
        }
 
+       free(realname);
        return ret;
 }
 
-- 
linuxbios mailing list
[email protected]
http://www.linuxbios.org/mailman/listinfo/linuxbios

Reply via email to