Ajay Dudani | a66de4f | 2009-11-22 08:57:39 -0800 | [diff] [blame^] | 1 | /* Copyright 2007, Google Inc. */ |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <unistd.h> |
| 6 | #include <fcntl.h> |
| 7 | |
| 8 | #include <sys/stat.h> |
| 9 | |
| 10 | int main(int argc, char *argv[]) |
| 11 | { |
| 12 | struct stat s; |
| 13 | unsigned size, base; |
| 14 | unsigned magic[10]; |
| 15 | int fd; |
| 16 | |
| 17 | if(argc != 3) { |
| 18 | fprintf(stderr,"usage: mkheader <bin> <hdr>\n"); |
| 19 | return -1; |
| 20 | } |
| 21 | |
| 22 | if(stat(argv[1], &s)) { |
| 23 | perror("cannot stat binary"); |
| 24 | return -1; |
| 25 | } |
| 26 | |
| 27 | size = s.st_size; |
| 28 | base = 0; |
| 29 | |
| 30 | magic[0] = 0x00000005; /* appsbl */ |
| 31 | magic[1] = 0x00000002; /* nand */ |
| 32 | magic[2] = 0x00000000; |
| 33 | magic[3] = base; |
| 34 | magic[4] = size; |
| 35 | magic[5] = size; |
| 36 | magic[6] = size + base; |
| 37 | magic[7] = 0x00000000; |
| 38 | magic[8] = size + base; |
| 39 | magic[9] = 0x00000000; |
| 40 | |
| 41 | fd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644); |
| 42 | if(fd < 0) { |
| 43 | perror("cannot open header for writing"); |
| 44 | return -1; |
| 45 | } |
| 46 | if(write(fd, magic, sizeof(magic)) != sizeof(magic)) { |
| 47 | perror("cannot write header"); |
| 48 | close(fd); |
| 49 | unlink(argv[2]); |
| 50 | return -1; |
| 51 | } |
| 52 | close(fd); |
| 53 | |
| 54 | return 0; |
| 55 | } |