diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..b9e7e7f9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,49 @@ +name: Release + +on: + release: + types: + - published + +jobs: + release: + name: "Release" + runs-on: ubuntu-latest + timeout-minutes: 15 + environment: crates_io_release + + steps: + - name: "Checkout Repository" + uses: actions/checkout@v1 + + - run: cargo publish -p bootloader_api + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + - run: cargo publish -p bootloader-x86_64-bios-common + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + - run: cargo publish -p bootloader-x86_64-common + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + - run: cargo publish -p bootloader-x86_64-bios-boot-sector --no-verify + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + - run: cargo publish -p bootloader-x86_64-bios-stage-2 --no-verify + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + - run: cargo publish -p bootloader-x86_64-bios-stage-3 --no-verify + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + - run: cargo publish -p bootloader-x86_64-bios-stage-4 --no-verify + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + - run: cargo publish -p bootloader-x86_64-uefi --no-verify + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + - run: cargo publish -p bootloader + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.github/workflows/trigger-release.yml b/.github/workflows/trigger-release.yml new file mode 100644 index 00000000..02f96aaa --- /dev/null +++ b/.github/workflows/trigger-release.yml @@ -0,0 +1,23 @@ +name: Trigger Release + +on: + push: + branches: + - "main" + +jobs: + check: + name: Trigger Release + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v3 + + - name: "Install Python Libraries" + run: python -m pip install --user -r .github/workflows/trigger-release/requirements.txt + + - name: "Run release script" + run: "python3 .github/workflows/trigger-release/trigger-release.py" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/trigger-release/requirements.txt b/.github/workflows/trigger-release/requirements.txt new file mode 100644 index 00000000..bd79a658 --- /dev/null +++ b/.github/workflows/trigger-release/requirements.txt @@ -0,0 +1 @@ +toml diff --git a/.github/workflows/trigger-release/trigger-release.py b/.github/workflows/trigger-release/trigger-release.py new file mode 100644 index 00000000..da62986d --- /dev/null +++ b/.github/workflows/trigger-release/trigger-release.py @@ -0,0 +1,42 @@ +import toml +import requests +import subprocess + +cargo_toml = toml.load("Cargo.toml") +crate_version = cargo_toml["workspace"]["package"]["version"] +print("Detected crate version " + crate_version) + +api_url = "https://crates.io/api/v1/crates/bootloader/" + crate_version +released_version = requests.get(api_url).json() + +if "version" in released_version: + version = released_version["version"] + assert (version["crate"] == "bootloader") + assert (version["num"] == crate_version) + print("Version " + crate_version + " already exists on crates.io") + +else: + print("Could not find version " + crate_version + + " on crates.io; creating a new release") + + tag_name = "v" + crate_version + print(" Tagging commit as " + tag_name) + sha = subprocess.run(["git", "rev-parse", "HEAD"], check=True, + stdout=subprocess.PIPE).stdout.decode("utf-8").strip() + subprocess.run([ + "gh", "api", "/repos/rust-osdev/x86_64/git/refs", + "-X", "POST", "-H", "Accept: application/vnd.github.v3+json", + "-F", "ref=refs/tags/" + tag_name, + "-F", "sha="+sha + ]) + + subprocess.run([ + "gh", "api", "--method", "POST", "-H", "Accept: application/vnd.github+json", + "/repos/rust-osdev/bootloader/releases", + "-f", f"tag_name='{tag_name}'", "-f", f"target_commitish='{sha}'", + "-f", f"name='{tag_name}'", + "-f", "body='[Changelog](https://github.com/rust-osdev/bootloader/blob/main/Changelog.md)'", + "-F", "draft=false", "-F", "prerelease=false", "-F", "generate_release_notes=false", + ]) + + print(" Done") diff --git a/Cargo.lock b/Cargo.lock index 6db246ac..672a597c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,9 +43,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitvec" -version = "0.22.3" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5237f00a8c86130a0cc317830e558b966dd7850d48a953d998c813f01a41b527" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" dependencies = [ "funty", "radium", @@ -55,7 +55,7 @@ dependencies = [ [[package]] name = "bootloader" -version = "0.11.0-alpha" +version = "0.11.0-beta.4" dependencies = [ "anyhow", "bootloader_test_runner", @@ -72,15 +72,15 @@ dependencies = [ [[package]] name = "bootloader-x86_64-bios-boot-sector" -version = "0.1.0" +version = "0.11.0-beta.4" [[package]] name = "bootloader-x86_64-bios-common" -version = "0.1.0" +version = "0.11.0-beta.4" [[package]] name = "bootloader-x86_64-bios-stage-2" -version = "0.1.0" +version = "0.11.0-beta.4" dependencies = [ "bootloader-x86_64-bios-common", "byteorder", @@ -89,7 +89,7 @@ dependencies = [ [[package]] name = "bootloader-x86_64-bios-stage-3" -version = "0.1.0" +version = "0.11.0-beta.4" dependencies = [ "bootloader-x86_64-bios-common", "noto-sans-mono-bitmap 0.1.6", @@ -97,7 +97,7 @@ dependencies = [ [[package]] name = "bootloader-x86_64-bios-stage-4" -version = "0.1.0-alpha.0" +version = "0.11.0-beta.4" dependencies = [ "bootloader-x86_64-bios-common", "bootloader-x86_64-common", @@ -110,7 +110,7 @@ dependencies = [ [[package]] name = "bootloader-x86_64-common" -version = "0.1.0-alpha.0" +version = "0.11.0-beta.4" dependencies = [ "bootloader_api", "conquer-once", @@ -127,7 +127,7 @@ dependencies = [ [[package]] name = "bootloader-x86_64-uefi" -version = "0.1.0-alpha.0" +version = "0.11.0-beta.4" dependencies = [ "bootloader-x86_64-common", "bootloader_api", @@ -138,7 +138,7 @@ dependencies = [ [[package]] name = "bootloader_api" -version = "0.1.0-alpha.0" +version = "0.11.0-beta.4" dependencies = [ "rand", ] @@ -230,9 +230,9 @@ dependencies = [ [[package]] name = "funty" -version = "1.2.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "getrandom" @@ -308,13 +308,14 @@ dependencies = [ [[package]] name = "mbrman" -version = "0.4.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef6f6de0b8cfc56e13dc3ac3c662d9419f8aa5e3ebceb2d0eb25abce49e00395" +checksum = "a4b239f4755d00466e3ac1d55ddeaf77a66c7580352fc6cbc40d56c218fc94a9" dependencies = [ "bincode", "bitvec", "serde", + "serde-big-array", "thiserror", ] @@ -381,9 +382,9 @@ dependencies = [ [[package]] name = "radium" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" [[package]] name = "rand" @@ -481,6 +482,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-big-array" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3323f09a748af288c3dc2474ea6803ee81f118321775bffa3ac8f7e65c5e90e7" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" version = "1.0.136" @@ -742,9 +752,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "wyz" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129e027ad65ce1453680623c3fb5163cbf7107bfe1aa32257e7d0e63f9ced188" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" dependencies = [ "tap", ] diff --git a/Cargo.toml b/Cargo.toml index 0f3e49c3..fc742db7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,11 +2,11 @@ cargo-features = ["profile-rustflags"] [package] name = "bootloader" -version = "0.11.0-alpha" -authors = ["Philipp Oppermann "] -license = "MIT/Apache-2.0" description = "An experimental x86_64 bootloader that works on both BIOS and UEFI systems." -repository = "https://github.com/rust-osdev/bootloader" +license.workspace = true +version.workspace = true +repository.workspace = true +authors = ["Philipp Oppermann "] edition = "2021" [workspace] @@ -26,12 +26,21 @@ members = [ ] exclude = ["examples/basic", "examples/test_framework"] +[workspace.package] +version = "0.11.0-beta.4" +license = "MIT/Apache-2.0" +repository = "https://github.com/rust-osdev/bootloader" + +[workspace.dependencies] +bootloader_api = { version = "0.11.0-beta.4", path = "api" } +bootloader-x86_64-common = { version = "0.11.0-beta.4", path = "common" } +bootloader-x86_64-bios-common = { version = "0.11.0-beta.4", path = "bios/common" } [dependencies] anyhow = "1.0.32" fatfs = "0.3.4" gpt = "3.0.0" -mbrman = "0.4.2" +mbrman = "0.5.1" tempfile = "3.3.0" [dev-dependencies] @@ -50,6 +59,7 @@ lto = false debug = true overflow-checks = true +# duplicated from `bios/boot_sector/Cargo.toml` [profile.stage-1] inherits = "release" opt-level = "s" @@ -58,6 +68,7 @@ codegen-units = 1 debug = false overflow-checks = false +# duplicated from `bios/stage-2/Cargo.toml` [profile.stage-2] inherits = "release" opt-level = "s" @@ -65,11 +76,13 @@ codegen-units = 1 debug = false overflow-checks = true +# duplicated from `bios/stage-3/Cargo.toml` [profile.stage-3] inherits = "release" debug = true overflow-checks = true +# duplicated from `bios/stage-4/Cargo.toml` [profile.stage-4] inherits = "release" debug = true @@ -93,7 +106,7 @@ rustflags = [ llvm-tools = "0.1.1" [package.metadata.docs.rs] -default-target = "x86_64-unknown-linux-gnu" +rustc-args = ["--cfg", "docsrs_dummy_build"] [package.metadata.release] dev-version = false diff --git a/Changelog.md b/Changelog.md index 7f0e4614..453e9ac6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,15 @@ # Unreleased +Major rewrite of the `bootloader` crate with various breaking changes: + +- **Separate API crate:** The bootloader is now split into two parts: An API crate to make kernels loadable by the bootloader and the actual bootloader implementation. This makes the build process for kernels much easier and faster. +- **New config system:** Instead of configuring the bootloader via a special table in the `Cargo.toml`, the configuration now happens through a normal Rust struct, which is part of the `entry_point!` macro. The macro then serializes the config struct at compile time and places it in a special ELF output section. The compile time serialization happens through a manually implemented `const fn` of the config struct. +- **Load the kernel at runtime:** The bootloader is now able to load files from FAT partitions at runtime. Thus, we don't need to link the kernel into the bootloader executable anymore. As a result, we don't need to recompile the bootloader on kernel changes anymore. We also load the config at runtime from the kernel's ELF section, which eliminates the second reason for recompiling the bootloader as well. +- **Split into sub-crates:** Since the bootloader build process does not need access to the kernel executable or its `Cargo.toml` anymore, we can build the different parts of the bootloader independently. For example, the BIOS boot sector is now a separate crate, and the UEFI bootloader is too. +- **Library to create disk images:** To create an abstraction the complex build steps of the different bootloader executables, we compile them inside cargo build scripts. At the top level, we provide a `bootloader` _library_ crate, which compiles everything as part of its build script. This library includes functions for creating BIOS and UEFI disk images for a given kernel. These functions can be used e.g. from a builder crate or a build script of the downstream operating system. + +See our [migration guides](docs/migration/README.md) for details. + # 0.10.13 – 2022-09-25 - Add dynamic range configuration ([#229](https://github.com/rust-osdev/bootloader/pull/229)) diff --git a/api/Cargo.toml b/api/Cargo.toml index a2fe956f..ef687b0c 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "bootloader_api" -version = "0.1.0-alpha.0" +license.workspace = true +version.workspace = true +repository.workspace = true edition = "2021" description = "Makes a kernel compatible with the bootloader crate" -license = "MIT/Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/bios/boot_sector/Cargo.toml b/bios/boot_sector/Cargo.toml index 620a036f..ca870600 100644 --- a/bios/boot_sector/Cargo.toml +++ b/bios/boot_sector/Cargo.toml @@ -1,9 +1,22 @@ [package] name = "bootloader-x86_64-bios-boot-sector" -version = "0.1.0" +version.workspace = true authors = ["Philipp Oppermann "] edition = "2021" +license.workspace = true +repository.workspace = true +description = "BIOS boot sector for the `bootloader` crate" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + +# This currently causes a cargo warning, but it is required for publishing to crates.io. +# See https://github.com/rust-lang/cargo/issues/8264 for details. +[profile.stage-1] +inherits = "release" +opt-level = "s" +lto = true +codegen-units = 1 +debug = false +overflow-checks = false diff --git a/bios/boot_sector/src/main.rs b/bios/boot_sector/src/main.rs index 251495aa..ab10922e 100644 --- a/bios/boot_sector/src/main.rs +++ b/bios/boot_sector/src/main.rs @@ -2,11 +2,8 @@ #![no_main] #![warn(unsafe_op_in_unsafe_fn)] -use core::{ - arch::{asm, global_asm}, - slice, -}; -use fail::{print_char, UnwrapOrFail}; +use core::{arch::global_asm, slice}; +use fail::UnwrapOrFail; global_asm!(include_str!("boot.s")); @@ -31,12 +28,10 @@ fn second_stage_start() -> *const () { #[no_mangle] pub extern "C" fn first_stage(disk_number: u16) { // read partition table and look for second stage partition - print_char(b'1'); let partition_table = unsafe { slice::from_raw_parts(partition_table_raw(), 16 * 4) }; let second_stage_partition = mbr::get_partition(partition_table, 0); // load second stage partition into memory - print_char(b'2'); let entry_point_address = second_stage_start() as u32; let mut start_lba = second_stage_partition.logical_block_address.into(); @@ -65,18 +60,12 @@ pub extern "C" fn first_stage(disk_number: u16) { } // jump to second stage - print_char(b'3'); let second_stage_entry_point: extern "C" fn( disk_number: u16, partition_table_start: *const u8, ) = unsafe { core::mem::transmute(entry_point_address as *const ()) }; let partition_table_start = unsafe { partition_table_raw() }; second_stage_entry_point(disk_number, partition_table_start); - for _ in 0..10 { - print_char(b'R'); - } - loop { - unsafe { asm!("hlt") } - } + fail::fail(b'R'); } diff --git a/bios/boot_sector/src/mbr.rs b/bios/boot_sector/src/mbr.rs index 39b1c756..1f7eed52 100644 --- a/bios/boot_sector/src/mbr.rs +++ b/bios/boot_sector/src/mbr.rs @@ -1,13 +1,8 @@ -use super::fail::{fail, UnwrapOrFail}; +use super::fail::UnwrapOrFail; pub(crate) fn get_partition(partitions_raw: &[u8], index: usize) -> PartitionTableEntry { - const PARTITIONS_AREA_SIZE: usize = 16 * 4; const ENTRY_SIZE: usize = 16; - if partitions_raw.len() < PARTITIONS_AREA_SIZE { - fail(b'a'); - } - let offset = index * ENTRY_SIZE; let buffer = partitions_raw.get(offset..).unwrap_or_fail(b'c'); diff --git a/bios/common/Cargo.toml b/bios/common/Cargo.toml index fedddfc8..0417d017 100644 --- a/bios/common/Cargo.toml +++ b/bios/common/Cargo.toml @@ -1,7 +1,10 @@ [package] name = "bootloader-x86_64-bios-common" -version = "0.1.0" +version.workspace = true edition = "2021" +license.workspace = true +repository.workspace = true +description = "Common code for BIOS stages of the `bootloader` crate" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/bios/stage-2/Cargo.toml b/bios/stage-2/Cargo.toml index f70bf2b4..4e39accb 100644 --- a/bios/stage-2/Cargo.toml +++ b/bios/stage-2/Cargo.toml @@ -1,12 +1,24 @@ [package] name = "bootloader-x86_64-bios-stage-2" -version = "0.1.0" +version.workspace = true authors = ["Philipp Oppermann "] edition = "2021" +license.workspace = true +repository.workspace = true +description = "Second BIOS stage of the `bootloader` crate" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] mbr-nostd = "0.1.0" byteorder = { version = "1.4.3", default-features = false } -bootloader-x86_64-bios-common = { version = "0.1.0", path = "../common" } +bootloader-x86_64-bios-common = { workspace = true } + +# This currently causes a cargo warning, but it is required for publishing to crates.io. +# See https://github.com/rust-lang/cargo/issues/8264 for details. +[profile.stage-2] +inherits = "release" +opt-level = "s" +codegen-units = 1 +debug = false +overflow-checks = true diff --git a/bios/stage-3/Cargo.toml b/bios/stage-3/Cargo.toml index bd606566..9db2bcce 100644 --- a/bios/stage-3/Cargo.toml +++ b/bios/stage-3/Cargo.toml @@ -1,11 +1,21 @@ [package] name = "bootloader-x86_64-bios-stage-3" -version = "0.1.0" +version.workspace = true authors = ["Philipp Oppermann "] edition = "2021" +license.workspace = true +repository.workspace = true +description = "Third BIOS stage of the `bootloader` crate" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bootloader-x86_64-bios-common = { version = "0.1.0", path = "../common" } +bootloader-x86_64-bios-common = { workspace = true } noto-sans-mono-bitmap = "0.1.5" + +# This currently causes a cargo warning, but it is required for publishing to crates.io. +# See https://github.com/rust-lang/cargo/issues/8264 for details. +[profile.stage-3] +inherits = "release" +debug = true +overflow-checks = true diff --git a/bios/stage-4/Cargo.toml b/bios/stage-4/Cargo.toml index ad3aac08..c02209fb 100644 --- a/bios/stage-4/Cargo.toml +++ b/bios/stage-4/Cargo.toml @@ -1,15 +1,25 @@ [package] name = "bootloader-x86_64-bios-stage-4" -version = "0.1.0-alpha.0" +version.workspace = true edition = "2021" +license.workspace = true +repository.workspace = true +description = "Fourth BIOS stage of the `bootloader` crate" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bootloader_api = { version = "0.1.0-alpha.0", path = "../../api" } -bootloader-x86_64-bios-common = { version = "0.1.0", path = "../common" } -bootloader-x86_64-common = { version = "0.1.0-alpha.0", path = "../../common" } +bootloader_api = { workspace = true } +bootloader-x86_64-common = { workspace = true } +bootloader-x86_64-bios-common = { workspace = true } log = "0.4.14" x86_64 = "0.14.8" rsdp = "2.0.0" usize_conversions = "0.2.0" + +# This currently causes a cargo warning, but it is required for publishing to crates.io. +# See https://github.com/rust-lang/cargo/issues/8264 for details. +[profile.stage-4] +inherits = "release" +debug = true +overflow-checks = true diff --git a/build.rs b/build.rs index 979050ed..7f04dddf 100644 --- a/build.rs +++ b/build.rs @@ -3,18 +3,15 @@ use std::{ process::Command, }; -const BOOTLOADER_X86_64_UEFI_VERSION: &str = "0.1.0-alpha.0"; +const BOOTLOADER_X86_64_UEFI_VERSION: &str = env!("CARGO_PKG_VERSION"); -const BOOTLOADER_X86_64_BIOS_BOOT_SECTOR_VERSION: &str = "0.1.0-alpha.0"; -const BOOTLOADER_X86_64_BIOS_STAGE_2_VERSION: &str = "0.1.0-alpha.0"; -const BOOTLOADER_X86_64_BIOS_STAGE_3_VERSION: &str = "0.1.0-alpha.0"; -const BOOTLOADER_X86_64_BIOS_STAGE_4_VERSION: &str = "0.1.0-alpha.0"; +const BOOTLOADER_X86_64_BIOS_BOOT_SECTOR_VERSION: &str = env!("CARGO_PKG_VERSION"); +const BOOTLOADER_X86_64_BIOS_STAGE_2_VERSION: &str = env!("CARGO_PKG_VERSION"); +const BOOTLOADER_X86_64_BIOS_STAGE_3_VERSION: &str = env!("CARGO_PKG_VERSION"); +const BOOTLOADER_X86_64_BIOS_STAGE_4_VERSION: &str = env!("CARGO_PKG_VERSION"); fn main() { let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); - println!("cargo:rerun-if-changed=build.rs"); - println!("cargo:rerun-if-changed=Cargo.toml"); - println!("cargo:rerun-if-changed=Cargo.lock"); let uefi_path = build_uefi_bootloader(&out_dir); println!( @@ -46,6 +43,7 @@ fn main() { ); } +#[cfg(not(docsrs_dummy_build))] fn build_uefi_bootloader(out_dir: &Path) -> PathBuf { let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()); let mut cmd = Command::new(cargo); @@ -79,6 +77,7 @@ fn build_uefi_bootloader(out_dir: &Path) -> PathBuf { } } +#[cfg(not(docsrs_dummy_build))] fn build_bios_boot_sector(out_dir: &Path) -> PathBuf { let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()); let mut cmd = Command::new(cargo); @@ -121,6 +120,7 @@ fn build_bios_boot_sector(out_dir: &Path) -> PathBuf { convert_elf_to_bin(elf_path) } +#[cfg(not(docsrs_dummy_build))] fn build_bios_stage_2(out_dir: &Path) -> PathBuf { let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()); let mut cmd = Command::new(cargo); @@ -161,6 +161,7 @@ fn build_bios_stage_2(out_dir: &Path) -> PathBuf { convert_elf_to_bin(elf_path) } +#[cfg(not(docsrs_dummy_build))] fn build_bios_stage_3(out_dir: &Path) -> PathBuf { let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()); let mut cmd = Command::new(cargo); @@ -201,6 +202,7 @@ fn build_bios_stage_3(out_dir: &Path) -> PathBuf { convert_elf_to_bin(elf_path) } +#[cfg(not(docsrs_dummy_build))] fn build_bios_stage_4(out_dir: &Path) -> PathBuf { let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()); let mut cmd = Command::new(cargo); @@ -268,3 +270,26 @@ fn convert_elf_to_bin(elf_path: PathBuf) -> PathBuf { } flat_binary_path } + +// dummy implementations because docsrs builds have no network access + +#[cfg(docsrs_dummy_build)] +fn build_uefi_bootloader(_out_dir: &Path) -> PathBuf { + PathBuf::new() +} +#[cfg(docsrs_dummy_build)] +fn build_bios_boot_sector(_out_dir: &Path) -> PathBuf { + PathBuf::new() +} +#[cfg(docsrs_dummy_build)] +fn build_bios_stage_2(_out_dir: &Path) -> PathBuf { + PathBuf::new() +} +#[cfg(docsrs_dummy_build)] +fn build_bios_stage_3(_out_dir: &Path) -> PathBuf { + PathBuf::new() +} +#[cfg(docsrs_dummy_build)] +fn build_bios_stage_4(_out_dir: &Path) -> PathBuf { + PathBuf::new() +} diff --git a/common/Cargo.toml b/common/Cargo.toml index 67c3505c..0d84c5f5 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -1,14 +1,15 @@ [package] name = "bootloader-x86_64-common" -version = "0.1.0-alpha.0" +version.workspace = true edition = "2021" description = "Common code for the x86_64 bootloader implementations" -license = "MIT/Apache-2.0" +license.workspace = true +repository.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bootloader_api = { version = "0.1.0-alpha.0", path = "../api" } +bootloader_api = { workspace = true } conquer-once = { version = "0.3.2", default-features = false } log = "0.4.14" spinning_top = "0.2.4" diff --git a/docs/migration/README.md b/docs/migration/README.md new file mode 100644 index 00000000..5eef5ed0 --- /dev/null +++ b/docs/migration/README.md @@ -0,0 +1,6 @@ +# Migration Guides + +These guides explain how to migrate your project from older `bootloader` versions: + +- [Migration from `v0.9.X`](v0.9.md) +- [Migration from `v0.10.X`](v0.10.md) diff --git a/src/mbr.rs b/src/mbr.rs index f5608cc1..821bb7eb 100644 --- a/src/mbr.rs +++ b/src/mbr.rs @@ -1,4 +1,5 @@ use anyhow::Context; +use mbrman::BOOT_ACTIVE; use std::{ fs::{self, File}, io::{self, Seek, SeekFrom}, @@ -33,7 +34,7 @@ pub fn create_mbr_disk( .try_into() .context("size of second stage is larger than u32::MAX")?; mbr[1] = mbrman::MBRPartitionEntry { - boot: true, + boot: BOOT_ACTIVE, starting_lba: second_stage_start_sector, sectors: second_stage_sectors, // see BOOTLOADER_SECOND_STAGE_PARTITION_TYPE in `boot_sector` crate @@ -51,7 +52,7 @@ pub fn create_mbr_disk( .context("failed to read file metadata of FAT boot partition")? .len(); mbr[2] = mbrman::MBRPartitionEntry { - boot: false, + boot: BOOT_ACTIVE, starting_lba: boot_partition_start_sector, sectors: ((boot_partition_size - 1) / u64::from(SECTOR_SIZE) + 1) .try_into() diff --git a/uefi/Cargo.toml b/uefi/Cargo.toml index 109b9298..a2dfe632 100644 --- a/uefi/Cargo.toml +++ b/uefi/Cargo.toml @@ -1,15 +1,16 @@ [package] name = "bootloader-x86_64-uefi" -version = "0.1.0-alpha.0" +version.workspace = true edition = "2021" description = "UEFI bootloader for x86_64" -license = "MIT/Apache-2.0" +license.workspace = true +repository.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bootloader_api = { version = "0.1.0-alpha.0", path = "../api" } -bootloader-x86_64-common = { version = "0.1.0-alpha.0", path = "../common" } +bootloader_api = { workspace = true } +bootloader-x86_64-common = { workspace = true } log = "0.4.14" uefi = "0.16.0" x86_64 = "0.14.8"