X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=tools%2Fsocfpgaimage.c;h=8fe91fe80ee9ac9ab5c2c0f7af25705f212bd486;hb=6fc901c538907f48d4253a6e23987df2268f75ae;hp=396d8a5472f90ce0981515e26c4ebb9c0d2541e8;hpb=790af815436bc6a93e4c581840be2419897f23b1;p=u-boot diff --git a/tools/socfpgaimage.c b/tools/socfpgaimage.c index 396d8a5472..8fe91fe80e 100644 --- a/tools/socfpgaimage.c +++ b/tools/socfpgaimage.c @@ -33,6 +33,8 @@ #include "pbl_crc32.h" #include "imagetool.h" +#include "mkimage.h" + #include #define HEADER_OFFSET 0x40 @@ -74,12 +76,12 @@ static uint16_t hdr_checksum(struct socfpga_header *header) static void build_header(uint8_t *buf, uint8_t version, uint8_t flags, uint16_t length_bytes) { - header.validation = htole32(VALIDATION_WORD); + header.validation = cpu_to_le32(VALIDATION_WORD); header.version = version; header.flags = flags; - header.length_u32 = htole16(length_bytes/4); + header.length_u32 = cpu_to_le16(length_bytes/4); header.zero = 0; - header.checksum = htole16(hdr_checksum(&header)); + header.checksum = cpu_to_le16(hdr_checksum(&header)); memcpy(buf, &header, sizeof(header)); } @@ -92,12 +94,12 @@ static int verify_header(const uint8_t *buf) { memcpy(&header, buf, sizeof(header)); - if (le32toh(header.validation) != VALIDATION_WORD) + if (le32_to_cpu(header.validation) != VALIDATION_WORD) return -1; - if (le16toh(header.checksum) != hdr_checksum(&header)) + if (le16_to_cpu(header.checksum) != hdr_checksum(&header)) return -1; - return le16toh(header.length_u32) * 4; + return le16_to_cpu(header.length_u32) * 4; } /* Sign the buffer and return the signed buffer size */ @@ -116,7 +118,7 @@ static int sign_buffer(uint8_t *buf, /* Calculate and apply the CRC */ calc_crc = ~pbl_crc32(0, (char *)buf, len); - *((uint32_t *)(buf + len)) = htole32(calc_crc); + *((uint32_t *)(buf + len)) = cpu_to_le32(calc_crc); if (!pad_64k) return len + 4; @@ -133,12 +135,12 @@ static int verify_buffer(const uint8_t *buf) len = verify_header(buf + HEADER_OFFSET); if (len < 0) { - fprintf(stderr, "Invalid header\n"); + debug("Invalid header\n"); return -1; } if (len < HEADER_OFFSET || len > PADDED_SIZE) { - fprintf(stderr, "Invalid header length (%i)\n", len); + debug("Invalid header length (%i)\n", len); return -1; } @@ -150,7 +152,7 @@ static int verify_buffer(const uint8_t *buf) calc_crc = ~pbl_crc32(0, (const char *)buf, len); - buf_crc = le32toh(*((uint32_t *)(buf + len))); + buf_crc = le32_to_cpu(*((uint32_t *)(buf + len))); if (buf_crc != calc_crc) { fprintf(stderr, "CRC32 does not match (%08x != %08x)\n", @@ -241,19 +243,17 @@ static void socfpgaimage_set_header(void *ptr, struct stat *sbuf, int ifd, sign_buffer(buf, 0, 0, data_size, 0); } -static struct image_type_params socfpgaimage_params = { - .name = "Altera SOCFPGA preloader support", - .vrec_header = socfpgaimage_vrec_header, - .header_size = 0, /* This will be modified by vrec_header() */ - .hdr = (void *)buffer, - .check_image_type = socfpgaimage_check_image_types, - .verify_header = socfpgaimage_verify_header, - .print_header = socfpgaimage_print_header, - .set_header = socfpgaimage_set_header, - .check_params = socfpgaimage_check_params, -}; - -void init_socfpga_image_type(void) -{ - register_image_type(&socfpgaimage_params); -} +U_BOOT_IMAGE_TYPE( + socfpgaimage, + "Altera SOCFPGA preloader support", + 0, /* This will be modified by vrec_header() */ + (void *)buffer, + socfpgaimage_check_params, + socfpgaimage_verify_header, + socfpgaimage_print_header, + socfpgaimage_set_header, + NULL, + socfpgaimage_check_image_types, + NULL, + socfpgaimage_vrec_header +);