1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2011 Samsung Electronics
14 #define BUFSIZE (16*1024)
15 #define IMG_SIZE (16*1024)
16 #define SPL_HEADER_SIZE 16
17 #define FILE_PERM (S_IRUSR | S_IWUSR | S_IRGRP \
18 | S_IWGRP | S_IROTH | S_IWOTH)
19 #define SPL_HEADER "S5PC210 HEADER "
22 * IROM code reads first 14K bytes from boot device.
23 * It then calculates the checksum of 14K-4 bytes and compare with data at
26 * This function takes two filenames:
27 * IN "u-boot-spl.bin" and
28 * OUT "$(BOARD)-spl.bin as filenames.
29 * It reads the "u-boot-spl.bin" in 16K buffer.
30 * It calculates checksum of 14K-4 Bytes and stores at 14K-4 offset in buffer.
31 * It writes the buffer to "$(BOARD)-spl.bin" file.
34 int main(int argc, char **argv)
37 unsigned char buffer[BUFSIZE] = {0};
39 unsigned int checksum = 0, count;
42 printf(" %d Wrong number of arguments\n", argc);
46 ifd = open(argv[1], O_RDONLY);
48 fprintf(stderr, "%s: Can't open %s: %s\n",
49 argv[0], argv[1], strerror(errno));
53 ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
55 fprintf(stderr, "%s: Can't open %s: %s\n",
56 argv[0], argv[2], strerror(errno));
62 len = lseek(ifd, 0, SEEK_END);
63 lseek(ifd, 0, SEEK_SET);
65 memcpy(&buffer[0], SPL_HEADER, SPL_HEADER_SIZE);
67 count = (len < (IMG_SIZE - SPL_HEADER_SIZE))
68 ? len : (IMG_SIZE - SPL_HEADER_SIZE);
70 if (read(ifd, buffer + SPL_HEADER_SIZE, count) != count) {
71 fprintf(stderr, "%s: Can't read %s: %s\n",
72 argv[0], argv[1], strerror(errno));
82 for (i = 0; i < IMG_SIZE - SPL_HEADER_SIZE; i++)
83 checksum += buffer[i+16];
85 *(unsigned long *)buffer ^= 0x1f;
86 *(unsigned long *)(buffer+4) ^= checksum;
88 for (i = 1; i < SPL_HEADER_SIZE; i++)
89 buffer[i] ^= buffer[i-1];
91 if (write(ofd, buffer, BUFSIZE) != BUFSIZE) {
92 fprintf(stderr, "%s: Can't write %s: %s\n",
93 argv[0], argv[2], strerror(errno));