This patch adds zero compression for bss segments.  One of the reasons
for this is that currently, if you select no compression, the bss
segment of filo takes up 153K with just zeroes.  With this patch, it
always takes up a lar header + 1 byte.  I left the one byte so that
the checksum wouldn't be broken.

This patch could have taken out the calloc in the compression area,
but since it only uses compile-time memory, I decided to keep this
simple.

I've included the results from lar -l for the four interesting cases.

Myles

Signed-off-by: Myles Watson <[EMAIL PROTECTED]>

Using lzma compression (with the patch):
  normal/payload/segment0 (152704 bytes, zeroes compressed to 1 bytes
@0x50);loadaddress 0x0x10bd80 entry 0x0x109c84
  normal/payload/segment1 (48488 bytes, lzma compressed to 28098 bytes
@0xb0);loadaddress 0x0x100000 entry 0x0x109c84
  normal/payload/segment2 (72 bytes, lzma compressed to 47 bytes
@0x6ed0);loadaddress 0x0x131200 entry 0x0x109c84
  normal/option_table (932 bytes @0x6f50);loadaddress 0x0 entry 0x0
  normal/stage2/segment0 (191792 bytes, zeroes compressed to 1 bytes
@0x7350);loadaddress 0x0xb2a0 entry 0x0x2000
  normal/stage2/segment1 (28116 bytes, lzma compressed to 15008 bytes
@0x73b0);loadaddress 0x0x2000 entry 0x0x2000
  normal/stage2/segment2 (5308 bytes, lzma compressed to 313 bytes
@0xaea0);loadaddress 0x0x9de0 entry 0x0x2000
  normal/initram/segment0 (432 bytes @0xb030);loadaddress 0x0 entry 0x0x42
  bootblock (20480 bytes @0xfb000)
Total size = 65744 bytes (0x100d0)

Using lzma compression (before the patch):
  normal/payload/segment0 (152704 bytes, lzma compressed to 105 bytes
@0x50);loadaddress 0x0x10bd80 entry 0x0x109c84
  normal/payload/segment1 (48488 bytes, lzma compressed to 28098 bytes
@0x110);loadaddress 0x0x100000 entry 0x0x109c84
  normal/payload/segment2 (72 bytes, lzma compressed to 47 bytes
@0x6f30);loadaddress 0x0x131200 entry 0x0x109c84
  normal/option_table (932 bytes @0x6fb0);loadaddress 0x0 entry 0x0
  normal/stage2/segment0 (191792 bytes, lzma compressed to 110 bytes
@0x73b0);loadaddress 0x0xb2a0 entry 0x0x2000
  normal/stage2/segment1 (28116 bytes, lzma compressed to 15006 bytes
@0x7470);loadaddress 0x0x2000 entry 0x0x2000
  normal/stage2/segment2 (5308 bytes, lzma compressed to 313 bytes
@0xaf60);loadaddress 0x0x9de0 entry 0x0x2000
  normal/initram/segment0 (432 bytes @0xb0f0);loadaddress 0x0 entry 0x0x42
  bootblock (20480 bytes @0xfb000)
Total size = 65955 bytes (0x101a3)

Using no compression (before the patch):
  normal/payload/segment0 (152704 bytes @0x50);loadaddress 0x0x10bd80
entry 0x0x109c84
  normal/payload/segment1 (48488 bytes @0x25520);loadaddress
0x0x100000 entry 0x0x109c84
  normal/payload/segment2 (72 bytes @0x312e0);loadaddress 0x0x131200
entry 0x0x109c84
  normal/option_table (932 bytes @0x31380);loadaddress 0x0 entry 0x0
  normal/stage2/segment0 (191792 bytes @0x31780);loadaddress 0x0xb2a0
entry 0x0x2000
  normal/stage2/segment1 (28116 bytes @0x60500);loadaddress 0x0x2000
entry 0x0x2000
  normal/stage2/segment2 (5308 bytes @0x67330);loadaddress 0x0x9de0
entry 0x0x2000
  normal/initram/segment0 (432 bytes @0x68840);loadaddress 0x0 entry 0x0x42
  bootblock (20480 bytes @0xfb000)
Total size = 448756 bytes (0x6d8f4)

Using no compression (after the patch):
  normal/payload/segment0 (152704 bytes, zeroes compressed to 1 bytes
@0x50);loadaddress 0x0x10bd80 entry 0x0x109c84
  normal/payload/segment1 (48488 bytes @0xb0);loadaddress 0x0x100000
entry 0x0x109c84
  normal/payload/segment2 (72 bytes @0xbe70);loadaddress 0x0x131200
