This patch makes lar -l print a total of the bytes used in an archive.
 I did it because I wanted to know the differences between preparsing
elf files and compressing the pieces.  Here is the output from a few
of them:

Coreboot v3 with filo.elf added using lar -a

  normal/option_table (932 bytes @0x50);loadaddress 0x0 entry 0x0
  normal/stage2/segment0 (191792 bytes, lzma compressed to 110 bytes
@0x450);loadaddress 0x0xa1c0 entry 0x0x2000
  normal/stage2/segment1 (28084 bytes, lzma compressed to 14976 bytes
@0x510);loadaddress 0x0x2000 entry 0x0x2000
  normal/stage2/segment2 (4540 bytes, lzma compressed to 316 bytes
@0x3fe0);loadaddress 0x0x9000 entry 0x0x2000
  normal/initram/segment0 (432 bytes @0x4170);loadaddress 0x0 entry 0x0x42
  normal/payload (77840 bytes @0x4360);loadaddress 0x0 entry 0x0
  bootblock (20480 bytes @0xfb000)
Total size = 115422 bytes (0x1c2de)

Coreboot v3 with filo.elf.lzma added using lar -a

  normal/option_table (932 bytes @0x50);loadaddress 0x0 entry 0x0
  normal/stage2/segment0 (191792 bytes, lzma compressed to 110 bytes
@0x450);loadaddress 0x0xa1c0 entry 0x0x2000
  normal/stage2/segment1 (28084 bytes, lzma compressed to 14976 bytes
@0x510);loadaddress 0x0x2000 entry 0x0x2000
  normal/stage2/segment2 (4540 bytes, lzma compressed to 316 bytes
@0x3fe0);loadaddress 0x0x9000 entry 0x0x2000
  normal/initram/segment0 (432 bytes @0x4170);loadaddress 0x0 entry 0x0x42
  normal/payload (42791 bytes @0x4360);loadaddress 0x0 entry 0x0
  bootblock (20480 bytes @0xfb000)
Total size = 80373 bytes (0x139f5)

Coreboot v3 with filo.elf added using lar -ae

  normal/option_table (932 bytes @0x50);loadaddress 0x0 entry 0x0
  normal/stage2/segment0 (191792 bytes, lzma compressed to 110 bytes
@0x450);loadaddress 0x0xa1c0 entry 0x0x2000
  normal/stage2/segment1 (28084 bytes, lzma compressed to 14976 bytes
@0x510);loadaddress 0x0x2000 entry 0x0x2000
  normal/stage2/segment2 (4540 bytes, lzma compressed to 316 bytes
@0x3fe0);loadaddress 0x0x9000 entry 0x0x2000
  normal/initram/segment0 (432 bytes @0x4170);loadaddress 0x0 entry 0x0x42
  normal/payload/segment0 (172032 bytes @0x4370);loadaddress
0x0x112d60 entry 0x0x10e51c
  normal/payload/segment1 (77128 bytes @0x2e3c0);loadaddress
0x0x100000 entry 0x0x10e51c
  normal/payload/segment2 (72 bytes @0x41160);loadaddress 0x0x13cd60
entry 0x0x10e51c
  bootblock (20480 bytes @0xfb000)
Total size = 286910 bytes (0x460be)

Coreboot v3 with filo.elf added using lar -ae -C lzma

  normal/option_table (932 bytes @0x50);loadaddress 0x0 entry 0x0
  normal/stage2/segment0 (191792 bytes, lzma compressed to 110 bytes
@0x450);loadaddress 0x0xa1c0 entry 0x0x2000
  normal/stage2/segment1 (28084 bytes, lzma compressed to 14976 bytes
@0x510);loadaddress 0x0x2000 entry 0x0x2000
  normal/stage2/segment2 (4540 bytes, lzma compressed to 316 bytes
@0x3fe0);loadaddress 0x0x9000 entry 0x0x2000
  normal/initram/segment0 (432 bytes @0x4170);loadaddress 0x0 entry 0x0x42
  normal/payload/segment0 (172032 bytes, lzma compressed to 108 bytes
@0x4370);loadaddress 0x0x112d60 entry 0x0x10e51c
  normal/payload/segment1 (77128 bytes, lzma compressed to 42548 bytes
@0x4430);loadaddress 0x0x100000 entry 0x0x10e51c
  normal/payload/segment2 (72 bytes, lzma compressed to 47 bytes
@0xeac0);loadaddress 0x0x13cd60 entry 0x0x10e51c
  bootblock (20480 bytes @0xfb000)
Total size = 80381 bytes (0x139fd)

I'm not sure I counted everything right, but I think this is a feature
that lar ought to have (space left in the archive is just as good for
me.)

Signed-off-by: Myles Watson <[EMAIL PROTECTED]>
Index: svn/util/lar/stream.c
===================================================================
--- svn/util/lar/stream.c	(revision 587)
+++ svn/util/lar/stream.c	(working copy)
@@ -545,6 +545,7 @@
 void lar_list_files(struct lar *lar, struct file *files)
 {
 	u8 *ptr = lar->map;
+	u32 total_size = 0;
 	char *filename;
 
 	struct lar_header *header;
@@ -553,12 +554,13 @@
 	while (ptr < (lar->map + get_bootblock_offset(lar->size))) {
 		header = (struct lar_header *) ptr;
 
-		/* We interpet the absence of the magic as empty space */
+		/* We interpret the absence of the magic as empty space */
 
 		if (strncmp(header->magic, MAGIC, 8))
 			break;
 
 		filename = (char *) (ptr + sizeof(struct lar_header));
+		total_size += sizeof(struct lar_header);
 
 		if (file_in_list(files, filename)) {
 			printf("  %s ", filename);
@@ -568,6 +570,7 @@
 				       ntohl(header->len),
 				       (unsigned long)(ptr - lar->map) +
 				       ntohl(header->offset));
+				total_size += ntohl(header->len);
 			} else {
 				printf("(%d bytes, %s compressed to %d bytes "
 				       "@0x%lx);",
@@ -576,6 +579,7 @@
 				       ntohl(header->len),
 				       (unsigned long)(ptr - lar->map) +
 				       ntohl(header->offset));
+				total_size += ntohl(header->len);
 			}
 			printf("loadaddress 0x%#x entry 0x%#x\n", 
 					ntohl(header->loadaddress), 
@@ -595,7 +599,12 @@
 		       ntohl(header->len),
 		       get_bootblock_offset(lar->size) +
 		       ntohl(header->offset));
+		total_size += sizeof(struct lar_header) + ntohl(header->len);
 	}
+
+	/* Print the total size */
+	printf ("Total size = %d bytes (0x%x)\n", total_size, total_size);
+	
 }
 
 /**
-- 
coreboot mailing list
[email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to