direct-io.hg

view tools/misc/mbootpack/buildimage.c @ 7477:5a7baecb1c70

Fix an issue for passing arguement from control panel to deivce model
for some arguemnt like 'localtime', 'isa', device model need an argument
"-localtime", instead of "-localtime 1"
Signed-off-by: Xiaofeng Ling <xiaofeng.ling@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Sun Oct 23 16:51:47 2005 +0100 (2005-10-23)
parents 06d84bf87159
children 2e58022889a5
line source
1 /*
2 * buildimage.c
3 *
4 * Takes the memory image of a loaded kernel and modules and repackages
5 * it as a linux bzImage
6 *
7 * Copyright (C) 2003-2004 Tim Deegan (tjd21@cl.cam.ac.uk)
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 * 02111-1307, USA.
23 *
24 * $Id: buildimage.c,v 1.2 2005/03/23 10:39:19 tjd21 Exp $
25 *
26 */
30 #include <assert.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <errno.h>
34 #include <string.h>
35 #include <getopt.h>
36 #include <elf.h>
37 #include <unistd.h>
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <sys/mman.h>
41 #include <asm/page.h>
43 #include "mbootpack.h"
44 #include "mb_header.h"
47 /* We will build an image that a bzImage-capable bootloader will load like
48 * this:
49 *
50 * ============== (0)
51 * (BIOS memory)
52 * --------------
53 * (Bootloader)
54 * --------------
55 * bzImage startup code
56 * MBI, command-lines, module info
57 * ============== (0xa0000)
58 * (memory hole)
59 * ============== (0x100000)
60 * Kernel and modules
61 * ==============
62 *
63 * The bzImage startup code is mostly taken straight from the linux kernel
64 * (see bootsect.S, startup.S). It does the usual unpleasant start-of-day
65 * tasks to get to 32-bit protected mode, then sets registers appropriately
66 * and jumps to the kernel's entry address.
67 *
68 * It also does some relocation to make sure the MBI is where we expect it,
69 * and parses the linux command line.
70 */
72 #define BZ_SETUP_OFFSET (512 * (1 + SETUPSECTS))
73 #define BZ_ENTRY_OFFSET 0x30
74 #define BZ_MBI_OFFSET 0x34
75 /* These *MUST* fit the offsets of entry_address and mbi_address in setup.S */
77 /* Bring in the bzImage boot sector and setup code */
78 #include "bzimage_header.c"
80 address_t place_mbi(long int size)
81 /* Find space at the top of *low* memory for the MBI and associated red tape */
82 {
83 address_t start;
84 start = 0xa000 - size;
85 if (start < 0x9000 + sizeof(bzimage_bootsect) + sizeof(bzimage_setup)) {
86 printf("Fatal: command-lines too long: need %i, have %i bytes\n",
87 size,
88 0x1000 - (sizeof(bzimage_bootsect) + sizeof(bzimage_setup)));
89 exit(1);
90 }
91 if (!quiet) {
92 printf("Placed MBI and strings (%p+%p)\n",
93 start, size);
94 }
95 return start;
96 }
98 void make_bzImage(section_t *sections,
99 address_t entry,
100 address_t mbi,
101 FILE *fp)
102 /* Rework this list of sections into a bzImage and write it out to fp */
103 {
104 int i;
105 size_t offset;
106 section_t *s;
108 /* Patch the kernel and mbi addresses into the setup code */
109 *(address_t *)(bzimage_setup + BZ_ENTRY_OFFSET) = eswap(entry);
110 *(address_t *)(bzimage_setup + BZ_MBI_OFFSET) = eswap(mbi);
111 if (!quiet) printf("Kernel entry is %p, MBI is %p.\n", entry, mbi);
113 /* Write out header and trampoline */
114 if (fseek(fp, 0, SEEK_SET) < 0) {
115 printf("Fatal: error seeking in output file: %s\n",
116 strerror(errno));
117 exit(1);
118 }
119 if (fwrite(bzimage_bootsect, sizeof(bzimage_bootsect), 1, fp) != 1) {
120 printf("Fatal: error writing to output file: %s\n",
121 strerror(errno));
122 exit(1);
123 }
124 if (fwrite(bzimage_setup, sizeof(bzimage_setup), 1, fp) != 1) {
125 printf("Fatal: error writing to output file: %s\n",
126 strerror(errno));
127 exit(1);
128 }
130 if (!quiet) printf("Wrote bzImage header: %i + %i bytes.\n",
131 sizeof(bzimage_bootsect), sizeof(bzimage_setup));
133 /* Sorted list of sections below 1MB: write them out */
134 for (s = sections, i = 0; s; s = s->next) {
135 if (s->start >= HIGHMEM_START) continue;
136 offset = (s->start - 0x9000);
137 if (fseek(fp, offset, SEEK_SET) < 0) {
138 printf("Fatal: error seeking in output file: %s\n",
139 strerror(errno));
140 exit(1);
141 }
142 if (fwrite(s->buffer, s->size, 1, fp) != 1) {
143 printf("Fatal: error writing to output file: %s\n",
144 strerror(errno));
145 exit(1);
146 }
147 i++;
148 }
150 if (!quiet) printf("Wrote %i low-memory sections.\n", i);
152 /* Sorted list of sections higher than 1MB: write them out */
153 for (s = sections, i = 0; s; s = s->next) {
154 if (s->start < HIGHMEM_START) continue;
155 offset = (s->start - HIGHMEM_START) + BZ_SETUP_OFFSET;
156 if (fseek(fp, offset, SEEK_SET) < 0) {
157 printf("Fatal: error seeking in output file: %s\n",
158 strerror(errno));
159 exit(1);
160 }
161 if (fwrite(s->buffer, s->size, 1, fp) != 1) {
162 printf("Fatal: error writing to output file: %s\n",
163 strerror(errno));
164 exit(1);
165 }
166 i++;
167 }
169 if (!quiet) printf("Wrote %i high-memory sections.\n", i);
170 }
173 /*
174 * EOF(buildimage.c)
175 */