9
0
Fork 0

move mkimage.c to scripts, make it compile

This commit is contained in:
Sascha Hauer 2007-09-21 13:55:04 +02:00
parent 762019f198
commit fd8e989e2e
4 changed files with 27 additions and 36 deletions

View File

@ -98,8 +98,6 @@
#define IH_CPU IH_CPU_BLACKFIN
#elif defined(__avr32__)
#define IH_CPU IH_CPU_AVR32
#else
# error Unknown CPU type
#endif
/*

View File

@ -8,21 +8,15 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#ifndef USE_HOSTCC /* Shut down "ANSI does not permit..." warnings */
#ifdef __U_BOOT__ /* Shut down "ANSI does not permit..." warnings */
#include <common.h> /* to get command definitions like CFG_CMD_JFFS2 */
#endif
#include "zlib.h"
#define local static
#define ZEXPORT /* empty */
unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
#ifdef CONFIG_DYNAMIC_CRC_TABLE
local int crc_table_empty = 1;
local uLongf crc_table[256];
local void make_crc_table OF((void));
static int crc_table_empty = 1;
static ulong crc_table[256];
static void make_crc_table(void);
/*
Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
@ -48,22 +42,22 @@ local void make_crc_table OF((void));
the information needed to generate CRC's on data a byte at a time for all
combinations of CRC register values and incoming bytes.
*/
local void make_crc_table()
static void make_crc_table()
{
uLong c;
ulong c;
int n, k;
uLong poly; /* polynomial exclusive-or pattern */
ulong poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
static const char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
/* make exclusive-or pattern from polynomial (0xedb88320L) */
poly = 0L;
for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
for (n = 0; n < sizeof(p)/sizeof(char); n++)
poly |= 1L << (31 - p[n]);
for (n = 0; n < 256; n++)
{
c = (uLong)n;
c = (ulong)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[n] = c;
@ -74,7 +68,7 @@ local void make_crc_table()
/* ========================================================================
* Table of CRC-32's of all single-byte values (made by make_crc_table)
*/
local const uLongf crc_table[256] = {
static const ulong crc_table[256] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
@ -138,10 +132,7 @@ local const uLongf crc_table[256] = {
#define DO8(buf) DO4(buf); DO4(buf);
/* ========================================================================= */
uLong ZEXPORT crc32(crc, buf, len)
uLong crc;
const Bytef *buf;
uInt len;
ulong crc32(ulong crc, const unsigned char *buf, uint len)
{
#ifdef CONFIG_DYNAMIC_CRC_TABLE
if (crc_table_empty)
@ -165,7 +156,7 @@ uLong ZEXPORT crc32(crc, buf, len)
/* No ones complement version. JFFS2 (and other things ?)
* don't use ones compliment in their CRC calculations.
*/
uLong ZEXPORT crc32_no_comp(uLong crc, const Bytef *buf, uInt len)
uLong crc32_no_comp(uLong crc, const Bytef *buf, uint len)
{
#ifdef CONFIG_DYNAMIC_CRC_TABLE
if (crc_table_empty)

View File

@ -12,6 +12,7 @@ hostprogs-$(CONFIG_LOGO) += pnmtologo
hostprogs-$(CONFIG_VT) += conmakehash
hostprogs-$(CONFIG_PROM_CONSOLE) += conmakehash
hostprogs-y += bin2c
hostprogs-y += mkimage
hostprogs-y += ubootenv
hostprogs-$(CONFIG_ARCH_NETX) += gen_netx_image

View File

@ -58,9 +58,7 @@ typedef unsigned int uint32_t;
#define O_BINARY 0
#endif
#include <image.h>
extern int errno;
#include "../include/image.h"
#ifndef MAP_FAILED
#define MAP_FAILED (-1)
@ -68,7 +66,10 @@ extern int errno;
char *cmdname;
extern unsigned long crc32 (unsigned long crc, const char *buf, unsigned int len);
#include "../include/zlib.h"
#include "../lib/crc32.c"
//extern unsigned long crc32 (unsigned long crc, const char *buf, unsigned int len);
typedef struct table_entry {
int val; /* as defined in image.h */
@ -182,7 +183,7 @@ main (int argc, char **argv)
uint32_t addr;
uint32_t ep;
struct stat sbuf;
unsigned char *ptr;
char *ptr;
char *name = "";
cmdname = *argv;
@ -320,7 +321,7 @@ NXTARG: ;
exit (EXIT_FAILURE);
}
ptr = (unsigned char *)mmap(0, sbuf.st_size,
ptr = mmap(0, sbuf.st_size,
PROT_READ, MAP_SHARED, ifd, 0);
if ((caddr_t)ptr == (caddr_t)-1) {
fprintf (stderr, "%s: Can't read %s: %s\n",
@ -348,7 +349,7 @@ NXTARG: ;
checksum = ntohl(hdr->ih_hcrc);
hdr->ih_hcrc = htonl(0); /* clear for re-calculation */
if (crc32 (0, data, len) != checksum) {
if (crc32 (0, (unsigned char *)data, len) != checksum) {
fprintf (stderr,
"%s: ERROR: \"%s\" has bad header checksum!\n",
cmdname, imagefile);
@ -358,7 +359,7 @@ NXTARG: ;
data = (char *)(ptr + sizeof(image_header_t));
len = sbuf.st_size - sizeof(image_header_t) ;
if (crc32 (0, data, len) != ntohl(hdr->ih_dcrc)) {
if (crc32 (0, (unsigned char *)data, len) != ntohl(hdr->ih_dcrc)) {
fprintf (stderr,
"%s: ERROR: \"%s\" has corrupted data!\n",
cmdname, imagefile);
@ -458,9 +459,9 @@ NXTARG: ;
exit (EXIT_FAILURE);
}
ptr = (unsigned char *)mmap(0, sbuf.st_size,
ptr = mmap(0, sbuf.st_size,
PROT_READ|PROT_WRITE, MAP_SHARED, ifd, 0);
if (ptr == (unsigned char *)MAP_FAILED) {
if (ptr == MAP_FAILED) {
fprintf (stderr, "%s: Can't map %s: %s\n",
cmdname, imagefile, strerror(errno));
exit (EXIT_FAILURE);
@ -469,7 +470,7 @@ NXTARG: ;
hdr = (image_header_t *)ptr;
checksum = crc32 (0,
(const char *)(ptr + sizeof(image_header_t)),
(unsigned char *)(ptr + sizeof(image_header_t)),
sbuf.st_size - sizeof(image_header_t)
);
@ -487,7 +488,7 @@ NXTARG: ;
strncpy((char *)hdr->ih_name, name, IH_NMLEN);
checksum = crc32(0,(const char *)hdr,sizeof(image_header_t));
checksum = crc32(0,(unsigned char *)hdr,sizeof(image_header_t));
hdr->ih_hcrc = htonl(checksum);