Skip to content

Commit 02a04c0

Browse files
bjzhjingrbradford
authored andcommitted
loader: Add bzImage support
Reimplement KernelLoader trait against structure BzImage to add bzImage loader support. Signed-off-by: Cathy Zhang <cathy.zhang@intel.com>
1 parent e983c6a commit 02a04c0

File tree

4 files changed

+4137
-4
lines changed

4 files changed

+4137
-4
lines changed

DESIGN.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,58 @@ be used to fill boot parameters, vmm is totally responsible for the construction
3535

3636
- GDT must be configured and loaded
3737

38+
# bzImage
39+
40+
The boot process is also explained from the following two sides.
41+
42+
## Loader side
43+
44+
### What will be returned from loader
45+
46+
bzImage includes two parts, the setup and the compressed kernel. The compressed
47+
kernel part will be loaded into guest memory, and the following three parts
48+
will be returned to the VMM by the loader.
49+
50+
- The start address of loaded kernel
51+
52+
- The offset of memory where kernel is end of loading
53+
54+
- The setup header begin at the offset 0x01f1 of bzImage, this one is an extra
55+
compared to the return of ELF loader.
56+
57+
### Where kernel is loaded
58+
59+
The same as ELF image loader, there are two ways for deciding where the
60+
compressed kernel will be loaded.
61+
62+
- VMM specify where to load kernel image.
63+
64+
- Load into code32_start (Boot load address) by default.
65+
66+
### Additional checking
67+
68+
As what the boot protocol said, the kernel is a bzImage kernel if the
69+
protocol >= 2.00 and the 0x01 bit(LOAD_HIGH) is the loadflags field is set. Add
70+
this checking to validate the bzImage.
71+
72+
## VMM side
73+
74+
### Construct zero page
75+
76+
While vmm build "zero page" with e820 table and other stuff, bzImage loader will
77+
return the setup header to fill the boot parameters. Meanwhile,
78+
setup_header.init_size is a must to be filled into zero page, which will be used
79+
during head_64.S boot process.
80+
81+
### Configure vCPU
82+
83+
- RIP, the start address of loaded 64-bit kernel returned from loader + 0x200.
84+
Regarding to the 64-bit boot protocol, kernel is started by jumping to the
85+
64-bit kernel entry point, which is the start address of loaded 64-bit kernel
86+
plus 0x200.
87+
88+
- 64 bit mode with paging enabled
89+
90+
- GDT must be configured and loaded
91+
3892

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,29 @@ cd linux-loader
1313
cargo build
1414
```
1515

16-
## How to run test
16+
## How to run test for Elf loader
1717

18+
```shell
19+
# Assuming your linux-loader is under $HOME
20+
$ cd linux-loader
21+
$ cargo test
22+
$ cargo test -- --nocapture
1823
```
19-
cd linux-loader
20-
cargo test
21-
cargo test -- --nocapture
24+
25+
## How to run test for bzImage loader
26+
27+
As we don't want to distribute an entire kernel bzImage, the `load_bzImage` test is ignored by
28+
default. In order to test the bzImage support, one needs to locally build a bzImage, copy it
29+
to the `src/loader` directory and run the ignored test:
30+
31+
```shell
32+
# Assuming your linux-loader and linux-stable are both under $LINUX_LOADER
33+
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git $LINUX_LOADER/linux-stable
34+
$ cd linux-stable
35+
$ make bzImage
36+
$ cp linux-stable/arch/x86/boot/bzImage $LINUX_LOADER/linux-loader/src/loader/
37+
$ cd $LINUX_LOADER/linux-loader
38+
$ cargo test -- --ignored
2239
```
2340

2441
## Platform Support

0 commit comments

Comments
 (0)