2 * Copyright (C) 2011 Samsung Electronics
4 * SPDX-License-Identifier: GPL-2.0+
15 #define BUFSIZE (16*1024)
16 #define IMG_SIZE (16*1024)
17 #define SPL_HEADER_SIZE 16
18 #define FILE_PERM (S_IRUSR | S_IWUSR | S_IRGRP \
19 | S_IWGRP | S_IROTH | S_IWOTH)
20 #define SPL_HEADER "S5PC210 HEADER "
23 * IROM code reads first 14K bytes from boot device.
24 * It then calculates the checksum of 14K-4 bytes and compare with data at
27 * This function takes two filenames:
28 * IN "u-boot-spl.bin" and
29 * OUT "$(BOARD)-spl.bin as filenames.
30 * It reads the "u-boot-spl.bin" in 16K buffer.
31 * It calculates checksum of 14K-4 Bytes and stores at 14K-4 offset in buffer.
32 * It writes the buffer to "$(BOARD)-spl.bin" file.
35 int main(int argc, char **argv)
38 unsigned char buffer[BUFSIZE] = {0};
40 unsigned int checksum = 0, count;
43 printf(" %d Wrong number of arguments\n", argc);
47 ifd = open(argv[1], O_RDONLY);
49 fprintf(stderr, "%s: Can't open %s: %s\n",
50 argv[0], argv[1], strerror(errno));
54 ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
56 fprintf(stderr, "%s: Can't open %s: %s\n",
57 argv[0], argv[2], strerror(errno));
63 len = lseek(ifd, 0, SEEK_END);
64 lseek(ifd, 0, SEEK_SET);
66 memcpy(&buffer[0], SPL_HEADER, SPL_HEADER_SIZE);
68 count = (len < (IMG_SIZE - SPL_HEADER_SIZE))
69 ? len : (IMG_SIZE - SPL_HEADER_SIZE);
71 if (read(ifd, buffer + SPL_HEADER_SIZE, count) != count) {
72 fprintf(stderr, "%s: Can't read %s: %s\n",
73 argv[0], argv[1], strerror(errno));
83 for (i = 0; i < IMG_SIZE - SPL_HEADER_SIZE; i++)
84 checksum += buffer[i+16];
86 *(ulong *)buffer ^= 0x1f;
87 *(ulong *)(buffer+4) ^= checksum;
89 for (i = 1; i < SPL_HEADER_SIZE; i++)
90 buffer[i] ^= buffer[i-1];
92 if (write(ofd, buffer, BUFSIZE) != BUFSIZE) {
93 fprintf(stderr, "%s: Can't write %s: %s\n",
94 argv[0], argv[2], strerror(errno));