entry 0x0x109c84
  normal/option_table (932 bytes @0xbf10);loadaddress 0x0 entry 0x0
  normal/stage2/segment0 (191792 bytes, zeroes compressed to 1 bytes
@0xc310);loadaddress 0x0xb2a0 entry 0x0x2000
  normal/stage2/segment1 (28116 bytes @0xc370);loadaddress 0x0x2000
entry 0x0x2000
  normal/stage2/segment2 (5308 bytes @0x131a0);loadaddress 0x0x9de0
entry 0x0x2000
  normal/initram/segment0 (432 bytes @0x146b0);loadaddress 0x0 entry 0x0x42
  bootblock (20480 bytes @0xfb000)
Total size = 104262 bytes (0x19746)
Index: include/lar.h
===================================================================
--- include/lar.h	(revision 597)
+++ include/lar.h	(working copy)
@@ -67,6 +67,7 @@
 	 * 0 = no compression
 	 * 1 = lzma
 	 * 2 = nrv2b
+	 * 3 = zeroes
 	 */
 	u32 compression;
 	u64 entry;
Index: lib/lar.c
===================================================================
--- lib/lar.c	(revision 597)
+++ lib/lar.c	(working copy)
@@ -170,6 +170,12 @@
 		return 0;
 	}
 #endif
+	/* zeroes */
+	if (archive->compression == 3) {
+		unsigned long tmp;
+		memset(archive->start, 0, archive->reallen);
+		return 0;
+	}
 	printk(BIOS_INFO, "LAR: Compression algorithm #%i not supported!\n", archive->compression);
 	return -1;
 }
Index: util/lar/lar.h
===================================================================
--- util/lar/lar.h	(revision 597)
+++ util/lar/lar.h	(working copy)
@@ -75,6 +75,7 @@
 	 * 0 = no compression
 	 * 1 = lzma
 	 * 2 = nrv2b
+	 * 3 = zeroes
 	 */
 	u32 compression;
 	u64 entry;
@@ -91,7 +92,7 @@
 	u32 size; /**< Size of the mmaped file */
 };
 
-enum compalgo { none = 0, lzma = 1, nrv2b = 2 };
+enum compalgo { none = 0, lzma = 1, nrv2b = 2, zeroes = 3 };
 
 typedef void (*compress_func) (char *, int, char *, int *);
 typedef void (*uncompress_func) (char *, int, char *, int);
@@ -100,26 +101,31 @@
 void do_no_compress(char *in, int in_len, char *out, int *out_len);
 void do_lzma_compress(char *in, int in_len, char *out, int *out_len);
 void do_nrv2b_compress(char *in, int in_len, char *out, int *out_len);
+void do_zeroes_compress(char *in, int in_len, char *out, int *out_len);
 
 void uncompress_impossible(char *dst, int dst_len, char *src, int src_len);
 void do_no_uncompress(char *dst, int dst_len, char *src, int src_len);
 void do_lzma_uncompress(char *dst, int dst_len, char *src, int src_len);
 void do_nrv2b_uncompress(char *dst, int dst_len, char *src, int src_len);
+void do_zeroes_uncompress(char *dst, int dst_len, char *src, int src_len);
 
 static compress_func compress_functions[] = {
 	do_no_compress,
 	do_lzma_compress,
 	do_nrv2b_compress,
+	do_zeroes_compress,
 };
 
 static uncompress_func uncompress_functions[] = {
 	do_no_uncompress,
 	do_lzma_uncompress,
 	do_nrv2b_uncompress,
+	do_zeroes_uncompress,
 };
 
 static const char *algo_name[] = {
 	"",
 	"lzma",
 	"nrv2b",
+	"zeroes",
 };
Index: util/lar/lib.c
===================================================================
--- util/lar/lib.c	(revision 597)
+++ util/lar/lib.c	(working copy)
@@ -57,6 +57,24 @@
 }
 
 /**
+ * The zeroes "compress" hook
+ */
+void do_zeroes_compress(char *in, int in_len, char *out, int *out_len)
+{
+	out[0] = 0;
+	out_len[0] = 1;
+}
+
+/**
+ * The zeroes "uncompress" hook
+ */
+
+void do_zeroes_uncompress(char *dst, int dst_len, char *src, int src_len)
+{
+	memset(dst, 0, dst_len);
+}
+
+/**
  * The default "uncompress" hook to call when no other compression is used
  */
 
Index: util/lar/stream.c
===================================================================
--- util/lar/stream.c	(revision 597)
+++ util/lar/stream.c	(working copy)
@@ -147,7 +147,7 @@
 				fprintf(stderr, "Dropping empty section\n");
 			continue;
 		}
-		thisalgo = algo;
+		thisalgo = zeroes;
 		if (verbose())
 			fprintf(stderr,  "New section addr %#x size %#x\n",
 			(u32)shdr[i].sh_addr, (u32)shdr[i].sh_size);
-- 
coreboot mailing list
[email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to