Skip to content

Add --feature readonly, to build a bin without risky commands #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ jobs:
run: rustup show

- name: Build UEFI application (no ESP)
run: make -C framework_uefi build/x86_64-unknown-uefi/boot.efi
run: |
make -C framework_uefi build/x86_64-unknown-uefi/boot.efi
mv framework_uefi/build/x86_64-unknown-uefi/boot.efi framework_tool_full.efi
make -C framework_uefi FEATURES=readonly build/x86_64-unknown-uefi/boot.efi
cp framework_uefi/build/x86_64-unknown-uefi/boot.efi framework_tool.efi

- name: Upload UEFI App
uses: actions/upload-artifact@v4
with:
name: framework.efi
path: framework_uefi/build/x86_64-unknown-uefi/boot.efi
name: framework_efi.zip
path: ./*.efi

- name: Install mtools to build ESP and ISO (Linux)
run: sudo apt-get install -y mtools genisoimage
Expand Down
1 change: 1 addition & 0 deletions framework_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ build = "build.rs"

[features]
default = ["hidapi", "rusb"]
readonly = [ ]
rusb = ["dep:rusb"]
hidapi = ["dep:hidapi"]
uefi = [ "lazy_static/spin_no_std" ]
Expand Down
4 changes: 2 additions & 2 deletions framework_lib/src/commandline/clap_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use clap_num::maybe_hex;
use crate::chromium_ec::commands::SetGpuSerialMagic;
use crate::chromium_ec::CrosEcDriverType;
use crate::commandline::{
Cli, ConsoleArg, FpBrightnessArg, HardwareDeviceType, InputDeckModeArg, RebootEcArg,
Cli, ConsoleArg, FpBrightnessArg, HardwareDeviceType, InputDeckModeArg, LogLevel, RebootEcArg,
TabletModeArg,
};

Expand Down Expand Up @@ -381,7 +381,7 @@ pub fn parse(args: &[String]) -> Cli {
};

Cli {
verbosity: args.verbosity.log_level_filter(),
verbosity: LogLevel(args.verbosity.log_level_filter()),
versions: args.versions,
version: args.version,
features: args.features,
Expand Down
85 changes: 79 additions & 6 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,22 @@ impl From<InputDeckModeArg> for DeckStateMode {
}
}

#[derive(Debug)]
pub struct LogLevel(log::LevelFilter);

impl Default for LogLevel {
fn default() -> Self {
LogLevel(log::LevelFilter::Error)
}
}

/// Shadows `clap_std::ClapCli` with extras for UEFI
///
/// The UEFI commandline currently doesn't use clap, so we need to shadow the struct.
/// Also it has extra options.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Cli {
pub verbosity: log::LevelFilter,
pub verbosity: LogLevel,
pub versions: bool,
pub version: bool,
pub features: bool,
Expand Down Expand Up @@ -212,9 +221,73 @@ pub struct Cli {

pub fn parse(args: &[String]) -> Cli {
#[cfg(feature = "uefi")]
return uefi::parse(args);
let cli = uefi::parse(args);
#[cfg(not(feature = "uefi"))]
return clap_std::parse(args);
let cli = clap_std::parse(args);

if cfg!(feature = "readonly") {
// Initialize a new Cli with no arguments
// Set all arguments that are readonly/safe
// We explicitly only cope the safe ones so that if we add new arguments in the future,
// which might be unsafe, we can't forget to exclude them from the safe set.
// TODO: Instead of silently ignoring blocked command, we should remind the user
Cli {
verbosity: cli.verbosity,
versions: cli.versions,
version: cli.version,
esrt: cli.esrt,
device: cli.device,
power: cli.power,
thermal: cli.thermal,
sensors: cli.sensors,
// fansetduty
// fansetrpm
// autofanctrl
privacy: cli.privacy,
pd_info: cli.version,
dp_hdmi_info: cli.dp_hdmi_info,
// dp_hdmi_update
audio_card_info: cli.audio_card_info,
pd_bin: cli.pd_bin,
ec_bin: cli.ec_bin,
capsule: cli.capsule,
dump: cli.dump,
h2o_capsule: cli.h2o_capsule,
// dump_ec_flash
// flash_ec
// flash_ro_ec
driver: cli.driver,
test: cli.test,
intrusion: cli.intrusion,
inputdeck: cli.inputdeck,
inputdeck_mode: cli.inputdeck_mode,
expansion_bay: cli.expansion_bay,
// charge_limit
// charge_current_limit
get_gpio: cli.get_gpio,
fp_led_level: cli.fp_led_level,
fp_brightness: cli.fp_brightness,
kblight: cli.kblight,
rgbkbd: cli.rgbkbd,
// tablet_mode
// touchscreen_enable
stylus_battery: cli.stylus_battery,
console: cli.console,
reboot_ec: cli.reboot_ec,
// ec_hib_delay
hash: cli.hash,
pd_addrs: cli.pd_addrs,
pd_ports: cli.pd_ports,
help: cli.help,
info: cli.info,
// allupdate
paginate: cli.paginate,
// raw_command
..Default::default()
}
} else {
cli
}
}

fn print_single_pd_details(pd: &PdController) {
Expand Down Expand Up @@ -815,7 +888,7 @@ fn compare_version(device: Option<HardwareDeviceType>, version: String, ec: &Cro
pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
#[cfg(feature = "uefi")]
{
log::set_max_level(args.verbosity);
log::set_max_level(args.verbosity.0);
}
#[cfg(not(feature = "uefi"))]
{
Expand All @@ -824,7 +897,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
// .filter("FRAMEWORK_COMPUTER_LOG")
// .write_style("FRAMEWORK_COMPUTER_LOG_STYLE");

let level = args.verbosity.as_str();
let level = args.verbosity.0.as_str();
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or(level))
.format_target(false)
.format_timestamp(None)
Expand Down
14 changes: 7 additions & 7 deletions framework_lib/src/commandline/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use uefi::Handle;

use crate::chromium_ec::commands::SetGpuSerialMagic;
use crate::chromium_ec::{CrosEcDriverType, HardwareDeviceType};
use crate::commandline::Cli;
use crate::commandline::{Cli, LogLevel};

use super::{ConsoleArg, FpBrightnessArg, InputDeckModeArg, RebootEcArg, TabletModeArg};

Expand All @@ -26,7 +26,7 @@ pub fn get_args(bs: &BootServices, image_handle: Handle) -> Vec<String> {

pub fn parse(args: &[String]) -> Cli {
let mut cli = Cli {
verbosity: log::LevelFilter::Error,
verbosity: LogLevel(log::LevelFilter::Error),
paginate: false,
versions: false,
version: false,
Expand Down Expand Up @@ -103,15 +103,15 @@ pub fn parse(args: &[String]) -> Cli {

for (i, arg) in args.iter().enumerate() {
if arg == "-q" {
cli.verbosity = log::LevelFilter::Off;
cli.verbosity = LogLevel(log::LevelFilter::Off);
} else if arg == "-v" {
cli.verbosity = log::LevelFilter::Warn;
cli.verbosity = LogLevel(log::LevelFilter::Warn);
} else if arg == "-vv" {
cli.verbosity = log::LevelFilter::Info;
cli.verbosity = LogLevel(log::LevelFilter::Info);
} else if arg == "-vvv" {
cli.verbosity = log::LevelFilter::Debug;
cli.verbosity = LogLevel(log::LevelFilter::Debug);
} else if arg == "-vvvv" {
cli.verbosity = log::LevelFilter::Trace;
cli.verbosity = LogLevel(log::LevelFilter::Trace);
} else if arg == "--versions" {
cli.versions = true;
found_an_option = true;
Expand Down
4 changes: 4 additions & 0 deletions framework_tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ edition = "2021"
name = "framework_tool"
path = "src/main.rs"

[features]
default = [ ]
readonly = [ "framework_lib/readonly" ]

[dependencies.framework_lib]
path = "../framework_lib"

Expand Down
4 changes: 4 additions & 0 deletions framework_uefi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ rust-version = "1.74"
name = "uefitool"
path = "src/main.rs"

[features]
default = [ ]
readonly = [ "framework_lib/readonly" ]

[dependencies]
uefi = { version = "0.20", features = ["alloc"] }
uefi-services = "0.17"
Expand Down
4 changes: 3 additions & 1 deletion framework_uefi/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
TARGET?=x86_64-unknown-uefi
BUILD=build/$(TARGET)
FEATURES?=''

SRC_DIR=.

Expand All @@ -18,7 +19,7 @@ all: $(BUILD)/boot.img
iso: $(BUILD)/UEFI-Shell-fwk.iso

clean:
rm -r $(BUILD)
rm -rf $(BUILD)

qemu: $(BUILD)/boot.img
$(QEMU) $(QEMU_FLAGS) $<
Expand Down Expand Up @@ -61,6 +62,7 @@ $(BUILD)/boot.efi: ../Cargo.lock $(SRC_DIR)/Cargo.toml $(SRC_DIR)/src/*
mkdir -p $(BUILD)
cargo rustc \
--target $(TARGET) \
--features $(FEATURES) \
--release \
-- \
--emit link=framework_uefi/$@
Loading