mktree.c (7eef4091a653c243a87e5375c54504cc03bec4d8) mktree.c (3c15a68880023722fc794018768df556f438ae98)
1/*
2 * Makes a tree bootable image for IBM Evaluation boards.
3 * Basically, just take a zImage, skip the ELF header, and stuff
4 * a 32 byte header on the front.
5 *
6 * We use htonl, which is a network macro, to make sure we're doing
7 * The Right Thing on an LE machine. It's non-obvious, but it should
8 * work on anything BSD'ish.

--- 22 unchanged lines hidden (view full) ---

31 uint32_t bb_num_512blocks; /* Size, rounded-up, in 512 byte blks */
32 uint32_t bb_debug_flag; /* Run debugger or image after load */
33 uint32_t bb_entry_point; /* The image address to start */
34 uint32_t bb_checksum; /* 32 bit checksum including header */
35 uint32_t reserved[2];
36} boot_block_t;
37
38#define IMGBLK 512
1/*
2 * Makes a tree bootable image for IBM Evaluation boards.
3 * Basically, just take a zImage, skip the ELF header, and stuff
4 * a 32 byte header on the front.
5 *
6 * We use htonl, which is a network macro, to make sure we're doing
7 * The Right Thing on an LE machine. It's non-obvious, but it should
8 * work on anything BSD'ish.

--- 22 unchanged lines hidden (view full) ---

31 uint32_t bb_num_512blocks; /* Size, rounded-up, in 512 byte blks */
32 uint32_t bb_debug_flag; /* Run debugger or image after load */
33 uint32_t bb_entry_point; /* The image address to start */
34 uint32_t bb_checksum; /* 32 bit checksum including header */
35 uint32_t reserved[2];
36} boot_block_t;
37
38#define IMGBLK 512
39char tmpbuf[IMGBLK];
39unsigned int tmpbuf[IMGBLK / sizeof(unsigned int)];
40
41int main(int argc, char *argv[])
42{
43 int in_fd, out_fd;
44 int nblks, i;
45 unsigned int cksum, *cp;
46 struct stat st;
47 boot_block_t bt;

--- 42 unchanged lines hidden (view full) ---

90
91 cksum = 0;
92 cp = (void *)&bt;
93 for (i = 0; i < sizeof(bt) / sizeof(unsigned int); i++)
94 cksum += *cp++;
95
96 /* Assume zImage is an ELF file, and skip the 64K header.
97 */
40
41int main(int argc, char *argv[])
42{
43 int in_fd, out_fd;
44 int nblks, i;
45 unsigned int cksum, *cp;
46 struct stat st;
47 boot_block_t bt;

--- 42 unchanged lines hidden (view full) ---

90
91 cksum = 0;
92 cp = (void *)&bt;
93 for (i = 0; i < sizeof(bt) / sizeof(unsigned int); i++)
94 cksum += *cp++;
95
96 /* Assume zImage is an ELF file, and skip the 64K header.
97 */
98 if (read(in_fd, tmpbuf, IMGBLK) != IMGBLK) {
98 if (read(in_fd, tmpbuf, sizeof(tmpbuf)) != sizeof(tmpbuf)) {
99 fprintf(stderr, "%s is too small to be an ELF image\n",
100 argv[1]);
101 exit(4);
102 }
103
99 fprintf(stderr, "%s is too small to be an ELF image\n",
100 argv[1]);
101 exit(4);
102 }
103
104 if ((*(unsigned int *)tmpbuf) != htonl(0x7f454c46)) {
104 if (tmpbuf[0] != htonl(0x7f454c46)) {
105 fprintf(stderr, "%s is not an ELF image\n", argv[1]);
106 exit(4);
107 }
108
109 if (lseek(in_fd, (64 * 1024), SEEK_SET) < 0) {
110 fprintf(stderr, "%s failed to seek in ELF image\n", argv[1]);
111 exit(4);
112 }
113
114 nblks -= (64 * 1024) / IMGBLK;
115
116 /* And away we go......
117 */
118 if (write(out_fd, &bt, sizeof(bt)) != sizeof(bt)) {
119 perror("boot-image write");
120 exit(5);
121 }
122
123 while (nblks-- > 0) {
105 fprintf(stderr, "%s is not an ELF image\n", argv[1]);
106 exit(4);
107 }
108
109 if (lseek(in_fd, (64 * 1024), SEEK_SET) < 0) {
110 fprintf(stderr, "%s failed to seek in ELF image\n", argv[1]);
111 exit(4);
112 }
113
114 nblks -= (64 * 1024) / IMGBLK;
115
116 /* And away we go......
117 */
118 if (write(out_fd, &bt, sizeof(bt)) != sizeof(bt)) {
119 perror("boot-image write");
120 exit(5);
121 }
122
123 while (nblks-- > 0) {
124 if (read(in_fd, tmpbuf, IMGBLK) < 0) {
124 if (read(in_fd, tmpbuf, sizeof(tmpbuf)) < 0) {
125 perror("zImage read");
126 exit(5);
127 }
125 perror("zImage read");
126 exit(5);
127 }
128 cp = (unsigned int *)tmpbuf;
128 cp = tmpbuf;
129 for (i = 0; i < sizeof(tmpbuf) / sizeof(unsigned int); i++)
130 cksum += *cp++;
131 if (write(out_fd, tmpbuf, sizeof(tmpbuf)) != sizeof(tmpbuf)) {
132 perror("boot-image write");
133 exit(5);
134 }
135 }
136

--- 14 unchanged lines hidden ---
129 for (i = 0; i < sizeof(tmpbuf) / sizeof(unsigned int); i++)
130 cksum += *cp++;
131 if (write(out_fd, tmpbuf, sizeof(tmpbuf)) != sizeof(tmpbuf)) {
132 perror("boot-image write");
133 exit(5);
134 }
135 }
136

--- 14 unchanged lines hidden ---