Skip to content

Commit a2d63ed

Browse files
bjzhjingrbradford
authored andcommitted
loader: Add elf and bzimage features
Add feature setting to separate elf and bzImage support, which will make convenience for VMM to select loader type based on its needs. Signed-off-by: Cathy Zhang <cathy.zhang@intel.com>
1 parent 5be96c6 commit a2d63ed

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

.buildkite/pipeline.yml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,55 @@ steps:
3434
privileged: true
3535
image: "rustvmm/dev:v2"
3636
always-pull: true
37-
37+
38+
- label: "build-gnu-x86-elf"
39+
commands:
40+
- cargo build --release --features elf
41+
retry:
42+
automatic: false
43+
agents:
44+
platform: x86_64.metal
45+
plugins:
46+
- docker#v3.0.1:
47+
image: "rustvmm/dev:v2"
48+
always-pull: true
49+
50+
- label: "unittests-gnu-x86-elf"
51+
commands:
52+
- cargo test --features elf
53+
retry:
54+
automatic: false
55+
agents:
56+
platform: x86_64.metal
57+
plugins:
58+
- docker#v3.0.1:
59+
privileged: true
60+
image: "rustvmm/dev:v2"
61+
62+
- label: "build-gnu-x86-bzimage"
63+
commands:
64+
- cargo build --release --features bzimage
65+
retry:
66+
automatic: false
67+
agents:
68+
platform: x86_64.metal
69+
plugins:
70+
- docker#v3.0.1:
71+
image: "rustvmm/dev:v2"
72+
always-pull: true
73+
74+
- label: "unittests-gnu-x86-bzimage"
75+
commands:
76+
- cargo test --features bzimage
77+
retry:
78+
automatic: false
79+
agents:
80+
platform: x86_64.metal
81+
plugins:
82+
- docker#v3.0.1:
83+
privileged: true
84+
image: "rustvmm/dev:v2"
85+
3886
- label: "clippy-x86"
3987
commands:
4088
- cargo clippy --all -- -D warnings

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ authors = ["Cathy Zhang <cathy.zhang@intel.com>"]
55
edition = "2018"
66
license = "Apache-2.0 AND BSD-3-Clause"
77

8+
[features]
9+
default = ["elf"]
10+
elf = []
11+
bzimage = []
12+
813
[dependencies.vm-memory]
914
git = "https://github.com/rust-vmm/vm-memory"
1015
features = ["backend-mmap"]

src/loader/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ pub trait KernelLoader {
131131
F: Read + Seek;
132132
}
133133

134+
#[cfg(feature = "elf")]
134135
pub struct Elf;
135136

137+
#[cfg(feature = "elf")]
136138
impl KernelLoader for Elf {
137139
/// Loads a kernel from a vmlinux elf image to a slice
138140
///
@@ -240,8 +242,10 @@ impl KernelLoader for Elf {
240242
}
241243
}
242244

245+
#[cfg(feature = "bzimage")]
243246
pub struct BzImage;
244247

248+
#[cfg(feature = "bzimage")]
245249
impl KernelLoader for BzImage {
246250
/// Loads a bzImage
247251
///
@@ -377,13 +381,15 @@ mod test {
377381
}
378382

379383
#[allow(non_snake_case)]
384+
#[cfg(feature = "bzimage")]
380385
fn make_bzImage() -> Vec<u8> {
381386
let mut v = Vec::new();
382387
v.extend_from_slice(include_bytes!("bzimage"));
383388
v
384389
}
385390

386391
// Elf64 image that prints hello world on x86_64.
392+
#[cfg(feature = "elf")]
387393
fn make_elf_bin() -> Vec<u8> {
388394
let mut v = Vec::new();
389395
v.extend_from_slice(include_bytes!("test_elf.bin"));
@@ -393,6 +399,7 @@ mod test {
393399
#[allow(safe_packed_borrows)]
394400
#[allow(non_snake_case)]
395401
#[test]
402+
#[cfg(feature = "bzimage")]
396403
fn load_bzImage() {
397404
let gm = create_guest_mem();
398405
let image = make_bzImage();
@@ -461,6 +468,7 @@ mod test {
461468
}
462469

463470
#[test]
471+
#[cfg(feature = "elf")]
464472
fn load_elf() {
465473
let gm = create_guest_mem();
466474
let image = make_elf_bin();
@@ -550,6 +558,7 @@ mod test {
550558
assert_eq!(val, '\0' as u8);
551559
}
552560

561+
#[cfg(feature = "elf")]
553562
#[test]
554563
fn bad_magic() {
555564
let gm = create_guest_mem();
@@ -562,6 +571,7 @@ mod test {
562571
);
563572
}
564573

574+
#[cfg(feature = "elf")]
565575
#[test]
566576
fn bad_endian() {
567577
// Only little endian is supported
@@ -575,6 +585,7 @@ mod test {
575585
);
576586
}
577587

588+
#[cfg(feature = "elf")]
578589
#[test]
579590
fn bad_phoff() {
580591
// program header has to be past the end of the elf header

0 commit comments

Comments
 (0)