This is transition code for cbfs to implement
[coreboot.git] / util / cbfstool / util.c
index 5dd946b5d7915efd595e7e230ec8c4c53c33daae..e1da4cb6fc4c1515e0cda1c206c3a9b96d162ab7 100644 (file)
 #include <sys/mman.h>
 #include "cbfstool.h"
 
+int uninitialized_flash_value = 0xff;
+
+void flashinit(void *ptr, size_t len)
+{
+       memset(ptr, uninitialized_flash_value, len);
+}
+
 int get_size(const char *size)
 {
        char *next;
@@ -151,6 +158,11 @@ int open_rom(struct rom *rom, const char *filename)
        }
 
        rom->size = ntohl(rom->header->romsize);
+       /* compute a 32-bit value of rombase. 
+        * This does the right thing on 64-bit machines. 
+        */
+       rom->rombase = 0-rom->size;
+       rom->rombase &= 0xffffffff;
        rom->fssize = rom->size - ntohl(rom->header->bootblocksize);
 
        return 0;
@@ -168,7 +180,7 @@ err:
 }
 
 int create_rom(struct rom *rom, const unsigned char *filename,
-              int romsize, const unsigned char *bootblockname,
+              int romsize, const char *bootblockname,
               int bootblocksize, int align)
 {
        unsigned char null = '\0';
@@ -203,6 +215,9 @@ int create_rom(struct rom *rom, const unsigned char *filename,
                return -1;
        }
 
+       /* mmap'ed pages are by default zero-filled. Fix that. */
+       flashinit(rom->ptr, romsize);
+
        /* This is a pointer to the header for easy access */
        rom->header = (struct cbfs_header *)
            ROM_PTR(rom, rom->size - 16 - bootblocksize - sizeof(struct cbfs_header));
@@ -212,12 +227,16 @@ int create_rom(struct rom *rom, const unsigned char *filename,
        rom->header->align = htonl(align);
        rom->header->offset = htonl(0);
 
-       add_bootblock(rom, bootblockname);
+       if (add_bootblock(rom, bootblockname) == -1)
+               return -1;
 
        /* Write the cbfs master header address at the end of the ROM. */
 
        ROM_WRITEL(rom, rom->size - 4,
                   0xFFFFFFF0 - bootblocksize - sizeof(struct cbfs_header));
+
+       /* write the empty header */
+       rom_set_header(rom, (struct cbfs_file *)rom->ptr, "", -1, CBFS_COMPONENT_NULL);
        return 0;
 }
 
@@ -226,7 +245,6 @@ int add_bootblock(struct rom *rom, const char *filename)
        unsigned int size;
        int fd = size_and_open(filename, &size);
        int ret;
-       struct cbfs_header tmp;
 
        if (fd == -1)
                return -1;