$(obj)cscope.* $(obj)*.*~
        @rm -f $(obj)u-boot $(obj)u-boot.map $(obj)u-boot.hex $(ALL)
        @rm -f $(obj)tools/{crc32.c,environment.c,env/crc32.c,md5.c,sha1.c,inca-swap-bytes}
-       @rm -f $(obj)tools/{image.c,fdt.c,fdt_ro.c,fdt_rw.c,fdt_strerror.c}
+       @rm -f $(obj)tools/{image.c,fdt.c,fdt_ro.c,fdt_rw.c,fdt_strerror.c,zlib.h}
        @rm -f $(obj)tools/{fdt_wip.c,libfdt_internal.h}
        @rm -f $(obj)cpu/mpc824x/bedbug_603e.c
        @rm -f $(obj)include/asm/proc $(obj)include/asm/arch $(obj)include/asm
 
        {       -1,             "",             "",                     },
 };
 
-unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
+uint32_t crc32 (uint32_t, const unsigned char *, uint);
 static void genimg_print_size (uint32_t size);
 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
 static void genimg_print_time (time_t timestamp);
 
 int    vsprintf(char *buf, const char *fmt, va_list args);
 
 /* lib_generic/crc32.c */
-ulong crc32 (ulong, const unsigned char *, uint);
-ulong crc32_no_comp (ulong, const unsigned char *, uint);
+uint32_t crc32 (uint32_t, const unsigned char *, uint);
+uint32_t crc32_no_comp (uint32_t, const unsigned char *, uint);
 
 /* common/console.c */
 int    console_init_f(void);   /* Before relocation; uses the serial  stuff    */
 
 # endif
 #endif /* CFG_ENV_IS_IN_NAND */
 
+#ifdef USE_HOSTCC
+# include <stdint.h>
+#else
+# include <linux/types.h>
+#endif
 
 #ifdef CFG_REDUNDAND_ENVIRONMENT
-# define ENV_HEADER_SIZE       (sizeof(unsigned long) + 1)
+# define ENV_HEADER_SIZE       (sizeof(uint32_t) + 1)
 #else
-# define ENV_HEADER_SIZE       (sizeof(unsigned long))
+# define ENV_HEADER_SIZE       (sizeof(uint32_t))
 #endif
 
 
 #define ENV_SIZE (CFG_ENV_SIZE - ENV_HEADER_SIZE)
 
 typedef        struct environment_s {
-       unsigned long   crc;            /* CRC32 over data bytes        */
+       uint32_t        crc;            /* CRC32 over data bytes        */
 #ifdef CFG_REDUNDAND_ENVIRONMENT
        unsigned char   flags;          /* active/obsolete flags        */
 #endif
 
 
 #ifndef USE_HOSTCC     /* Shut down "ANSI does not permit..." warnings */
 #include <common.h>
+#else
+#include <stdint.h>
 #endif
 
 #include "zlib.h"
 
 #define local static
 #define ZEXPORT        /* empty */
-unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
 
 #ifdef DYNAMIC_CRC_TABLE
 
 local int crc_table_empty = 1;
-local uLongf crc_table[256];
+local uint32_t crc_table[256];
 local void make_crc_table OF((void));
 
 /*
 */
 local void make_crc_table()
 {
-  uLong c;
+  uint32_t c;
   int n, k;
   uLong poly;            /* polynomial exclusive-or pattern */
   /* terms of polynomial defining this crc (except x^32): */
 /* ========================================================================
  * Table of CRC-32's of all single-byte values (made by make_crc_table)
  */
-local const uLongf crc_table[256] = {
+local const uint32_t crc_table[256] = {
   0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
   0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
   0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
 /* =========================================================================
  * This function can be used by asm versions of crc32()
  */
-const uLongf * ZEXPORT get_crc_table()
+const uint32_t * ZEXPORT get_crc_table()
 {
 #ifdef DYNAMIC_CRC_TABLE
   if (crc_table_empty) make_crc_table();
 #endif
-  return (const uLongf *)crc_table;
+  return (const uint32_t *)crc_table;
 }
 #endif
 
 #define DO8(buf)  DO4(buf); DO4(buf);
 
 /* ========================================================================= */
-uLong ZEXPORT crc32(crc, buf, len)
-    uLong crc;
+uint32_t ZEXPORT crc32(crc, buf, len)
+    uint32_t crc;
     const Bytef *buf;
     uInt 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)
+uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
 {
 #ifdef DYNAMIC_CRC_TABLE
     if (crc_table_empty)
 
 $(obj)environment.o:   $(obj)environment.c
                $(CC) -g $(HOST_ENVIRO_CFLAGS) $(CPPFLAGS) -c -o $@ $<
 
-$(obj)crc32.c:
+$(obj)zlib.h:
+               @rm -f $@
+               ln -s $(src)../include/zlib.h $@
+
+$(obj)crc32.c: $(obj)zlib.h
                @rm -f $(obj)crc32.c
                ln -s $(src)../lib_generic/crc32.c $(obj)crc32.c
 
 
  */
 
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <unistd.h>
 
 #endif /* CFG_ENV_IS_IN_FLASH */
 
 #ifdef CFG_REDUNDAND_ENVIRONMENT
-# define ENV_HEADER_SIZE       (sizeof(unsigned long) + 1)
+# define ENV_HEADER_SIZE       (sizeof(uint32_t) + 1)
 #else
-# define ENV_HEADER_SIZE       (sizeof(unsigned long))
+# define ENV_HEADER_SIZE       (sizeof(uint32_t))
 #endif
 
 #define ENV_SIZE (CFG_ENV_SIZE - ENV_HEADER_SIZE)
 
 
-extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
+extern uint32_t crc32 (uint32_t, const unsigned char *, unsigned int);
 
 #ifdef ENV_IS_EMBEDDED
 extern unsigned int env_size;
 int main (int argc, char **argv)
 {
 #ifdef ENV_IS_EMBEDDED
-       int crc;
+       uint32_t crc;
        unsigned char *envptr = &environment,
                *dataptr = envptr + ENV_HEADER_SIZE;
        unsigned int datasize = ENV_SIZE;