Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] Make the bzImage format self-terminating

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Frank Sorenson <frank@tuxrocks.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

H. Peter Anvin and committed by
Linus Torvalds
f8eeaaf4 5e1efe49

+30 -17
+22 -13
Documentation/i386/boot.txt
··· 2 2 ---------------------------- 3 3 4 4 H. Peter Anvin <hpa@zytor.com> 5 - Last update 2002-01-01 5 + Last update 2005-09-02 6 6 7 7 On the i386 platform, the Linux kernel uses a rather complicated boot 8 8 convention. This has evolved partially due to historical aspects, as ··· 33 33 34 34 Protocol 2.03: (Kernel 2.4.18-pre1) Explicitly makes the highest possible 35 35 initrd address available to the bootloader. 36 + 37 + Protocol 2.04: (Kernel 2.6.14) Extend the syssize field to four bytes. 36 38 37 39 38 40 **** MEMORY LAYOUT ··· 105 103 Offset Proto Name Meaning 106 104 /Size 107 105 108 - 01F1/1 ALL setup_sects The size of the setup in sectors 106 + 01F1/1 ALL(1 setup_sects The size of the setup in sectors 109 107 01F2/2 ALL root_flags If set, the root is mounted readonly 110 - 01F4/2 ALL syssize DO NOT USE - for bootsect.S use only 111 - 01F6/2 ALL swap_dev DO NOT USE - obsolete 108 + 01F4/4 2.04+(2 syssize The size of the 32-bit code in 16-byte paras 112 109 01F8/2 ALL ram_size DO NOT USE - for bootsect.S use only 113 110 01FA/2 ALL vid_mode Video mode control 114 111 01FC/2 ALL root_dev Default root device number ··· 130 129 0228/4 2.02+ cmd_line_ptr 32-bit pointer to the kernel command line 131 130 022C/4 2.03+ initrd_addr_max Highest legal initrd address 132 131 133 - For backwards compatibility, if the setup_sects field contains 0, the 134 - real value is 4. 132 + (1) For backwards compatibility, if the setup_sects field contains 0, the 133 + real value is 4. 134 + 135 + (2) For boot protocol prior to 2.04, the upper two bytes of the syssize 136 + field are unusable, which means the size of a bzImage kernel 137 + cannot be determined. 135 138 136 139 If the "HdrS" (0x53726448) magic number is not found at offset 0x202, 137 140 the boot protocol version is "old". Loading an old kernel, the ··· 235 230 relevant to the boot loader itself, see "special command line options" 236 231 below. 237 232 238 - The kernel command line is a null-terminated string up to 255 239 - characters long, plus the final null. 233 + The kernel command line is a null-terminated string currently up to 234 + 255 characters long, plus the final null. A string that is too long 235 + will be automatically truncated by the kernel, a boot loader may allow 236 + a longer command line to be passed to permit future kernels to extend 237 + this limit. 240 238 241 239 If the boot protocol version is 2.02 or later, the address of the 242 240 kernel command line is given by the header field cmd_line_ptr (see 243 - above.) 241 + above.) This address can be anywhere between the end of the setup 242 + heap and 0xA0000. 244 243 245 244 If the protocol version is *not* 2.02 or higher, the kernel 246 245 command line is entered using the following protocol: ··· 264 255 **** SAMPLE BOOT CONFIGURATION 265 256 266 257 As a sample configuration, assume the following layout of the real 267 - mode segment: 258 + mode segment (this is a typical, and recommended layout): 268 259 269 260 0x0000-0x7FFF Real mode kernel 270 261 0x8000-0x8FFF Stack and heap ··· 321 312 322 313 **** LOADING THE REST OF THE KERNEL 323 314 324 - The non-real-mode kernel starts at offset (setup_sects+1)*512 in the 325 - kernel file (again, if setup_sects == 0 the real value is 4.) It 326 - should be loaded at address 0x10000 for Image/zImage kernels and 315 + The 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512 316 + in the kernel file (again, if setup_sects == 0 the real value is 4.) 317 + It should be loaded at address 0x10000 for Image/zImage kernels and 327 318 0x100000 for bzImage kernels. 328 319 329 320 The kernel is a bzImage kernel if the protocol >= 2.00 and the 0x01
+1 -1
arch/i386/boot/setup.S
··· 82 82 # This is the setup header, and it must start at %cs:2 (old 0x9020:2) 83 83 84 84 .ascii "HdrS" # header signature 85 - .word 0x0203 # header version number (>= 0x0105) 85 + .word 0x0204 # header version number (>= 0x0105) 86 86 # or else old loadlin-1.5 will fail) 87 87 realmode_swtch: .word 0, 0 # default_switch, SETUPSEG 88 88 start_sys_seg: .word SYSSEG
+3 -1
arch/i386/boot/tools/build.c
··· 177 177 die("Output: seek failed"); 178 178 buf[0] = (sys_size & 0xff); 179 179 buf[1] = ((sys_size >> 8) & 0xff); 180 - if (write(1, buf, 2) != 2) 180 + buf[2] = ((sys_size >> 16) & 0xff); 181 + buf[3] = ((sys_size >> 24) & 0xff); 182 + if (write(1, buf, 4) != 4) 181 183 die("Write of image length failed"); 182 184 183 185 return 0; /* Everything is OK */
+1 -1
arch/x86_64/boot/setup.S
··· 81 81 # This is the setup header, and it must start at %cs:2 (old 0x9020:2) 82 82 83 83 .ascii "HdrS" # header signature 84 - .word 0x0203 # header version number (>= 0x0105) 84 + .word 0x0204 # header version number (>= 0x0105) 85 85 # or else old loadlin-1.5 will fail) 86 86 realmode_swtch: .word 0, 0 # default_switch, SETUPSEG 87 87 start_sys_seg: .word SYSSEG
+3 -1
arch/x86_64/boot/tools/build.c
··· 178 178 die("Output: seek failed"); 179 179 buf[0] = (sys_size & 0xff); 180 180 buf[1] = ((sys_size >> 8) & 0xff); 181 - if (write(1, buf, 2) != 2) 181 + buf[2] = ((sys_size >> 16) & 0xff); 182 + buf[3] = ((sys_size >> 24) & 0xff); 183 + if (write(1, buf, 4) != 4) 182 184 die("Write of image length failed"); 183 185 184 186 return 0; /* Everything is OK */