[U-Boot-Users] [patch] do not use linux/string.h in sha1.c on hosts

Mike Frysinger vapier at gentoo.org
Mon Dec 24 23:09:30 CET 2007


linux/string.h is not a valid include outside of the kernel, so when compiling 
sha1.c for the host (for use with the `mkimage` host binary), the include 
needs to be changed to string.h.

Signed-Off-By: Mike Frysinger <vapier at gentoo.org>
---
diff --git a/lib_generic/sha1.c b/lib_generic/sha1.c
index 08ffa6b..d04cba7 100644
--- a/lib_generic/sha1.c
+++ b/lib_generic/sha1.c
@@ -29,7 +29,11 @@
 #define _CRT_SECURE_NO_DEPRECATE 1
 #endif
 
+#ifndef USE_HOSTCC
 #include <linux/string.h>
+#else
+#include <string.h>
+#endif
 #include "sha1.h"
 
 /*
diff --git a/tools/easylogo/Makefile b/tools/easylogo/Makefile
index 292344a..566b125 100644
--- a/tools/easylogo/Makefile
+++ b/tools/easylogo/Makefile
@@ -1,2 +1,8 @@
-all:	easylogo.c
-	gcc easylogo.c -o easylogo
+CFLAGS += -Wall
+
+all: easylogo
+
+clean:
+	rm -f easylogo *.o
+
+.PHONY: all clean
diff --git a/tools/easylogo/easylogo.c b/tools/easylogo/easylogo.c
index 9f1d1ff..c69f012 100644
--- a/tools/easylogo/easylogo.c
+++ b/tools/easylogo/easylogo.c
@@ -8,6 +8,8 @@
 */
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #pragma pack(1)
 
@@ -41,7 +43,7 @@ typedef struct {
 } yuyv_t ;
 
 typedef struct {
-	unsigned char	*data,
+	void				*data,
 					*palette ;
 	int				width,
 					height,
@@ -125,6 +127,16 @@ void printlogo_yuyv (unsigned short *data, int w, int h)
     }
 }
 
+static inline unsigned short le16_to_cpu (unsigned short val)
+{
+    union {
+	unsigned char pval[2];
+	unsigned short val;
+    } swapped;
+    swapped.val = val;
+    return (swapped.pval[1] << 8) + swapped.pval[0];
+}
+
 int image_load_tga (image_t *image, char *filename)
 {
     FILE *file ;
@@ -138,6 +150,14 @@ int image_load_tga (image_t *image, char *filename)
 
     fread(&header, sizeof(header), 1, file);
 
+    /* byte swap: tga is little endian, host is ??? */
+    header.ColorMapOrigin = le16_to_cpu (header.ColorMapOrigin);
+    header.ColorMapLenght = le16_to_cpu (header.ColorMapLenght);
+    header.ImageXOrigin = le16_to_cpu (header.ImageXOrigin);
+    header.ImageYOrigin = le16_to_cpu (header.ImageYOrigin);
+    header.ImageWidth = le16_to_cpu (header.ImageWidth);
+    header.ImageHeight = le16_to_cpu (header.ImageHeight);
+
     image->width 	= header.ImageWidth ;
     image->height 	= header.ImageHeight ;
 
@@ -352,9 +372,10 @@ int main (int argc, char *argv[])
 	    strcpy (varname, 	argv[2]);
 	else
 	{
-	    int pos = strchr(inputfile, '.');
+	    char *dot = strchr(inputfile, '.');
+	    int pos = dot - inputfile;
 
-	    if (pos >= 0)
+	    if (dot)
 	    {
 		strncpy (varname, inputfile, pos);
 		varname[pos] = 0 ;
@@ -365,13 +386,15 @@ int main (int argc, char *argv[])
 	    strcpy (outputfile, argv[3]);
 	else
 	{
-	    int pos = strchr (varname, '.');
+	    char *dot = strchr (varname, '.');
+	    int pos = dot - varname;
 
-	    if (pos > 0)
+	    if (dot)
 	    {
 		char app[DEF_FILELEN] ;
 
 		strncpy(app, varname, pos);
+		app[pos] = 0;
 		sprintf(outputfile, "%s.h", app);
 	    }
 	}
@@ -389,6 +412,8 @@ int main (int argc, char *argv[])
 	return -1 ;
     }
 
+    setbuf(stdout, NULL);
+
     printf("Doing '%s' (%s) from '%s'...",
 	outputfile, varname, inputfile);
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20071224/afa3f5dd/attachment.pgp 


More information about the U-Boot mailing list