3 * Heiko Schocher, DENX Software Engineering, <hs@denx.de>
5 * SPDX-License-Identifier: GPL-2.0+
8 #include "os_support.h"
18 int main (int argc, char **argv)
20 unsigned char output[20];
24 char *cmdname = *argv;
28 unsigned char *ptroff;
34 ifd = open (imagefile, O_RDWR|O_BINARY);
36 fprintf (stderr, "%s: Can't open %s: %s\n",
37 cmdname, imagefile, strerror(errno));
40 if (fstat (ifd, &sbuf) < 0) {
41 fprintf (stderr, "%s: Can't stat %s: %s\n",
42 cmdname, imagefile, strerror(errno));
46 ptr = (unsigned char *)mmap(0, len,
47 PROT_READ, MAP_SHARED, ifd, 0);
48 if (ptr == (unsigned char *)MAP_FAILED) {
49 fprintf (stderr, "%s: Can't read %s: %s\n",
50 cmdname, imagefile, strerror(errno));
54 /* create a copy, so we can blank out the sha1 sum */
56 memcpy (data, ptr, len);
58 ptroff = &data[len + off];
59 for (i = 0; i < SHA1_SUM_LEN; i++) {
63 sha1_csum ((unsigned char *) data, len, (unsigned char *)output);
65 printf ("U-Boot sum:\n");
66 for (i = 0; i < 20 ; i++) {
67 printf ("%02X ", output[i]);
70 /* overwrite the sum in the bin file, with the actual */
71 lseek (ifd, SHA1_SUM_POS, SEEK_END);
72 if (write (ifd, output, SHA1_SUM_LEN) != SHA1_SUM_LEN) {
73 fprintf (stderr, "%s: Can't write %s: %s\n",
74 cmdname, imagefile, strerror(errno));
79 (void) munmap((void *)ptr, len);