Skip to content

Commit 77321d0

Browse files
Fix builds for powerpc and s390x
Only allow Grub as the bootloader for powerpc and s390x Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent c721fd8 commit 77321d0

3 files changed

Lines changed: 70 additions & 14 deletions

File tree

src/backend/statefile.rs

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::bootloader::Bootloader;
44
use crate::bootupd::list_dev_current_root;
5-
use crate::efi::Efi;
65
use crate::freezethaw::fsfreeze_thaw_cycle;
76
use crate::model::SavedState;
87
use crate::util::SignalTerminationGuard;
@@ -133,7 +132,24 @@ impl SavedState {
133132
}
134133
}
135134

135+
#[cfg(any(target_arch = "powerpc64", target_arch = "s390x"))]
136136
Bootloader::GrubCC => {
137+
let arch = if cfg!(target_arch = "powerpc64") {
138+
"powerpc64"
139+
} else {
140+
"s390x"
141+
};
142+
143+
anyhow::bail!("Only Grub is supported for {arch}");
144+
}
145+
146+
#[cfg(any(
147+
target_arch = "x86_64",
148+
target_arch = "aarch64",
149+
target_arch = "riscv64"
150+
))]
151+
Bootloader::GrubCC => {
152+
use crate::efi::Efi;
137153
let efi = Efi::default();
138154

139155
let device = get_parent_device(&root)?;
@@ -202,27 +218,54 @@ pub(crate) struct StateLockGuard {
202218
}
203219

204220
impl StateLockGuard {
205-
/// Atomically replace the on-disk state with a new version.
221+
fn write_grub_statefile(&self, state: &SavedState) -> Result<()> {
222+
let subdir = self.sysroot.open_dir(SavedState::STATEFILE_DIR)?;
223+
224+
subdir
225+
.atomic_write_with_perms(
226+
SavedState::STATEFILE_NAME,
227+
serde_json::to_vec(state).context("Serializing state")?,
228+
Permissions::from_mode(0o644),
229+
)
230+
.context("Writing state file")?;
231+
232+
return Ok(());
233+
}
234+
235+
#[cfg(any(target_arch = "powerpc64", target_arch = "s390x"))]
206236
#[context("Updating state")]
207237
pub(crate) fn update_state(
208238
&mut self,
209239
state: &SavedState,
210240
bootloader: Bootloader,
211241
) -> Result<()> {
212-
if bootloader == Bootloader::Grub {
213-
let subdir = self.sysroot.open_dir(SavedState::STATEFILE_DIR)?;
242+
let arch = if cfg!(target_arch = "powerpc64") {
243+
"powerpc64"
244+
} else {
245+
"s390x"
246+
};
214247

215-
subdir
216-
.atomic_write_with_perms(
217-
SavedState::STATEFILE_NAME,
218-
serde_json::to_vec(state).context("Serializing state")?,
219-
Permissions::from_mode(0o644),
220-
)
221-
.context("Writing state file")?;
248+
if bootloader != Bootloader::Grub {
249+
anyhow::anyhow!("Found bootloader: {bootloader}. Only Grub is supported for {arch}");
250+
}
222251

223-
return Ok(());
252+
self.write_grub_statefile(state)
253+
}
254+
255+
/// Atomically replace the on-disk state with a new version.
256+
#[cfg(not(any(target_arch = "powerpc64", target_arch = "s390x")))]
257+
#[context("Updating state")]
258+
pub(crate) fn update_state(
259+
&mut self,
260+
state: &SavedState,
261+
bootloader: Bootloader,
262+
) -> Result<()> {
263+
if bootloader == Bootloader::Grub {
264+
return self.write_grub_statefile(state);
224265
}
225266

267+
use crate::efi::Efi;
268+
226269
let device = get_parent_device(&self.sysroot)?;
227270
let all_esps = device
228271
.find_colocated_esps()

src/bootloader.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use anyhow::Result;
22
use fn_error_context::context;
33
use std::{fmt::Display, sync::OnceLock};
44

5-
use crate::efi::get_loader_info;
6-
75
#[derive(Debug, Default, Copy, Clone, clap::ValueEnum, PartialEq, Eq)]
86
pub enum Bootloader {
97
#[default]
@@ -48,8 +46,17 @@ impl Bootloader {
4846
}
4947
}
5048

49+
#[cfg(any(target_arch = "powerpc64", target_arch = "s390x"))]
50+
#[context("Getting bootloader")]
51+
pub(crate) fn get_bootloader() -> Result<Bootloader> {
52+
Ok(Bootloader::Grub)
53+
}
54+
55+
#[cfg(not(any(target_arch = "powerpc64", target_arch = "s390x")))]
5156
#[context("Getting bootloader")]
5257
pub(crate) fn get_bootloader() -> Result<Bootloader> {
58+
use crate::efi::get_loader_info;
59+
5360
static BOOTLOADER: OnceLock<Bootloader> = OnceLock::new();
5461

5562
if let Some(bootloader) = BOOTLOADER.get() {

src/cli/bootupd.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ impl DCommand {
119119

120120
/// Runner for `install` verb.
121121
pub(crate) fn run_install(opts: InstallOpts) -> Result<()> {
122+
if opts.bootloader != Bootloader::Grub
123+
&& cfg!(any(target_arch = "powerpc64", target_arch = "s390x"))
124+
{
125+
anyhow::bail!("Only Grub is supported for powerpc64 and s390x");
126+
}
127+
122128
let configmode = if opts.write_uuid {
123129
ConfigMode::WithUUID
124130
} else if opts.with_static_configs {

0 commit comments

Comments
 (0)