3 * Heiko Schocher, DENX Software Engineering, <hs@denx.de>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 #include "os_support.h"
35 #define __ASSEMBLY__ /* Dirty trick to get only #defines */
40 extern void sha1_csum (unsigned char *input, int ilen, unsigned char output[20]);
42 int main (int argc, char **argv)
44 unsigned char output[20];
48 char *cmdname = *argv;
52 unsigned char *ptroff;
58 ifd = open (imagefile, O_RDWR|O_BINARY);
60 fprintf (stderr, "%s: Can't open %s: %s\n",
61 cmdname, imagefile, strerror(errno));
64 if (fstat (ifd, &sbuf) < 0) {
65 fprintf (stderr, "%s: Can't stat %s: %s\n",
66 cmdname, imagefile, strerror(errno));
70 ptr = (unsigned char *)mmap(0, len,
71 PROT_READ, MAP_SHARED, ifd, 0);
72 if (ptr == (unsigned char *)MAP_FAILED) {
73 fprintf (stderr, "%s: Can't read %s: %s\n",
74 cmdname, imagefile, strerror(errno));
78 /* create a copy, so we can blank out the sha1 sum */
80 memcpy (data, ptr, len);
82 ptroff = &data[len + off];
83 for (i = 0; i < SHA1_SUM_LEN; i++) {
87 sha1_csum ((unsigned char *) data, len, (unsigned char *)output);
89 printf ("U-Boot sum:\n");
90 for (i = 0; i < 20 ; i++) {
91 printf ("%02X ", output[i]);
94 /* overwrite the sum in the bin file, with the actual */
95 lseek (ifd, SHA1_SUM_POS, SEEK_END);
96 if (write (ifd, output, SHA1_SUM_LEN) != SHA1_SUM_LEN) {
97 fprintf (stderr, "%s: Can't write %s: %s\n",
98 cmdname, imagefile, strerror(errno));
103 (void) munmap((void *)ptr, len);