Skip to content

Commit

Permalink
tool: Add error for write locked
Browse files Browse the repository at this point in the history
Add a new error for the case of trying to flash when security is enabled
and it is still locked and update the related docs.

Signed-off-by: Tim Crawford <[email protected]>
  • Loading branch information
crawfxrd committed Jul 15, 2024
1 parent 54d7954 commit 70c8678
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
20 changes: 16 additions & 4 deletions docs/flashing.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
# Flashing firmware

## UEFI application

The `flash.sh` script from the top-level firmware-open project will use
firmware-update, the UEFI application which is used for normal system updates.

This will flash both the SBIOS and the EC after building the firmware. To
flash just the EC, delete the built `firmware.rom` before running `flash.sh`.

## Internal programmer

Use this method for flashing a system already running System76 EC.

This method will only work if the running firmware is not locked. Firmware is
write locked if it was built with `CONFIG_SECURITY=y`. firmware-update must be
used to flash from UEFI in this state (see `flash.sh` in firmware-open).
write locked if it was built with `CONFIG_SECURITY=y`. The firmware can be
unlocked using ectool for a single boot:

```
./scripts/ectool.sh security unlock
```

This will trigger a watchdog reset causing the system to **immediately power
off**. OS data may be lost or corrupted as a result. Save and close all
This method will trigger a watchdog reset causing the system to **immediately
power off**. OS data may be lost or corrupted as a result. Save and close all
applications before flashing.

```
Expand Down
4 changes: 0 additions & 4 deletions docs/keyboard-layout-customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ make

See [flashing firmware](./flashing.md) for details.

```sh
make flash_internal
```

Do not use the keyboard or touchpad while it is flashing.

The system will power off as part of the flash process. Turn it back on after
Expand Down
2 changes: 1 addition & 1 deletion scripts/ectool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# SPDX-License-Identifier: GPL-3.0-only

set -e
cargo build --release --manifest-path tool/Cargo.toml
cargo build --release --quiet --manifest-path tool/Cargo.toml
sudo tool/target/release/system76_ectool "$@"
2 changes: 1 addition & 1 deletion src/board/system76/common/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum SecurityState security_get(void) {

bool security_set(enum SecurityState state) {
switch (state) {
// Allow perpare states to be set
// Allow prepare states to be set
case SECURITY_STATE_PREPARE_LOCK:
case SECURITY_STATE_PREPARE_UNLOCK:
security_state = state;
Expand Down
2 changes: 2 additions & 0 deletions tool/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum Error {
/// Encountered a hidapi::Error
#[cfg(feature = "hidapi")]
Hid(hidapi::HidError),
/// Writing to flash is disabled
WriteLocked,
}

#[cfg(feature = "std")]
Expand Down
8 changes: 6 additions & 2 deletions tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ unsafe fn flash(ec: &mut Ec<Box<dyn Access>>, path: &str, target: SpiTarget) ->
println!("ec version: {:?}", str::from_utf8(ec_version));
}

if let Ok(security) = ec.security_get() {
if security != SecurityState::Unlock {
return Err(Error::WriteLocked);
}
}

if scratch {
// Wait for any key releases
eprintln!("Waiting 5 seconds for all keys to be released");
Expand Down Expand Up @@ -378,8 +384,6 @@ struct Args {
}

fn main() {
//.subcommand(Command::new("security").arg(Arg::new("state").value_parser(["lock", "unlock"])))

let args = Args::parse();

let get_ec = || -> Result<_, Error> {
Expand Down

0 comments on commit 70c8678

Please sign in to comment.