Skip to content
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
46 changes: 41 additions & 5 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ const EC_MEMMAP_SIZE: u16 = 0xFF;
/// representing 'EC' in ASCII (0x20 == 'E', 0x21 == 'C')
const EC_MEMMAP_ID: u16 = 0x20;

const FLASH_BASE: u32 = 0x0; // 0x80000
const FLASH_BASE: u32 = 0x0;
const FLASH_SIZE: u32 = 0x80000;
const FLASH_RO_BASE: u32 = 0x0;
const FLASH_RO_SIZE: u32 = 0x3C000;
const FLASH_RW_BASE: u32 = 0x40000;
Expand All @@ -76,6 +77,7 @@ const FLASH_PROGRAM_OFFSET: u32 = 0x1000;
#[derive(Clone, Debug, PartialEq)]
pub enum EcFlashType {
Full,
Both,
Ro,
Rw,
}
Expand Down Expand Up @@ -817,7 +819,7 @@ impl CrosEc {
));
};

if ft == EcFlashType::Full || ft == EcFlashType::Ro {
if matches!(ft, EcFlashType::Full | EcFlashType::Both | EcFlashType::Ro) {
if let Some(version) = ec_binary::read_ec_version(data, true) {
println!("EC RO Version in File: {:?}", version.version);
if version.details.platform != platform {
Expand All @@ -832,7 +834,7 @@ impl CrosEc {
));
}
}
if ft == EcFlashType::Full || ft == EcFlashType::Rw {
if matches!(ft, EcFlashType::Full | EcFlashType::Both | EcFlashType::Rw) {
if let Some(version) = ec_binary::read_ec_version(data, false) {
println!("EC RW Version in File: {:?}", version.version);
if version.details.platform != platform {
Expand Down Expand Up @@ -874,7 +876,41 @@ impl CrosEc {
// 2. Read back two rows and make sure it's all 0xFF
// 3. Write each row (128B) individually

if ft == EcFlashType::Full || ft == EcFlashType::Rw {
if ft == EcFlashType::Full {
if data.len() < FLASH_SIZE as usize {
return Err(EcError::DeviceError(format!(
"Firmware file too small for full flash. Expected {} bytes, got {}",
FLASH_SIZE,
data.len()
)));
}
let data = &data[..FLASH_SIZE as usize];

println!(
"Erasing full flash{}",
if dry_run { " (DRY RUN)" } else { "" }
);
self.erase_ec_flash(FLASH_BASE, FLASH_SIZE, dry_run, info.erase_block_size)?;
println!(" Done");

println!(
"Writing full flash{}",
if dry_run { " (DRY RUN)" } else { "" }
);
self.write_ec_flash(FLASH_BASE, data, dry_run)?;
println!(" Done");

println!("Verifying full flash region");
let flash_data = self.read_ec_flash(FLASH_BASE, FLASH_SIZE)?;
if data == flash_data {
println!(" flash verify success");
} else {
error!("Flash verify fail!");
res = Err(EcError::DeviceError("Flash verify fail!".to_string()));
}
}

if ft == EcFlashType::Both || ft == EcFlashType::Rw {
let rw_data = &data[FLASH_RW_BASE as usize..(FLASH_RW_BASE + FLASH_RW_SIZE) as usize];

println!(
Expand Down Expand Up @@ -906,7 +942,7 @@ impl CrosEc {
}
}

if ft == EcFlashType::Full || ft == EcFlashType::Ro {
if ft == EcFlashType::Both || ft == EcFlashType::Ro {
let ro_data = &data[FLASH_RO_BASE as usize..(FLASH_RO_BASE + FLASH_RO_SIZE) as usize];

println!("Erasing RO region");
Expand Down
7 changes: 7 additions & 0 deletions framework_lib/src/commandline/clap_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ struct ClapCli {
#[arg(long)]
dump_ec_flash: Option<std::path::PathBuf>,

/// Flash full EC flash with new firmware from file - may render your hardware unbootable!
#[arg(long)]
flash_full_ec: Option<std::path::PathBuf>,

/// Flash EC (RO+RW) with new firmware from file - may render your hardware unbootable!
#[arg(long)]
flash_ec: Option<std::path::PathBuf>,
Expand Down Expand Up @@ -497,6 +501,9 @@ pub fn parse(args: &[String]) -> Cli {
dump_ec_flash: args
.dump_ec_flash
.map(|x| x.into_os_string().into_string().unwrap()),
flash_full_ec: args
.flash_full_ec
.map(|x| x.into_os_string().into_string().unwrap()),
flash_ec: args
.flash_ec
.map(|x| x.into_os_string().into_string().unwrap()),
Expand Down
10 changes: 9 additions & 1 deletion framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ pub struct Cli {
pub dump: Option<String>,
pub h2o_capsule: Option<String>,
pub dump_ec_flash: Option<String>,
pub flash_full_ec: Option<String>,
pub flash_ec: Option<String>,
pub flash_ro_ec: Option<String>,
pub flash_rw_ec: Option<String>,
Expand Down Expand Up @@ -273,6 +274,7 @@ pub fn parse(args: &[String]) -> Cli {
dump: cli.dump,
h2o_capsule: cli.h2o_capsule,
// dump_ec_flash
// flash_full_ec
// flash_ec
// flash_ro_ec
// flash_rw_ec
Expand Down Expand Up @@ -1722,9 +1724,15 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
println!("Dumping to {}", dump_path);
// TODO: Should have progress indicator
dump_ec_flash(&ec, dump_path);
} else if let Some(ec_bin_path) = &args.flash_ec {
} else if let Some(ec_bin_path) = &args.flash_full_ec {
if args.force {
flash_ec(&ec, ec_bin_path, EcFlashType::Full, args.dry_run);
} else {
error!("Flashing full EC flash is unsafe. Use --flash-ec instead");
}
} else if let Some(ec_bin_path) = &args.flash_ec {
if args.force {
flash_ec(&ec, ec_bin_path, EcFlashType::Both, args.dry_run);
} else {
error!("Flashing EC RO region is unsafe. Use --flash-ec-rw instead");
}
Expand Down
9 changes: 9 additions & 0 deletions framework_lib/src/commandline/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub fn parse(args: &[String]) -> Cli {
pd_bin: None,
ec_bin: None,
dump_ec_flash: None,
flash_full_ec: None,
flash_ec: None,
flash_ro_ec: None,
flash_rw_ec: None,
Expand Down Expand Up @@ -654,6 +655,14 @@ pub fn parse(args: &[String]) -> Cli {
None
};
found_an_option = true;
} else if arg == "--flash-full-ec" {
cli.flash_full_ec = if args.len() > i + 1 {
Some(args[i + 1].clone())
} else {
println!("--flash-full-ec requires extra argument to denote input file");
None
};
found_an_option = true;
} else if arg == "--flash-ec" {
cli.flash_ec = if args.len() > i + 1 {
Some(args[i + 1].clone())
Expand Down
6 changes: 5 additions & 1 deletion framework_tool/completions/bash/framework_tool
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _framework_tool() {

case "${cmd}" in
framework_tool)
opts="-v -q -t -f -h --flash-gpu-descriptor --verbose --quiet --versions --version --features --esrt --device --compare-version --power --thermal --sensors --fansetduty --fansetrpm --autofanctrl --pdports --info --meinfo --pd-info --pd-reset --pd-disable --pd-enable --dp-hdmi-info --dp-hdmi-update --audio-card-info --privacy --pd-bin --ec-bin --capsule --dump --h2o-capsule --dump-ec-flash --flash-ec --flash-ro-ec --flash-rw-ec --intrusion --inputdeck --inputdeck-mode --expansion-bay --charge-limit --charge-current-limit --charge-rate-limit --get-gpio --fp-led-level --fp-brightness --kblight --remap-key --rgbkbd --ps2-enable --tablet-mode --touchscreen-enable --stylus-battery --console --reboot-ec --ec-hib-delay --uptimeinfo --s0ix-counter --hash --driver --pd-addrs --pd-ports --test --test-retimer --boardid --force --dry-run --flash-gpu-descriptor-file --dump-gpu-descriptor-file --nvidia --host-command --generate-completions --help"
opts="-v -q -t -f -h --flash-gpu-descriptor --verbose --quiet --versions --version --features --esrt --device --compare-version --power --thermal --sensors --fansetduty --fansetrpm --autofanctrl --pdports --info --meinfo --pd-info --pd-reset --pd-disable --pd-enable --dp-hdmi-info --dp-hdmi-update --audio-card-info --privacy --pd-bin --ec-bin --capsule --dump --h2o-capsule --dump-ec-flash --flash-full-ec --flash-ec --flash-ro-ec --flash-rw-ec --intrusion --inputdeck --inputdeck-mode --expansion-bay --charge-limit --charge-current-limit --charge-rate-limit --get-gpio --fp-led-level --fp-brightness --kblight --remap-key --rgbkbd --ps2-enable --tablet-mode --touchscreen-enable --stylus-battery --console --reboot-ec --ec-hib-delay --uptimeinfo --s0ix-counter --hash --driver --pd-addrs --pd-ports --test --test-retimer --boardid --force --dry-run --flash-gpu-descriptor-file --dump-gpu-descriptor-file --nvidia --host-command --generate-completions --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -97,6 +97,10 @@ _framework_tool() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--flash-full-ec)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--flash-ec)
COMPREPLY=($(compgen -f "${cur}"))
return 0
Expand Down
1 change: 1 addition & 0 deletions framework_tool/completions/fish/framework_tool.fish
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ complete -c framework_tool -l capsule -d 'Parse UEFI Capsule information from bi
complete -c framework_tool -l dump -d 'Dump extracted UX capsule bitmap image to a file' -r -F
complete -c framework_tool -l h2o-capsule -d 'Parse UEFI Capsule information from binary file' -r -F
complete -c framework_tool -l dump-ec-flash -d 'Dump EC flash contents' -r -F
complete -c framework_tool -l flash-full-ec -d 'Flash full EC flash with new firmware from file - may render your hardware unbootable!' -r -F
complete -c framework_tool -l flash-ec -d 'Flash EC (RO+RW) with new firmware from file - may render your hardware unbootable!' -r -F
complete -c framework_tool -l flash-ro-ec -d 'Flash EC with new RO firmware from file - may render your hardware unbootable!' -r -F
complete -c framework_tool -l flash-rw-ec -d 'Flash EC with new RW firmware from file' -r -F
Expand Down
1 change: 1 addition & 0 deletions framework_tool/completions/zsh/_framework_tool
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ _framework_tool() {
'--dump=[Dump extracted UX capsule bitmap image to a file]:DUMP:_files' \
'--h2o-capsule=[Parse UEFI Capsule information from binary file]:H2O_CAPSULE:_files' \
'--dump-ec-flash=[Dump EC flash contents]:DUMP_EC_FLASH:_files' \
'--flash-full-ec=[Flash full EC flash with new firmware from file - may render your hardware unbootable!]:FLASH_FULL_EC:_files' \
'--flash-ec=[Flash EC (RO+RW) with new firmware from file - may render your hardware unbootable!]:FLASH_EC:_files' \
'--flash-ro-ec=[Flash EC with new RO firmware from file - may render your hardware unbootable!]:FLASH_RO_EC:_files' \
'--flash-rw-ec=[Flash EC with new RW firmware from file]:FLASH_RW_EC:_files' \
Expand Down
Loading