[new uImage] Define a API for image handling operations

- Add inline helper macros for basic header processing
- Move common non inline code common/image.c
- Replace direct header access with the API routines
- Rename IH_CPU_* to IH_ARCH_*

Signed-off-by: Marian Balakowicz <m8@semihalf.com>
diff --git a/board/mpl/common/common_util.c b/board/mpl/common/common_util.c
index 8d4cbe8..30c6ca9 100644
--- a/board/mpl/common/common_util.c
+++ b/board/mpl/common/common_util.c
@@ -57,9 +57,6 @@
 
 extern flash_info_t flash_info[];	/* info for FLASH chips */
 
-static image_header_t header;
-
-
 static int
 mpl_prg(uchar *src, ulong size)
 {
@@ -77,7 +74,7 @@
 	info = &flash_info[0];
 
 #if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI)
-	if (ntohl(magic[0]) != IH_MAGIC) {
+	if (image_to_cpu (magic[0]) != IH_MAGIC) {
 		puts("Bad Magic number\n");
 		return -1;
 	}
@@ -179,44 +176,39 @@
 static int
 mpl_prg_image(uchar *ld_addr)
 {
-	unsigned long len, checksum;
+	unsigned long len;
 	uchar *data;
-	image_header_t *hdr = &header;
+	image_header_t *hdr = (image_header_t *)ld_addr;
 	int rc;
 
-	/* Copy header so we can blank CRC field for re-calculation */
-	memcpy (&header, (char *)ld_addr, sizeof(image_header_t));
-	if (ntohl(hdr->ih_magic)  != IH_MAGIC) {
+	if (!image_check_magic (hdr)) {
 		puts("Bad Magic Number\n");
 		return 1;
 	}
 	print_image_hdr(hdr);
-	if (hdr->ih_os  != IH_OS_U_BOOT) {
+	if (!image_check_os (hdr, IH_OS_U_BOOT)) {
 		puts("No U-Boot Image\n");
 		return 1;
 	}
-	if (hdr->ih_type  != IH_TYPE_FIRMWARE) {
+	if (!image_check_type (hdr, IH_TYPE_FIRMWARE)) {
 		puts("No Firmware Image\n");
 		return 1;
 	}
-	data = (uchar *)&header;
-	len  = sizeof(image_header_t);
-	checksum = ntohl(hdr->ih_hcrc);
-	hdr->ih_hcrc = 0;
-	if (crc32 (0, (uchar *)data, len) != checksum) {
+	if (!image_check_hcrc (hdr)) {
 		puts("Bad Header Checksum\n");
 		return 1;
 	}
-	data = ld_addr + sizeof(image_header_t);
-	len  = ntohl(hdr->ih_size);
 	puts("Verifying Checksum ... ");
-	if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) {
+	if (!image_check_dcrc (hdr)) {
 		puts("Bad Data CRC\n");
 		return 1;
 	}
 	puts("OK\n");
 
-	if (hdr->ih_comp != IH_COMP_NONE) {
+	data = (uchar *)image_get_data (hdr);
+	len = image_get_data_size (hdr);
+
+	if (image_get_comp (hdr) != IH_COMP_NONE) {
 		uchar *buf;
 		/* reserve space for uncompressed image */
 		if ((buf = malloc(IMAGE_SIZE)) == NULL) {
@@ -224,7 +216,7 @@
 			return 1;
 		}
 
-		switch (hdr->ih_comp) {
+		switch (image_get_comp (hdr)) {
 		case IH_COMP_GZIP:
 			puts("Uncompressing (GZIP) ... ");
 			rc = gunzip ((void *)(buf), IMAGE_SIZE, data, &len);
@@ -253,7 +245,8 @@
 			break;
 #endif
 		default:
-			printf ("Unimplemented compression type %d\n", hdr->ih_comp);
+			printf ("Unimplemented compression type %d\n",
+				image_get_comp (hdr));
 			free(buf);
 			return 1;
 		}