add command line arguments to override antirollback settings

this argument is primarily intended for use in CI testing to create
a synthetic image that has an advanced antirollback code.
This commit is contained in:
bunnie 2026-02-03 03:24:06 +08:00
parent 56c1230b2e
commit 7a55d6a669
2 changed files with 21 additions and 2 deletions

View file

@ -1,7 +1,10 @@
use std::io::{Error, ErrorKind};
use clap::{App, Arg, crate_version};
use xous_tools::sign_image::{convert_to_uf2, load_pem, sign_file};
use xous_tools::{
sign_image::{convert_to_uf2, load_pem, sign_file},
utils::parse_u32,
};
const DEVKEY_PATH: &str = "devkey/dev.key";
@ -98,6 +101,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.help("Function code to embed in the signature block. Only meaningful in combination with --bao1x")
.required(false)
)
.arg(
Arg::with_name("antirollback-override")
.long("antirollback-override")
.takes_value(true)
.help("Manually specify an anti-rollback value for the image. Overrides the system configuration file.")
.required(false)
)
.get_matches();
let minver =
@ -109,6 +119,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
None
};
let arb_override = if let Some(arb_str) = matches.value_of("antirollback-override") {
parse_u32(arb_str).ok()
} else {
None
};
let sig_length = usize::from_str_radix(matches.value_of("sig-length").unwrap_or("4096"), 10)
.expect("sig-length should be a decimal number");
// Sign the loader, if an output file was specified
@ -140,6 +156,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
matches.is_present("with-jump"),
sig_length,
matches.value_of("function-code"),
arb_override.map(|x| x as usize),
)?;
if matches.is_present("bao1x") {
@ -181,6 +198,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
matches.is_present("with-jump"),
sig_length,
Some(matches.value_of("function-code").unwrap_or("kernel")),
arb_override.map(|x| x as usize),
)?;
if matches.is_present("bao1x") {

View file

@ -304,6 +304,7 @@ pub fn sign_file<S, T>(
with_jump: bool,
sector_length: usize,
function_code: Option<&str>,
arb_override: Option<usize>,
) -> Result<(), Box<dyn std::error::Error>>
where
S: AsRef<Path>,
@ -324,7 +325,7 @@ where
sector_length,
version,
function_code,
None,
arb_override,
)?;
dest_file.write_all(&result)?;
Ok(())