summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile3
-rw-r--r--tools/easylogo/Makefile10
-rw-r--r--tools/easylogo/easylogo.c626
-rw-r--r--tools/env/Makefile4
-rw-r--r--tools/env/README4
-rw-r--r--tools/env/fw_env.c57
-rw-r--r--tools/env/fw_env.h6
7 files changed, 373 insertions, 337 deletions
diff --git a/tools/Makefile b/tools/Makefile
index e8e0280..af0de47 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -97,6 +97,7 @@ endif
#
ifeq ($(HOSTOS),cygwin)
SFX = .exe
+HOST_CFLAGS += -ansi
else
SFX =
endif
@@ -136,7 +137,7 @@ $(obj)img2srec$(SFX): $(obj)img2srec.o
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
$(STRIP) $@
-$(obj)mkimage$(SFX): $(obj)mkimage.o $(obj)crc32.o $(obj)sha1.o
+$(obj)mkimage$(SFX): $(obj)mkimage.o $(obj)crc32.o
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
$(STRIP) $@
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..080bea9 100644
--- a/tools/easylogo/easylogo.c
+++ b/tools/easylogo/easylogo.c
@@ -8,415 +8,431 @@
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#pragma pack(1)
/*#define ENABLE_ASCII_BANNERS */
typedef struct {
- unsigned char id;
- unsigned char ColorMapType;
- unsigned char ImageTypeCode;
- unsigned short ColorMapOrigin;
- unsigned short ColorMapLenght;
- unsigned char ColorMapEntrySize;
- unsigned short ImageXOrigin;
- unsigned short ImageYOrigin;
- unsigned short ImageWidth;
- unsigned short ImageHeight;
- unsigned char ImagePixelSize;
- unsigned char ImageDescriptorByte;
+ unsigned char id;
+ unsigned char ColorMapType;
+ unsigned char ImageTypeCode;
+ unsigned short ColorMapOrigin;
+ unsigned short ColorMapLenght;
+ unsigned char ColorMapEntrySize;
+ unsigned short ImageXOrigin;
+ unsigned short ImageYOrigin;
+ unsigned short ImageWidth;
+ unsigned short ImageHeight;
+ unsigned char ImagePixelSize;
+ unsigned char ImageDescriptorByte;
} tga_header_t;
typedef struct {
- unsigned char r,g,b ;
-} rgb_t ;
+ unsigned char r, g, b;
+} rgb_t;
typedef struct {
- unsigned char b,g,r ;
-} bgr_t ;
+ unsigned char b, g, r;
+} bgr_t;
typedef struct {
- unsigned char Cb,y1,Cr,y2;
-} yuyv_t ;
+ unsigned char Cb, y1, Cr, y2;
+} yuyv_t;
typedef struct {
- unsigned char *data,
- *palette ;
- int width,
- height,
- pixels,
- bpp,
- pixel_size,
- size,
- palette_size,
- yuyv;
-} image_t ;
+ void *data, *palette;
+ int width, height, pixels, bpp, pixel_size, size, palette_size, yuyv;
+} image_t;
void StringUpperCase (char *str)
{
- int count = strlen(str);
- char c ;
-
- while(count--)
- {
- c=*str;
- if ((c >= 'a')&&(c<='z'))
- *str = 'A' + (c-'a');
- str++ ;
- }
+ int count = strlen (str);
+ char c;
+
+ while (count--) {
+ c = *str;
+ if ((c >= 'a') && (c <= 'z'))
+ *str = 'A' + (c - 'a');
+ str++;
+ }
}
void StringLowerCase (char *str)
{
- int count = strlen(str);
- char c ;
-
- while(count--)
- {
- c=*str;
- if ((c >= 'A')&&(c<='Z'))
- *str = 'a' + (c-'A');
- str++ ;
- }
+ int count = strlen (str);
+ char c;
+
+ while (count--) {
+ c = *str;
+ if ((c >= 'A') && (c <= 'Z'))
+ *str = 'a' + (c - 'A');
+ str++;
+ }
}
-void pixel_rgb_to_yuyv (rgb_t *rgb_pixel, yuyv_t *yuyv_pixel)
+void pixel_rgb_to_yuyv (rgb_t * rgb_pixel, yuyv_t * yuyv_pixel)
{
- unsigned int pR, pG, pB ;
+ unsigned int pR, pG, pB;
- /* Transform (0-255) components to (0-100) */
- pR = rgb_pixel->r * 100 / 255 ;
- pG = rgb_pixel->g * 100 / 255 ;
- pB = rgb_pixel->b * 100 / 255 ;
+ /* Transform (0-255) components to (0-100) */
+ pR = rgb_pixel->r * 100 / 255;
+ pG = rgb_pixel->g * 100 / 255;
+ pB = rgb_pixel->b * 100 / 255;
- /* Calculate YUV values (0-255) from RGB beetween 0-100 */
- yuyv_pixel->y1 = yuyv_pixel->y2 = 209 * (pR + pG + pB) / 300 + 16 ;
- yuyv_pixel->Cb = pB - (pR/4) - (pG*3/4) + 128 ;
- yuyv_pixel->Cr = pR - (pG*3/4) - (pB/4) + 128 ;
+ /* Calculate YUV values (0-255) from RGB beetween 0-100 */
+ yuyv_pixel->y1 = yuyv_pixel->y2 = 209 * (pR + pG + pB) / 300 + 16;
+ yuyv_pixel->Cb = pB - (pR / 4) - (pG * 3 / 4) + 128;
+ yuyv_pixel->Cr = pR - (pG * 3 / 4) - (pB / 4) + 128;
- return ;
+ return;
}
-void printlogo_rgb (rgb_t *data, int w, int h)
+void printlogo_rgb (rgb_t * data, int w, int h)
{
- int x,y;
- for (y=0; y<h; y++)
- {
- for (x=0; x<w; x++, data++)
- if ((data->r < 30)/*&&(data->g == 0)&&(data->b == 0)*/)
- printf(" ");
- else
- printf("X");
- printf("\n");
- }
+ int x, y;
+
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++, data++)
+ if ((data->r <
+ 30) /*&&(data->g == 0)&&(data->b == 0) */ )
+ printf (" ");
+ else
+ printf ("X");
+ printf ("\n");
+ }
}
void printlogo_yuyv (unsigned short *data, int w, int h)
{
- int x,y;
- for (y=0; y<h; y++)
- {
- for (x=0; x<w; x++, data++)
- if (*data == 0x1080) /* Because of inverted on i386! */
- printf(" ");
- else
- printf("X");
- printf("\n");
- }
+ int x, y;
+
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++, data++)
+ if (*data == 0x1080) /* Because of inverted on i386! */
+ printf (" ");
+ else
+ printf ("X");
+ printf ("\n");
+ }
}
-int image_load_tga (image_t *image, char *filename)
+static inline unsigned short le16_to_cpu (unsigned short val)
{
- FILE *file ;
- tga_header_t header ;
- int i;
- unsigned char app ;
- rgb_t *p ;
+ union {
+ unsigned char pval[2];
+ unsigned short val;
+ } swapped;
- if( ( file = fopen( filename, "rb" ) ) == NULL )
- return -1;
-
- fread(&header, sizeof(header), 1, file);
-
- image->width = header.ImageWidth ;
- image->height = header.ImageHeight ;
+ swapped.val = val;
+ return (swapped.pval[1] << 8) + swapped.pval[0];
+}
- switch (header.ImageTypeCode){
- case 2: /* Uncompressed RGB */
- image->yuyv = 0 ;
- image->palette_size = 0 ;
- image->palette = NULL ;
- break;
+int image_load_tga (image_t * image, char *filename)
+{
+ FILE *file;
+ tga_header_t header;
+ int i;
+ unsigned char app;
+ rgb_t *p;
+
+ if ((file = fopen (filename, "rb")) == NULL)
+ return -1;
+
+ 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;
+
+ switch (header.ImageTypeCode) {
+ case 2: /* Uncompressed RGB */
+ image->yuyv = 0;
+ image->palette_size = 0;
+ image->palette = NULL;
+ break;
default:
- printf("Format not supported!\n");
- return -1 ;
- }
+ printf ("Format not supported!\n");
+ return -1;
+ }
- image->bpp = header.ImagePixelSize ;
- image->pixel_size = ((image->bpp-1) / 8) + 1 ;
- image->pixels = image->width * image->height;
- image->size = image->pixels * image->pixel_size ;
- image->data = malloc(image->size) ;
+ image->bpp = header.ImagePixelSize;
+ image->pixel_size = ((image->bpp - 1) / 8) + 1;
+ image->pixels = image->width * image->height;
+ image->size = image->pixels * image->pixel_size;
+ image->data = malloc (image->size);
- if (image->bpp != 24)
- {
- printf("Bpp not supported: %d!\n", image->bpp);
- return -1 ;
- }
+ if (image->bpp != 24) {
+ printf ("Bpp not supported: %d!\n", image->bpp);
+ return -1;
+ }
- fread(image->data, image->size, 1, file);
+ fread (image->data, image->size, 1, file);
/* Swapping R and B values */
- p = image->data ;
- for(i=0; i < image->pixels; i++, p++)
- {
- app = p->r ;
- p->r = p->b ;
- p->b = app ;
- }
+ p = image->data;
+ for (i = 0; i < image->pixels; i++, p++) {
+ app = p->r;
+ p->r = p->b;
+ p->b = app;
+ }
/* Swapping image */
- if(!(header.ImageDescriptorByte & 0x20))
- {
- unsigned char *temp = malloc(image->size);
- int linesize = image->pixel_size * image->width ;
- void *dest = image->data,
- *source = temp + image->size - linesize ;
-
- printf("S");
- if (temp == NULL)
- {
- printf("Cannot alloc temp buffer!\n");
- return -1;
- }
+ if (!(header.ImageDescriptorByte & 0x20)) {
+ unsigned char *temp = malloc (image->size);
+ int linesize = image->pixel_size * image->width;
+ void *dest = image->data,
+ *source = temp + image->size - linesize;
- memcpy(temp, image->data, image->size);
- for(i = 0; i<image->height; i++, dest+=linesize, source-=linesize)
- memcpy(dest, source, linesize);
+ printf ("S");
+ if (temp == NULL) {
+ printf ("Cannot alloc temp buffer!\n");
+ return -1;
+ }
- free( temp );
- }
+ memcpy (temp, image->data, image->size);
+ for (i = 0; i < image->height;
+ i++, dest += linesize, source -= linesize)
+ memcpy (dest, source, linesize);
+ free (temp);
+ }
#ifdef ENABLE_ASCII_BANNERS
- printlogo_rgb (image->data,image->width, image->height);
+ printlogo_rgb (image->data, image->width, image->height);
#endif
- fclose (file);
- return 0;
+ fclose (file);
+ return 0;
}
-int image_free (image_t *image)
+int image_free (image_t * image)
{
- if(image->data != NULL)
- free(image->data);
+ if (image->data != NULL)
+ free (image->data);
- if(image->palette != NULL)
- free(image->palette);
+ if (image->palette != NULL)
+ free (image->palette);
return 0;
}
-int image_rgb_to_yuyv (image_t *rgb_image, image_t *yuyv_image)
+int image_rgb_to_yuyv (image_t * rgb_image, image_t * yuyv_image)
{
- rgb_t *rgb_ptr = (rgb_t *) rgb_image->data ;
- yuyv_t yuyv ;
- unsigned short *dest ;
- int count = 0 ;
-
- yuyv_image->pixel_size = 2 ;
- yuyv_image->bpp = 16 ;
- yuyv_image->yuyv = 1 ;
- yuyv_image->width = rgb_image->width ;
- yuyv_image->height = rgb_image->height ;
- yuyv_image->pixels = yuyv_image->width * yuyv_image->height ;
- yuyv_image->size = yuyv_image->pixels * yuyv_image->pixel_size ;
- dest = (unsigned short *) (yuyv_image->data = malloc(yuyv_image->size)) ;
- yuyv_image->palette = 0 ;
- yuyv_image->palette_size= 0 ;
-
- while((count++) < rgb_image->pixels)
- {
+ rgb_t *rgb_ptr = (rgb_t *) rgb_image->data;
+ yuyv_t yuyv;
+ unsigned short *dest;
+ int count = 0;
+
+ yuyv_image->pixel_size = 2;
+ yuyv_image->bpp = 16;
+ yuyv_image->yuyv = 1;
+ yuyv_image->width = rgb_image->width;
+ yuyv_image->height = rgb_image->height;
+ yuyv_image->pixels = yuyv_image->width * yuyv_image->height;
+ yuyv_image->size = yuyv_image->pixels * yuyv_image->pixel_size;
+ dest = (unsigned short *) (yuyv_image->data =
+ malloc (yuyv_image->size));
+ yuyv_image->palette = 0;
+ yuyv_image->palette_size = 0;
+
+ while ((count++) < rgb_image->pixels) {
pixel_rgb_to_yuyv (rgb_ptr++, &yuyv);
- if ((count & 1)==0) /* Was == 0 */
- memcpy (dest, ((void *)&yuyv) + 2, sizeof(short));
+ if ((count & 1) == 0) /* Was == 0 */
+ memcpy (dest, ((void *) &yuyv) + 2, sizeof (short));
else
- memcpy (dest, (void *)&yuyv, sizeof(short));
+ memcpy (dest, (void *) &yuyv, sizeof (short));
- dest ++ ;
+ dest++;
}
#ifdef ENABLE_ASCII_BANNERS
- printlogo_yuyv (yuyv_image->data, yuyv_image->width, yuyv_image->height);
+ printlogo_yuyv (yuyv_image->data, yuyv_image->width,
+ yuyv_image->height);
#endif
- return 0 ;
+ return 0;
}
-int image_save_header (image_t *image, char *filename, char *varname)
+int image_save_header (image_t * image, char *filename, char *varname)
{
- FILE *file = fopen (filename, "w");
- char app[256], str[256]="", def_name[64] ;
- int count = image->size, col=0;
- unsigned char *dataptr = image->data ;
- if (file==NULL)
- return -1 ;
-
-/* Author information */
- fprintf(file, "/*\n * Generated by EasyLogo, (C) 2000 by Paolo Scaffardi\n *\n");
- fprintf(file, " * To use this, include it and call: easylogo_plot(screen,&%s, width,x,y)\n *\n", varname);
- fprintf(file, " * Where:\t'screen'\tis the pointer to the frame buffer\n");
- fprintf(file, " *\t\t'width'\tis the screen width\n");
- fprintf(file, " *\t\t'x'\t\tis the horizontal position\n");
- fprintf(file, " *\t\t'y'\t\tis the vertical position\n */\n\n");
-
-/* Headers */
- fprintf(file, "#include <video_easylogo.h>\n\n");
-/* Macros */
- strcpy(def_name, varname);
+ FILE *file = fopen (filename, "w");
+ char app[256], str[256] = "", def_name[64];
+ int count = image->size, col = 0;
+ unsigned char *dataptr = image->data;
+
+ if (file == NULL)
+ return -1;
+
+ /* Author information */
+ fprintf (file,
+ "/*\n * Generated by EasyLogo, (C) 2000 by Paolo Scaffardi\n *\n");
+ fprintf (file,
+ " * To use this, include it and call: easylogo_plot(screen,&%s, width,x,y)\n *\n",
+ varname);
+ fprintf (file,
+ " * Where:\t'screen'\tis the pointer to the frame buffer\n");
+ fprintf (file, " *\t\t'width'\tis the screen width\n");
+ fprintf (file, " *\t\t'x'\t\tis the horizontal position\n");
+ fprintf (file, " *\t\t'y'\t\tis the vertical position\n */\n\n");
+
+ /* Headers */
+ fprintf (file, "#include <video_easylogo.h>\n\n");
+ /* Macros */
+ strcpy (def_name, varname);
StringUpperCase (def_name);
- fprintf(file, "#define DEF_%s_WIDTH\t\t%d\n", def_name, image->width);
- fprintf(file, "#define DEF_%s_HEIGHT\t\t%d\n", def_name, image->height);
- fprintf(file, "#define DEF_%s_PIXELS\t\t%d\n", def_name, image->pixels);
- fprintf(file, "#define DEF_%s_BPP\t\t%d\n", def_name, image->bpp);
- fprintf(file, "#define DEF_%s_PIXEL_SIZE\t%d\n", def_name, image->pixel_size);
- fprintf(file, "#define DEF_%s_SIZE\t\t%d\n\n", def_name, image->size);
-/* Declaration */
- fprintf(file, "unsigned char DEF_%s_DATA[DEF_%s_SIZE] = {\n", def_name, def_name);
-
-/* Data */
- while(count)
- switch (col){
- case 0:
- sprintf(str, " 0x%02x", *dataptr++);
- col++;
- count-- ;
- break;
-
- case 16:
- fprintf(file, "%s", str);
- if (count > 0)
- fprintf(file,",");
- fprintf(file, "\n");
-
- col = 0 ;
- break;
-
- default:
- strcpy(app, str);
- sprintf(str, "%s, 0x%02x", app, *dataptr++);
- col++ ;
- count-- ;
- break;
+ fprintf (file, "#define DEF_%s_WIDTH\t\t%d\n", def_name,
+ image->width);
+ fprintf (file, "#define DEF_%s_HEIGHT\t\t%d\n", def_name,
+ image->height);
+ fprintf (file, "#define DEF_%s_PIXELS\t\t%d\n", def_name,
+ image->pixels);
+ fprintf (file, "#define DEF_%s_BPP\t\t%d\n", def_name, image->bpp);
+ fprintf (file, "#define DEF_%s_PIXEL_SIZE\t%d\n", def_name,
+ image->pixel_size);
+ fprintf (file, "#define DEF_%s_SIZE\t\t%d\n\n", def_name,
+ image->size);
+ /* Declaration */
+ fprintf (file, "unsigned char DEF_%s_DATA[DEF_%s_SIZE] = {\n",
+ def_name, def_name);
+
+ /* Data */
+ while (count)
+ switch (col) {
+ case 0:
+ sprintf (str, " 0x%02x", *dataptr++);
+ col++;
+ count--;
+ break;
+
+ case 16:
+ fprintf (file, "%s", str);
+ if (count > 0)
+ fprintf (file, ",");
+ fprintf (file, "\n");
+
+ col = 0;
+ break;
+
+ default:
+ strcpy (app, str);
+ sprintf (str, "%s, 0x%02x", app, *dataptr++);
+ col++;
+ count--;
+ break;
}
if (col)
- fprintf(file, "%s\n", str);
-
-/* End of declaration */
- fprintf(file, "};\n\n");
-/* Variable */
- fprintf(file, "fastimage_t %s = {\n", varname);
- fprintf(file, " DEF_%s_DATA,\n", def_name);
- fprintf(file, " DEF_%s_WIDTH,\n", def_name);
- fprintf(file, " DEF_%s_HEIGHT,\n", def_name);
- fprintf(file, " DEF_%s_BPP,\n", def_name);
- fprintf(file, " DEF_%s_PIXEL_SIZE,\n", def_name);
- fprintf(file, " DEF_%s_SIZE\n};\n", def_name);
+ fprintf (file, "%s\n", str);
+
+ /* End of declaration */
+ fprintf (file, "};\n\n");
+ /* Variable */
+ fprintf (file, "fastimage_t %s = {\n", varname);
+ fprintf (file, " DEF_%s_DATA,\n", def_name);
+ fprintf (file, " DEF_%s_WIDTH,\n", def_name);
+ fprintf (file, " DEF_%s_HEIGHT,\n", def_name);
+ fprintf (file, " DEF_%s_BPP,\n", def_name);
+ fprintf (file, " DEF_%s_PIXEL_SIZE,\n", def_name);
+ fprintf (file, " DEF_%s_SIZE\n};\n", def_name);
fclose (file);
- return 0 ;
+ return 0;
}
#define DEF_FILELEN 256
int main (int argc, char *argv[])
{
- char
- inputfile[DEF_FILELEN],
- outputfile[DEF_FILELEN],
- varname[DEF_FILELEN];
-
- image_t rgb_logo, yuyv_logo ;
-
- switch (argc){
- case 2:
- case 3:
- case 4:
- strcpy (inputfile, argv[1]);
-
- if (argc > 2)
- strcpy (varname, argv[2]);
- else
- {
- int pos = strchr(inputfile, '.');
-
- if (pos >= 0)
- {
- strncpy (varname, inputfile, pos);
- varname[pos] = 0 ;
- }
- }
+ char inputfile[DEF_FILELEN],
+ outputfile[DEF_FILELEN], varname[DEF_FILELEN];
+
+ image_t rgb_logo, yuyv_logo;
+
+ switch (argc) {
+ case 2:
+ case 3:
+ case 4:
+ strcpy (inputfile, argv[1]);
+
+ if (argc > 2)
+ strcpy (varname, argv[2]);
+ else {
+ char *dot = strchr (inputfile, '.');
+ int pos = dot - inputfile;
+
+ if (dot) {
+ strncpy (varname, inputfile, pos);
+ varname[pos] = 0;
+ }
+ }
- if (argc > 3)
- strcpy (outputfile, argv[3]);
- else
- {
- int pos = strchr (varname, '.');
+ if (argc > 3)
+ strcpy (outputfile, argv[3]);
+ else {
+ char *dot = strchr (varname, '.');
+ int pos = dot - varname;
- if (pos > 0)
- {
- char app[DEF_FILELEN] ;
+ if (dot) {
+ char app[DEF_FILELEN];
- strncpy(app, varname, pos);
- sprintf(outputfile, "%s.h", app);
- }
- }
- break;
+ strncpy (app, varname, pos);
+ app[pos] = 0;
+ sprintf (outputfile, "%s.h", app);
+ }
+ }
+ break;
- default:
- printf("EasyLogo 1.0 (C) 2000 by Paolo Scaffardi\n\n");
+ default:
+ printf ("EasyLogo 1.0 (C) 2000 by Paolo Scaffardi\n\n");
- printf("Syntax: easylogo inputfile [outputvar {outputfile}] \n");
- printf("\n");
- printf("Where: 'inputfile' is the TGA image to load\n");
- printf(" 'outputvar' is the variable name to create\n");
- printf(" 'outputfile' is the output header file (default is 'inputfile.h')\n");
+ printf("Syntax: easylogo inputfile [outputvar {outputfile}] \n");
+ printf("\n");
+ printf("Where: 'inputfile' is the TGA image to load\n");
+ printf(" 'outputvar' is the variable name to create\n");
+ printf(" 'outputfile' is the output header file (default is 'inputfile.h')\n");
- return -1 ;
- }
+ return -1;
+ }
- printf("Doing '%s' (%s) from '%s'...",
- outputfile, varname, inputfile);
+ printf ("Doing '%s' (%s) from '%s'...",
+ outputfile, varname, inputfile);
-/* Import TGA logo */
+ /* Import TGA logo */
- printf("L");
- if (image_load_tga (&rgb_logo, inputfile)<0)
- {
- printf("input file not found!\n");
- exit(1);
- }
+ printf ("L");
+ if (image_load_tga (&rgb_logo, inputfile) < 0) {
+ printf ("input file not found!\n");
+ exit (1);
+ }
-/* Convert it to YUYV format */
+ /* Convert it to YUYV format */
- printf("C");
- image_rgb_to_yuyv (&rgb_logo, &yuyv_logo) ;
+ printf ("C");
+ image_rgb_to_yuyv (&rgb_logo, &yuyv_logo);
-/* Save it into a header format */
+ /* Save it into a header format */
- printf("S");
- image_save_header (&yuyv_logo, outputfile, varname) ;
+ printf ("S");
+ image_save_header (&yuyv_logo, outputfile, varname);
-/* Free original image and copy */
+ /* Free original image and copy */
- image_free (&rgb_logo);
- image_free (&yuyv_logo);
+ image_free (&rgb_logo);
+ image_free (&yuyv_logo);
- printf("\n");
+ printf ("\n");
- return 0 ;
+ return 0;
}
diff --git a/tools/env/Makefile b/tools/env/Makefile
index 1f16768..ea2d5b5 100644
--- a/tools/env/Makefile
+++ b/tools/env/Makefile
@@ -28,6 +28,10 @@ HEADERS := fw_env.h
CPPFLAGS := -Wall -DUSE_HOSTCC
+ifeq ($(MTD_VERSION),old)
+CPPFLAGS += -DMTD_OLD
+endif
+
all: $(obj)fw_printenv
$(obj)fw_printenv: $(SRCS) $(HEADERS)
diff --git a/tools/env/README b/tools/env/README
index d8386f7..f8a644e 100644
--- a/tools/env/README
+++ b/tools/env/README
@@ -6,6 +6,10 @@ For the run-time utiltity configuration uncomment the line
#define CONFIG_FILE "/etc/fw_env.config"
in fw_env.h.
+For building against older versions of the MTD headers (meaning before
+v2.6.8-rc1) it is required to pass the argument "MTD_VERSION=old" to
+make.
+
See comments in the fw_env.config file for definitions for the
particular board.
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index f723b5b..e083a5b 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -31,16 +31,21 @@
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
-#include <linux/mtd/mtd.h>
-#include "fw_env.h"
-typedef unsigned char uchar;
+#ifdef MTD_OLD
+# include <linux/mtd/mtd.h>
+#else
+# define __user /* nothing */
+# include <mtd/mtd-user.h>
+#endif
+
+#include "fw_env.h"
#define CMD_GETENV "fw_printenv"
#define CMD_SETENV "fw_setenv"
typedef struct envdev_s {
- uchar devname[16]; /* Device name */
+ char devname[16]; /* Device name */
ulong devoff; /* Device offset */
ulong env_size; /* environment size */
ulong erase_size; /* device erase size */
@@ -60,22 +65,22 @@ static int curdev;
typedef struct environment_s {
ulong crc; /* CRC32 over data bytes */
- uchar flags; /* active or obsolete */
- uchar *data;
+ unsigned char flags; /* active or obsolete */
+ char *data;
} env_t;
static env_t environment;
static int HaveRedundEnv = 0;
-static uchar active_flag = 1;
-static uchar obsolete_flag = 0;
+static unsigned char active_flag = 1;
+static unsigned char obsolete_flag = 0;
#define XMK_STR(x) #x
#define MK_STR(x) XMK_STR(x)
-static uchar default_environment[] = {
+static char default_environment[] = {
#if defined(CONFIG_BOOTARGS)
"bootargs=" CONFIG_BOOTARGS "\0"
#endif
@@ -155,7 +160,7 @@ static uchar default_environment[] = {
};
static int flash_io (int mode);
-static uchar *envmatch (uchar * s1, uchar * s2);
+static char *envmatch (char * s1, char * s2);
static int env_init (void);
static int parse_config (void);
@@ -175,15 +180,15 @@ static inline ulong getenvsize (void)
* Search the environment for a variable.
* Return the value, if found, or NULL, if not found.
*/
-unsigned char *fw_getenv (unsigned char *name)
+char *fw_getenv (char *name)
{
- uchar *env, *nxt;
+ char *env, *nxt;
if (env_init ())
return (NULL);
for (env = environment.data; *env; env = nxt + 1) {
- uchar *val;
+ char *val;
for (nxt = env; *nxt; ++nxt) {
if (nxt >= &environment.data[ENV_SIZE]) {
@@ -206,7 +211,7 @@ unsigned char *fw_getenv (unsigned char *name)
*/
void fw_printenv (int argc, char *argv[])
{
- uchar *env, *nxt;
+ char *env, *nxt;
int i, n_flag;
if (env_init ())
@@ -241,8 +246,8 @@ void fw_printenv (int argc, char *argv[])
}
for (i = 1; i < argc; ++i) { /* print single env variables */
- uchar *name = argv[i];
- uchar *val = NULL;
+ char *name = argv[i];
+ char *val = NULL;
for (env = environment.data; *env; env = nxt + 1) {
@@ -279,9 +284,9 @@ void fw_printenv (int argc, char *argv[])
int fw_setenv (int argc, char *argv[])
{
int i, len;
- uchar *env, *nxt;
- uchar *oldval = NULL;
- uchar *name;
+ char *env, *nxt;
+ char *oldval = NULL;
+ char *name;
if (argc < 2) {
return (EINVAL);
@@ -361,7 +366,7 @@ int fw_setenv (int argc, char *argv[])
while ((*env = *name++) != '\0')
env++;
for (i = 2; i < argc; ++i) {
- uchar *val = argv[i];
+ char *val = argv[i];
*env = (i == 2) ? '=' : ' ';
while ((*++env = *val++) != '\0');
@@ -373,7 +378,7 @@ int fw_setenv (int argc, char *argv[])
WRITE_FLASH:
/* Update CRC */
- environment.crc = crc32 (0, environment.data, ENV_SIZE);
+ environment.crc = crc32 (0, (uint8_t*) environment.data, ENV_SIZE);
/* write environment back to flash */
if (flash_io (O_RDWR)) {
@@ -569,7 +574,7 @@ static int flash_io (int mode)
* If the names match, return the value of s2, else NULL.
*/
-static uchar *envmatch (uchar * s1, uchar * s2)
+static char *envmatch (char * s1, char * s2)
{
while (*s1 == *s2++)
@@ -586,10 +591,10 @@ static uchar *envmatch (uchar * s1, uchar * s2)
static int env_init (void)
{
int crc1, crc1_ok;
- uchar *addr1;
+ char *addr1;
int crc2, crc2_ok;
- uchar flag1, flag2, *addr2;
+ char flag1, flag2, *addr2;
if (parse_config ()) /* should fill envdevices */
return 1;
@@ -608,7 +613,7 @@ static int env_init (void)
return (errno);
}
- crc1_ok = ((crc1 = crc32 (0, environment.data, ENV_SIZE))
+ crc1_ok = ((crc1 = crc32 (0, (uint8_t *) environment.data, ENV_SIZE))
== environment.crc);
if (!HaveRedundEnv) {
if (!crc1_ok) {
@@ -632,7 +637,7 @@ static int env_init (void)
return (errno);
}
- crc2_ok = ((crc2 = crc32 (0, environment.data, ENV_SIZE))
+ crc2_ok = ((crc2 = crc32 (0, (uint8_t *) environment.data, ENV_SIZE))
== environment.crc);
flag2 = environment.flags;
diff --git a/tools/env/fw_env.h b/tools/env/fw_env.h
index 13c45a2..58607de 100644
--- a/tools/env/fw_env.h
+++ b/tools/env/fw_env.h
@@ -47,8 +47,8 @@
"ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; " \
"bootm"
-extern void fw_printenv(int argc, char *argv[]);
-extern unsigned char *fw_getenv (unsigned char *name);
-extern int fw_setenv (int argc, char *argv[]);
+extern void fw_printenv(int argc, char *argv[]);
+extern char *fw_getenv (char *name);
+extern int fw_setenv (int argc, char *argv[]);
extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned);