Skip to contentSkip to conversation

easylogo: add lzma support

PATCH New Mike Frysinger 3 participants 7 messages Feb 4, 2012 – Jun 19, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 easylogo: add lzma support

Compressing the logos with lzma rather than gzip saves ~9kb with the Blackfin 24bit images and ~3kb with the 16bit images.

Add a new -l option to easylogo so people can pick lzma as their decompression routine.

---
 tools/easylogo/easylogo.c |   85 +++++++++++++++++++++++++++++---------------
 1 files changed, 56 insertions(+), 29 deletions(-)
tools/easylogo/easylogo.c +56 -29
index d9b33fa..4ba86bf 100644
@@ -305,7 +305,13 @@ int image_rgb888_to_rgb565(image_t *rgb888_image, image_t *rgb565_image)
 	return 0;
 }
 
-int use_gzip = 0;
+enum comp_t {
+	COMP_NONE,
+	COMP_GZIP,
+	COMP_LZMA,
+};
+static enum comp_t compression = COMP_NONE;
+static bool bss_storage = false;
 
 int image_save_header (image_t * image, char *filename, char *varname)
 {
@@ -329,58 +335,74 @@ int image_save_header (image_t * image, char *filename, char *varname)
 	fprintf (file, " *\t\t'x'\t\tis the horizontal position\n");
 	fprintf (file, " *\t\t'y'\t\tis the vertical position\n */\n\n");
 
-	/*  gzip compress */
-	if (use_gzip & 0x1) {
+	/* image compress */
+	if (compression != COMP_NONE) {
 		const char *errstr = NULL;
 		unsigned char *compressed;
+		const char *comp_name;
 		struct stat st;
-		FILE *gz;
-		char *gzfilename = xmalloc(strlen (filename) + 20);
-		char *gzcmd = xmalloc(strlen (filename) + 20);
-
-		sprintf (gzfilename, "%s.gz", filename);
-		sprintf (gzcmd, "gzip > %s", gzfilename);
-		gz = popen (gzcmd, "w");
-		if (!gz) {
+		FILE *compfp;
+		size_t filename_len = strlen(filename);
+		char *compfilename = xmalloc(filename_len + 20);
+		char *compcmd = xmalloc(filename_len + 50);
+
+		sprintf(compfilename, "%s.bin", filename);
+		switch (compression) {
+		case COMP_GZIP:
+			strcpy(compcmd, "gzip");
+			comp_name = "GZIP";
+			break;
+		case COMP_LZMA:
+			strcpy(compcmd, "lzma");
+			comp_name = "LZMA";
+			break;
+		default:
+			errstr = "\nerror: unknown compression method";
+			goto done;
+		}
+		strcat(compcmd, " > ");
+		strcat(compcmd, compfilename);
+		compfp = popen(compcmd, "w");
+		if (!compfp) {
 			errstr = "\nerror: popen() failed";
 			goto done;
 		}
-		if (fwrite (image->data, image->size, 1, gz) != 1) {
+		if (fwrite(image->data, image->size, 1, compfp) != 1) {
 			errstr = "\nerror: writing data to gzip failed";
 			goto done;
 		}
-		if (pclose (gz)) {
+		if (pclose(compfp)) {
 			errstr = "\nerror: gzip process failed";
 			goto done;
 		}
 
-		gz = fopen (gzfilename, "r");
-		if (!gz) {
+		compfp = fopen(compfilename, "r");
+		if (!compfp) {
 			errstr = "\nerror: open() on gzip data failed";
 			goto done;
 		}
-		if (stat (gzfilename, &st)) {
+		if (stat(compfilename, &st)) {
 			errstr = "\nerror: stat() on gzip file failed";
 			goto done;
 		}
-		compressed = xmalloc (st.st_size);
-		if (fread (compressed, st.st_size, 1, gz) != 1) {
+		compressed = xmalloc(st.st_size);
+		if (fread(compressed, st.st_size, 1, compfp) != 1) {
 			errstr = "\nerror: reading gzip data failed";
 			goto done;
 		}
-		fclose (gz);
+		fclose(compfp);
 
-		unlink (gzfilename);
+		unlink(compfilename);
 
 		dataptr = compressed;
 		count = st.st_size;
-		fprintf (file, "#define EASYLOGO_ENABLE_GZIP %i\n\n", count);
-		if (use_gzip & 0x2)
+		fprintf(file, "#define EASYLOGO_ENABLE_%s %i\n\n", comp_name, count);
+		if (bss_storage)
 			fprintf (file, "static unsigned char EASYLOGO_DECOMP_BUFFER[%i];\n\n", image->size);
 
  done:
-		free (gzfilename);
-		free (gzcmd);
+		free(compfilename);
+		free(compcmd);
 
 		if (errstr) {
 			perror (errstr);
@@ -466,6 +488,7 @@ static void usage (int exit_status)
 		"  -r     Output RGB888 instead of YUYV\n"
 		"  -s     Output RGB565 instead of YUYV\n"
 		"  -g     Compress with gzip\n"
+		"  -l     Compress with lzma\n"
 		"  -b     Preallocate space in bss for decompressing image\n"
 		"  -h     Help output\n"
 		"\n"
@@ -486,7 +509,7 @@ int main (int argc, char *argv[])
 
 	image_t rgb888_logo, rgb565_logo, yuyv_logo;
 
-	while ((c = getopt(argc, argv, "hrsgb")) > 0) {
+	while ((c = getopt(argc, argv, "hrsglb")) > 0) {
 		switch (c) {
 		case 'h':
 			usage (0);
@@ -500,12 +523,16 @@ int main (int argc, char *argv[])
 			puts("Using 16-bit RGB565 Output Fromat");
 			break;
 		case 'g':
-			use_gzip |= 0x1;
-			puts ("Compressing with gzip");
+			compression = COMP_GZIP;
+			puts("Compressing with gzip");
+			break;
+		case 'l':
+			compression = COMP_LZMA;
+			puts("Compressing with lzma");
 			break;
 		case 'b':
-			use_gzip |= 0x2;
-			puts ("Preallocating bss space for decompressing image");
+			bss_storage = true;
+			puts("Preallocating bss space for decompressing image");
 			break;
 		default:
 			usage (1);
Signature · 1 line
1.7.8.4
#1 lore raw

PATCH 2/2 Blackfin: easylogo: add lzma logos

The bf527-ezkit boards are getting too big to fit into their reserved flash space, so we need to use a lzma compressed logo.

Since the video driver code is very similar, add lzma compressed support to all of the Blackfin video drivers.

---
 ...fin_logo_230x230.h => bfin_logo_230x230_gzip.h} |    0
 arch/blackfin/include/asm/bfin_logo_230x230_lzma.h | 1819 ++++++++++++++++++++
 ...5_230x230.h => bfin_logo_rgb565_230x230_gzip.h} |    0
 .../include/asm/bfin_logo_rgb565_230x230_lzma.h    | 1079 ++++++++++++
 board/bf527-ezkit/video.c                          |   30 +-
 board/bf548-ezkit/video.c                          |   22 +-
 board/cm-bf548/video.c                             |   25 +-
 include/configs/bf527-ezkit.h                      |    9 +
 include/configs/bf548-ezkit.h                      |    1 +
 include/configs/cm-bf548.h                         |    1 +
 10 files changed, 2964 insertions(+), 22 deletions(-)
 rename arch/blackfin/include/asm/{bfin_logo_230x230.h => bfin_logo_230x230_gzip.h} (100%)
 create mode 100644 arch/blackfin/include/asm/bfin_logo_230x230_lzma.h
 rename arch/blackfin/include/asm/{bfin_logo_rgb565_230x230.h => bfin_logo_rgb565_230x230_gzip.h} (100%)
 create mode 100644 arch/blackfin/include/asm/bfin_logo_rgb565_230x230_lzma.h
arch/blackfin/include/asm/bfin_logo_230x230_gzip.h renamed from arch/blackfin/include/asm/bfin_logo_230x230.h +0 -0
similarity index 100%
rename from arch/blackfin/include/asm/bfin_logo_230x230.h
rename to arch/blackfin/include/asm/bfin_logo_230x230_gzip.h
arch/blackfin/include/asm/bfin_logo_230x230_lzma.h new file +1819 -0

1,819 lines not on this page · raw message

arch/blackfin/include/asm/bfin_logo_rgb565_230x230_gzip.h renamed from arch/blackfin/include/asm/bfin_logo_rgb565_230x230.h +0 -0
similarity index 100%
rename from arch/blackfin/include/asm/bfin_logo_rgb565_230x230.h
rename to arch/blackfin/include/asm/bfin_logo_rgb565_230x230_gzip.h
arch/blackfin/include/asm/bfin_logo_rgb565_230x230_lzma.h new file +1079 -0

1,079 lines not on this page · raw message

board/bf527-ezkit/video.c +19 -11
index ca5e9b0..5d8a091 100644
@@ -17,6 +17,10 @@
 #include <linux/types.h>
 #include <stdio_dev.h>
 
+#include <lzma/LzmaTypes.h>
+#include <lzma/LzmaDec.h>
+#include <lzma/LzmaTools.h>
+
 #include <asm/mach-common/bits/ppi.h>
 #include <asm/mach-common/bits/timer.h>
 
@@ -24,12 +28,9 @@
 #define LCD_Y_RES		240	/* Vertical Resolution */
 #define DMA_BUS_SIZE		16
 
-#ifdef CONFIG_BF527_EZKIT_REV_2_1 /* lq035q1 */
+#include EASYLOGO_HEADER
 
-#if !defined(CONFIG_LQ035Q1_USE_RGB888_8_BIT_PPI) && \
-    !defined(CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI)
-# define CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI
-#endif
+#ifdef CONFIG_BF527_EZKIT_REV_2_1 /* lq035q1 */
 
 /* Interface 16/18-bit TFT over an 8-bit wide PPI using a
  * small Programmable Logic Device (CPLD)
@@ -37,14 +38,12 @@
  */
 
 #ifdef CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI
-#include <asm/bfin_logo_rgb565_230x230.h>
 #define LCD_BPP		16	/* Bit Per Pixel */
 #define CLOCKS_PPIX	2	/* Clocks per pixel */
 #define CPLD_DELAY	3	/* RGB565 pipeline delay */
 #endif
 
 #ifdef CONFIG_LQ035Q1_USE_RGB888_8_BIT_PPI
-#include <asm/bfin_logo_230x230.h>
 #define LCD_BPP		24	/* Bit Per Pixel */
 #define CLOCKS_PPIX	3	/* Clocks per pixel */
 #define CPLD_DELAY	5	/* RGB888 pipeline delay */
@@ -96,7 +95,6 @@
 #endif
 
 #else /* t350mcqb */
-#include <asm/bfin_logo_230x230.h>
 
 #define LCD_BPP		24	/* Bit Per Pixel */
 #define CLOCKS_PPIX	3	/* Clocks per pixel */
@@ -419,13 +417,23 @@ int drv_video_init(void)
 #ifdef EASYLOGO_ENABLE_GZIP
 	unsigned char *data = EASYLOGO_DECOMP_BUFFER;
 	unsigned long src_len = EASYLOGO_ENABLE_GZIP;
-	if (gunzip(data, bfin_logo.size, bfin_logo.data, &src_len)) {
+	error = gunzip(data, bfin_logo.size, bfin_logo.data, &src_len);
+	bfin_logo.data = data;
+#elif defined(EASYLOGO_ENABLE_LZMA)
+	unsigned char *data = EASYLOGO_DECOMP_BUFFER;
+	SizeT lzma_len = bfin_logo.size;
+	error = lzmaBuffToBuffDecompress(data, &lzma_len,
+		bfin_logo.data, EASYLOGO_ENABLE_LZMA);
+	bfin_logo.data = data;
+#else
+	error = 0;
+#endif
+
+	if (error) {
 		puts("Failed to decompress logo\n");
 		free(dst);
 		return -1;
 	}
-	bfin_logo.data = data;
-#endif
 
 	memset(dst + ACTIVE_VIDEO_MEM_OFFSET, bfin_logo.data[0], fbmem_size - ACTIVE_VIDEO_MEM_OFFSET);
 
board/bf548-ezkit/video.c +18 -4
index 9bcf935..6737ac1 100644
@@ -18,11 +18,15 @@
 #include <linux/types.h>
 #include <stdio_dev.h>
 
+#include <lzma/LzmaTypes.h>
+#include <lzma/LzmaDec.h>
+#include <lzma/LzmaTools.h>
+
 #define DMA_SIZE16	2
 
 #include <asm/mach-common/bits/eppi.h>
 
-#include <asm/bfin_logo_230x230.h>
+#include EASYLOGO_HEADER
 
 #define LCD_X_RES		480	/*Horizontal Resolution */
 #define LCD_Y_RES		272	/* Vertical Resolution */
@@ -303,13 +307,23 @@ int drv_video_init(void)
 #ifdef EASYLOGO_ENABLE_GZIP
 	unsigned char *data = EASYLOGO_DECOMP_BUFFER;
 	unsigned long src_len = EASYLOGO_ENABLE_GZIP;
-	if (gunzip(data, bfin_logo.size, bfin_logo.data, &src_len)) {
+	error = gunzip(data, bfin_logo.size, bfin_logo.data, &src_len);
+	bfin_logo.data = data;
+#elif defined(EASYLOGO_ENABLE_LZMA)
+	unsigned char *data = EASYLOGO_DECOMP_BUFFER;
+	SizeT lzma_len = bfin_logo.size;
+	error = lzmaBuffToBuffDecompress(data, &lzma_len,
+		bfin_logo.data, EASYLOGO_ENABLE_LZMA);
+	bfin_logo.data = data;
+#else
+	error = 0;
+#endif
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

board/cm-bf548/video.c +18 -7
index 4703098..a43413e 100644

Lines of this file are not shown. View the raw message.

include/configs/bf527-ezkit.h +9 -0
index 1256e81..3b473fe 100644

Lines of this file are not shown. View the raw message.

include/configs/bf548-ezkit.h +1 -0
index 3eadcef..d457f21 100644

Lines of this file are not shown. View the raw message.

include/configs/cm-bf548.h +1 -0
index a6d2fa8..3c9eeb5 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.8.4

Part of the diff is not shown here. View the raw message.

#2 lore raw

PATCH 2/2 Blackfin: easylogo: add lzma logos

Quoted 7 lines

The bf527-ezkit boards are getting too big to fit into their reserved flash space, so we need to use a lzma compressed logo.

Since the video driver code is very similar, add lzma compressed support to all of the Blackfin video drivers.

So what exactly do you plan to do when the u-boot won't fit into the reserved flash space next time ?

#3 lore raw

PATCH 2/2 Blackfin: easylogo: add lzma logos

Quoted 8 lines · On Saturday 04 February 2012 09:56:33 Marek Vasut wrote:
Quoted 5 lines

The bf527-ezkit boards are getting too big to fit into their reserved flash space, so we need to use a lzma compressed logo.

Since the video driver code is very similar, add lzma compressed support to all of the Blackfin video drivers.

So what exactly do you plan to do when the u-boot won't fit into the reserved flash space next time ?

i'll worry about that when it comes
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120204/1ef54b83/attachment.pgp>

#4 lore raw

PATCH 2/2 Blackfin: easylogo: add lzma logos

Quoted 12 lines · On Saturday 04 February 2012 09:56:33 Marek Vasut wrote:
Quoted 8 lines
Quoted 5 lines

The bf527-ezkit boards are getting too big to fit into their reserved flash space, so we need to use a lzma compressed logo.

Since the video driver code is very similar, add lzma compressed support to all of the Blackfin video drivers.

So what exactly do you plan to do when the u-boot won't fit into the reserved flash space next time ?

i'll worry about that when it comes
-mike

maybe you can introduce decompressor into u-boot like linux has it and compress the rest of uboot with lzma/xz ? :)

M

#5 lore raw

PATCH 2/2 Blackfin: easylogo: add lzma logos

Quoted 7 lines · On Saturday 04 February 2012 14:38:15 Marek Vasut wrote:
Quoted 7 lines · On Saturday 04 February 2012 09:56:33 Marek Vasut wrote:
Quoted 6 lines
Quoted 5 lines

The bf527-ezkit boards are getting too big to fit into their reserved flash space, so we need to use a lzma compressed logo.

Since the video driver code is very similar, add lzma compressed support to all of the Blackfin video drivers.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

So what exactly do you plan to do when the u-boot won't fit into the reserved flash space next time ?

i'll worry about that when it comes

maybe you can introduce decompressor into u-boot like linux has it and compress the rest of uboot with lzma/xz ? :)

i've thought of doing that in the past. for some people, size matters a _lot_ more than speed. although i looked at implementing it with the Blackfin bootrom callback mechanism rather than in u-boot directly. i guess the SPL code could do the same thing "easily".
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120204/7574c499/attachment.pgp>

#6 lore raw

PATCH 1/2 easylogo: add lzma support

In reply to Mike Frysinger

Dear Mike Frysinger,

Quoted 10 lines · In message <[email protected]> you wrote:

Compressing the logos with lzma rather than gzip saves ~9kb with the Blackfin 24bit images and ~3kb with the 16bit images.

Add a new -l option to easylogo so people can pick lzma as their decompression routine.

---
 tools/easylogo/easylogo.c |   85 +++++++++++++++++++++++++++++---------------
 1 files changed, 56 insertions(+), 29 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The first thing we do is kill all the lawyers.
(Shakespeare. II Henry VI, Act IV, scene ii)