123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- #include "imagetool.h"
- #include <compiler.h>
- #include <image.h>
- struct nand_page_0_boot_header {
- union {
- uint32_t fcb[128];
- uint8_t fcb_bytes[512];
- };
- uint8_t sw_ecc[512];
- uint32_t padding[65280];
- uint8_t ivt_prefix[1024];
- };
- static struct nand_page_0_boot_header vybridimage_header;
- static int vybridimage_check_image_types(uint8_t type)
- {
- if (type == IH_TYPE_VYBRIDIMAGE)
- return EXIT_SUCCESS;
- return EXIT_FAILURE;
- }
- static uint8_t vybridimage_sw_ecc(uint8_t byte)
- {
- uint8_t bit0 = (byte & (1 << 0)) ? 1 : 0;
- uint8_t bit1 = (byte & (1 << 1)) ? 1 : 0;
- uint8_t bit2 = (byte & (1 << 2)) ? 1 : 0;
- uint8_t bit3 = (byte & (1 << 3)) ? 1 : 0;
- uint8_t bit4 = (byte & (1 << 4)) ? 1 : 0;
- uint8_t bit5 = (byte & (1 << 5)) ? 1 : 0;
- uint8_t bit6 = (byte & (1 << 6)) ? 1 : 0;
- uint8_t bit7 = (byte & (1 << 7)) ? 1 : 0;
- uint8_t res = 0;
- res |= ((bit6 ^ bit5 ^ bit3 ^ bit2) << 0);
- res |= ((bit7 ^ bit5 ^ bit4 ^ bit2 ^ bit1) << 1);
- res |= ((bit7 ^ bit6 ^ bit5 ^ bit1 ^ bit0) << 2);
- res |= ((bit7 ^ bit4 ^ bit3 ^ bit0) << 3);
- res |= ((bit6 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0) << 4);
- return res;
- }
- static int vybridimage_verify_header(unsigned char *ptr, int image_size,
- struct image_tool_params *params)
- {
- struct nand_page_0_boot_header *hdr =
- (struct nand_page_0_boot_header *)ptr;
- int idx;
- if (hdr->fcb[1] != 0x46434220)
- return -1;
- if (hdr->fcb[2] != 1)
- return -1;
- if (hdr->fcb[7] != 64)
- return -1;
- if (hdr->fcb[14] != 6)
- return -1;
- if (hdr->fcb[30] != 0x0001ff00)
- return -1;
- if (hdr->fcb[43] != 1)
- return -1;
- if (hdr->fcb[54] != 0)
- return -1;
- if (hdr->fcb[55] != 8)
- return -1;
-
- for (idx = 0; idx < sizeof(hdr->fcb_bytes); idx++) {
- uint8_t sw_ecc = vybridimage_sw_ecc(hdr->fcb_bytes[idx]);
- if (sw_ecc != hdr->sw_ecc[idx])
- return -1;
- }
- return 0;
- }
- static void vybridimage_set_header(void *ptr, struct stat *sbuf, int ifd,
- struct image_tool_params *params)
- {
- struct nand_page_0_boot_header *hdr =
- (struct nand_page_0_boot_header *)ptr;
- int idx;
-
- memset(&hdr->fcb[0], 0x0, 56*sizeof(uint32_t));
- memset(&hdr->fcb[56], 0xff, 72*sizeof(uint32_t));
-
- memset(&hdr->sw_ecc[0], 0xff, sizeof(hdr->sw_ecc));
- memset(&hdr->padding[0], 0xff, sizeof(hdr->padding));
-
- memset(&hdr->ivt_prefix[0], 0x00, sizeof(hdr->ivt_prefix));
-
- hdr->fcb[1] = 0x46434220;
- hdr->fcb[2] = 0x00000001;
- hdr->fcb[5] = 2048;
- hdr->fcb[6] = (2048+64);
- hdr->fcb[7] = 64;
- hdr->fcb[14] = 6;
- hdr->fcb[26] = 128;
- hdr->fcb[27] = 128;
- hdr->fcb[30] = 0x0001ff00;
- hdr->fcb[33] = 2048;
- hdr->fcb[43] = 1;
- hdr->fcb[54] = 0;
- hdr->fcb[55] = 8;
-
- for (idx = 0; idx < sizeof(hdr->fcb_bytes); idx++)
- hdr->sw_ecc[idx] = vybridimage_sw_ecc(hdr->fcb_bytes[idx]);
- }
- static void vybridimage_print_hdr_field(struct nand_page_0_boot_header *hdr,
- int idx)
- {
- printf("header.fcb[%d] = %08x\n", idx, hdr->fcb[idx]);
- }
- static void vybridimage_print_header(const void *ptr)
- {
- struct nand_page_0_boot_header *hdr =
- (struct nand_page_0_boot_header *)ptr;
- int idx;
- for (idx = 0; idx < 56; idx++)
- vybridimage_print_hdr_field(hdr, idx);
- }
- U_BOOT_IMAGE_TYPE(
- vybridimage,
- "Vybrid Boot Image",
- sizeof(vybridimage_header),
- (void *)&vybridimage_header,
- NULL,
- vybridimage_verify_header,
- vybridimage_print_header,
- vybridimage_set_header,
- NULL,
- vybridimage_check_image_types,
- NULL,
- NULL
- );
|