-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile.toml
157 lines (142 loc) · 10.9 KB
/
Makefile.toml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
[config]
skip_core_tasks = true
reduce_output = true
[tasks.default]
run_task = { name = ["format", "build"] }
[tasks.update_pciids]
script_runner = "@rust"
script='''
//!```cargo
//![dependencies]
//!compression={version = "*", features=["gzip"]}
//!blake3={version = "*", features=["rayon"]}
//!curl="*"
//!```
use curl::easy::Easy;
use compression::prelude::*;
use blake3::*;
use std::fs::{read, write};
use std::path::Path;
fn main() {
println!("Checking for PCI ID repository");
let mut bytes = Vec::new();
let path = format!("{}/libk/pci.ids.gz", env!("CARGO_MAKE_WORKING_DIRECTORY"));
let path = path.as_str();
if Path::new(path.clone()).exists() {
println!("Found existing PCI IDs repository");
let current_repo = read(path).expect("Cannot open existing PCI IDs repository").iter().cloned().decode(&mut GZipDecoder::new()).collect::<Result<Vec<_>, _>>().expect("Cannot decompress existing PCI IDs repository");
println!("Existing PCI IDs repository is {} bytes", current_repo.len());
println!("Checking for PCI ID repository updates");
let mut easy = Easy::new();
easy.url("https://pci-ids.ucw.cz/v2.2/pci.ids.gz").expect("Cannot set URL of curl easy instance");
{
let mut transfer = easy.transfer();
transfer.write_function(|data| {
bytes.extend_from_slice(data);
Ok(data.len())
}).expect("Cannot set write function for download");
transfer.perform().expect("Cannot download PCI IDs repository");
}
let new_bytes = bytes.iter().cloned().decode(&mut GZipDecoder::new()).collect::<Result<Vec<_>, _>>().expect("Cannot decompress new repository bytes");
println!("Latest PCI IDs repository is {} bytes", new_bytes.len());
let mut hasher1 = Hasher::new();
let mut hasher2 = Hasher::new();
hasher1.update_rayon(&new_bytes);
hasher2.update_rayon(¤t_repo);
let new_hash = hasher1.finalize();
let current_hash = hasher2.finalize();
if current_hash != new_hash {
println!("PCI IDs repository updated, dumping ({} bytes)", bytes.len());
write(path.clone(), bytes.clone()).expect("Cannot dump new PCI IDs repository");
println!("New hash: {}", new_hash.to_hex());
println!("Was: {}", current_hash.to_hex());
} else {
println!("PCI IDs repository is up to date");
println!("Hash: {}", current_hash.to_hex());
}
} else {
println!("Downloading latest PCI IDs repository because it does not already exist");
let mut easy = Easy::new();
easy.url("https://pci-ids.ucw.cz/v2.2/pci.ids.gz").expect("Cannot set URL of curl easy instance");
{
let mut transfer = easy.transfer();
transfer.write_function(|data| {
bytes.extend_from_slice(data);
Ok(data.len())
}).expect("Cannot set write function for download");
transfer.perform().expect("Cannot download PCI IDs repository");
}
write(path.clone(), bytes.clone()).expect("Cannot dump new PCI IDs repository");
let decompressed_bytes = bytes.iter().cloned().decode(&mut GZipDecoder::new()).collect::<Result<Vec<_>, _>>().expect("Cannot decompress new repository bytes");
let mut hasher = Hasher::new();
hasher.update_rayon(&decompressed_bytes);
println!("Downloaded latest repository ({}bytes)", bytes.len());
println!("Hash: {}", hasher.finalize().to_hex());
}
}
'''
[tasks.format]
command = "cargo"
args = ["fmt", "--all"]
[tasks.build]
run_task = { name = ["check_kernel", "clippy_kernel", "build_kernel", "build_bootloader"] }
dependencies = ["format"]
[tasks.build_kernel]
command = "cargo"
args = [
"build",
"-Zbuild-std=core,compiler_builtins,alloc",
"-Zbuild-std-features=compiler-builtins-mem",
"--target",
"x86_64-unknown-none"
]
[tasks.build_bootloader]
script_runner = "@rust"
script = '''
//!```cargo
//![dependencies]
//!```
#![feature(fs_try_exists)]
use std::env::var;
use std::fs::{copy, create_dir_all, try_exists, write};
fn main() {
let cwd = var("CARGO_MAKE_WORKING_DIRECTORY").expect("CARGO_MAKE_WORKING_DIRECTORY not set");
if !matches!(try_exists(format!("{}/target/boot/EFI/BOOT", cwd)), Ok(true)) {
create_dir_all(format!("{}/target/boot/EFI/BOOT", cwd)).expect("Can't create EFI boot directory");
}
println!("Copying {}/limine/BOOTX64.EFI to {}/target/boot/EFI/BOOT/BOOTX64.EFI", cwd, cwd);
copy(format!("{}/limine/BOOTX64.EFI", cwd), format!("{}/target/boot/EFI/BOOT/BOOTX64.EFI", cwd)).expect("Can't copy BOOTX64.EFI");
println!("Generating {}/target/boot/EFI/BOOT/limine.cfg", cwd);
write(format!("{}/target/boot/EFI/BOOT/limine.cfg", cwd), r#"TIMEOUT=0
DEFAULT_ENTRY=1
GRAPHICS=yes
MENU_FONT_SCALE=2x2
EDITOR_ENABLED=no
VERBOSE=yes
SERIAL=yes
RANDOMIZE_MEMORY=no
:Kernel
PROTOCOL=stivale2
KASLR=no
KERNEL_PATH=boot:///EFI/BOOT/kernel
"#).expect("Can't write limine.cfg");
}
'''
[tasks.run]
command = "qemu-system-x86_64"
args = ["-enable-kvm", "-machine", "q35,smm=off,vmport=off", "-cpu", "host,kvm=on", "-m", "8G", "-device", "virtio-balloon", "-nographic", "-device", "qemu-xhci,id=input", "-device", "usb-kbd,bus=input.0", "-device", "usb-tablet,bus=input.0", "-audiodev", "pa,id=audio0,out.mixing-engine=off,out.stream-name=kernel,in.stream-name=kernel", "-device", "intel-hda", "-device", "hda-duplex,audiodev=audio0", "-rtc", "base=localtime,clock=host,driftfix=slew", "-drive", "file=fat:rw:target/boot", "-drive", "if=pflash,format=raw,file=OVMF_CODE.fd,readonly=on", "-drive", "file=disk-nvme.qcow2,if=none,id=NVME01", "-device", "nvme,drive=NVME01,serial=0001", "-drive", "id=disk,file=disk-sata.qcow2,if=none", "-device", "ahci,id=ahci", "-device", "ide-hd,drive=disk,bus=ahci.0", "-debugcon", "file:qemu.log", "-global", "isa-debugcon.iobase=0x402", "-d", "int", "-D", "qemu2.log", "-device", "qemu-xhci,id=audio", "-device", "usb-audio,audiodev=usbaudio,bus=audio.0", "-audiodev", "pa,id=usbaudio,out.mixing-engine=off,out.stream-name=kernel-alsa,in.stream-name=kernel-alsa", "-device", "virtio-net,netdev=nic", "-netdev", "user,hostname=kernel,id=nic", "-device", "virtio-rng-pci,rng=rng0", "-object", "rng-random,id=rng0,filename=/dev/urandom", "-device", "virtio-gpu", "-global", "driver=cfi.pflash01,property=secure,value=on", "-no-reboot"]
[tasks.run_gdb]
command = "qemu-system-x86_64"
args = ["-machine", "q35,smm=off,vmport=off", "-cpu", "max,kvm=off", "-m", "8G", "-device", "virtio-balloon", "-nographic", "-device", "qemu-xhci,id=input", "-device", "usb-kbd,bus=input.0", "-device", "usb-tablet,bus=input.0", "-audiodev", "pa,id=audio0,out.mixing-engine=off,out.stream-name=kernel,in.stream-name=kernel", "-device", "intel-hda", "-device", "hda-duplex,audiodev=audio0", "-rtc", "base=localtime,clock=host,driftfix=slew", "-drive", "file=fat:rw:target/boot", "-drive", "if=pflash,format=raw,file=OVMF_CODE.fd,readonly=on", "-drive", "file=disk-nvme.qcow2,if=none,id=NVME01", "-device", "nvme,drive=NVME01,serial=0001", "-drive", "id=disk,file=disk-sata.qcow2,if=none", "-device", "ahci,id=ahci", "-device", "ide-hd,drive=disk,bus=ahci.0", "-debugcon", "file:qemu.log", "-global", "isa-debugcon.iobase=0x402", "-d", "int", "-D", "qemu2.log", "-device", "qemu-xhci,id=audio", "-device", "usb-audio,audiodev=usbaudio,bus=audio.0", "-audiodev", "pa,id=usbaudio,out.mixing-engine=off,out.stream-name=kernel-alsa,in.stream-name=kernel-alsa", "-device", "virtio-net,netdev=nic", "-netdev", "user,hostname=kernel,id=nic", "-device", "virtio-rng-pci,rng=rng0", "-object", "rng-random,id=rng0,filename=/dev/urandom", "-device", "virtio-gpu", "-global", "driver=cfi.pflash01,property=secure,value=on", "-no-reboot", "-no-shutdown", "-s", "-S"]
[tasks.run_debug]
command = "qemu-system-x86_64"
args = ["-machine", "q35,smm=off,vmport=off", "-cpu", "max,kvm=off", "-m", "8G", "-device", "virtio-balloon", "-nographic", "-device", "qemu-xhci,id=input", "-device", "usb-kbd,bus=input.0", "-device", "usb-tablet,bus=input.0", "-audiodev", "pa,id=audio0,out.mixing-engine=off,out.stream-name=kernel,in.stream-name=kernel", "-device", "intel-hda", "-device", "hda-duplex,audiodev=audio0", "-rtc", "base=localtime,clock=host,driftfix=slew", "-drive", "file=fat:rw:target/boot", "-drive", "if=pflash,format=raw,file=OVMF_CODE.fd,readonly=on", "-drive", "file=disk-nvme.qcow2,if=none,id=NVME01", "-device", "nvme,drive=NVME01,serial=0001", "-drive", "id=disk,file=disk-sata.qcow2,if=none", "-device", "ahci,id=ahci", "-device", "ide-hd,drive=disk,bus=ahci.0", "-debugcon", "file:qemu.log", "-global", "isa-debugcon.iobase=0x402", "-d", "int", "-D", "qemu2.log", "-device", "qemu-xhci,id=audio", "-device", "usb-audio,audiodev=usbaudio,bus=audio.0", "-audiodev", "pa,id=usbaudio,out.mixing-engine=off,out.stream-name=kernel-alsa,in.stream-name=kernel-alsa", "-device", "virtio-net,netdev=nic", "-netdev", "user,hostname=kernel,id=nic", "-device", "virtio-rng-pci,rng=rng0", "-object", "rng-random,id=rng0,filename=/dev/urandom", "-device", "virtio-gpu", "-global", "driver=cfi.pflash01,property=secure,value=on", "-no-reboot", "-no-shutdown", "-s"]
[tasks.check_kernel]
command = "cargo"
args = ["check", "-Zbuild-std=core,compiler_builtins,alloc", "-Zbuild-std-features=compiler-builtins-mem", "--target", "x86_64-unknown-none"]
[tasks.clippy_kernel]
command = "cargo"
args = ["clippy", "-Zbuild-std=core,compiler_builtins,alloc", "-Zbuild-std-features=compiler-builtins-mem", "--target", "x86_64-unknown-none"]
[tasks.run_kvm_debug]
command = "qemu-system-x86_64"
args = ["-enable-kvm", "-machine", "q35,smm=off,vmport=off", "-cpu", "host,kvm=on", "-m", "8G", "-device", "virtio-balloon", "-nographic", "-device", "qemu-xhci,id=input", "-device", "usb-kbd,bus=input.0", "-device", "usb-tablet,bus=input.0", "-audiodev", "pa,id=audio0,out.mixing-engine=off,out.stream-name=kernel,in.stream-name=kernel", "-device", "intel-hda", "-device", "hda-duplex,audiodev=audio0", "-rtc", "base=localtime,clock=host,driftfix=slew", "-drive", "file=fat:rw:target/boot", "-drive", "if=pflash,format=raw,file=/usr/share/OVMF/x64/OVMF_CODE.fd,readonly=on", "-drive", "file=disk-nvme.qcow2,if=none,id=NVME01", "-device", "nvme,drive=NVME01,serial=0001", "-drive", "id=disk,file=disk-sata.qcow2,if=none", "-device", "ahci,id=ahci", "-device", "ide-hd,drive=disk,bus=ahci.0", "-debugcon", "file:qemu.log", "-global", "isa-debugcon.iobase=0x402", "-d", "int", "-D", "qemu2.log", "-device", "qemu-xhci,id=audio", "-device", "usb-audio,audiodev=usbaudio,bus=audio.0", "-audiodev", "pa,id=usbaudio,out.mixing-engine=off,out.stream-name=kernel-alsa,in.stream-name=kernel-alsa", "-device", "virtio-net,netdev=nic", "-netdev", "user,hostname=kernel,id=nic", "-device", "virtio-rng-pci,rng=rng0", "-object", "rng-random,id=rng0,filename=/dev/urandom", "-device", "virtio-gpu", "-global", "driver=cfi.pflash01,property=secure,value=on", "-no-reboot", "-S", "-s"]