api: added reboot into FEL mode
authorSven Rademakers <sven.rademakers@gmail.com>
Sat, 3 Feb 2024 20:29:26 +0000 (20:29 +0000)
committerSven Rademakers <sven.rademakers@gmail.com>
Sat, 3 Feb 2024 20:29:26 +0000 (20:29 +0000)
FEL mode is a recovery mechanism of BMC's bootROM.

Cargo.lock
Cargo.toml
src/api/legacy.rs
src/app/bmc_application.rs
src/app/event_application.rs

index 9531d2b59753f381c0263491bdcd6e52d83fb7a1..9ab1a6c961e62b1665cb1c2211d4f3f87110fe23 100644 (file)
@@ -509,6 +509,28 @@ dependencies = [
  "serde",
 ]
 
+[[package]]
+name = "bindgen"
+version = "0.64.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4"
+dependencies = [
+ "bitflags 1.3.2",
+ "cexpr",
+ "clang-sys",
+ "lazy_static",
+ "lazycell",
+ "log",
+ "peeking_take_while",
+ "proc-macro2",
+ "quote",
+ "regex",
+ "rustc-hash",
+ "shlex",
+ "syn 1.0.109",
+ "which",
+]
+
 [[package]]
 name = "bitflags"
 version = "1.3.2"
@@ -594,6 +616,7 @@ dependencies = [
  "log",
  "nix 0.27.1",
  "openssl",
+ "peekpoke",
  "pin-project",
  "pwhash",
  "rand 0.8.5",
@@ -688,6 +711,15 @@ dependencies = [
  "libc",
 ]
 
+[[package]]
+name = "cexpr"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
+dependencies = [
+ "nom",
+]
+
 [[package]]
 name = "cfg-if"
 version = "1.0.0"
@@ -724,6 +756,17 @@ version = "0.1.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "b8da9d36ad01a07a2c380bdece16e418820ffa8eda01d3debed9bff3f296a84f"
 
+[[package]]
+name = "clang-sys"
+version = "1.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1"
+dependencies = [
+ "glob",
+ "libc",
+ "libloading",
+]
+
 [[package]]
 name = "clap"
 version = "4.4.18"
@@ -945,6 +988,12 @@ dependencies = [
  "crypto-common",
 ]
 
+[[package]]
+name = "either"
+version = "1.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
+
 [[package]]
 name = "encoding_rs"
 version = "0.8.33"
@@ -1180,6 +1229,12 @@ version = "0.28.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
 
+[[package]]
+name = "glob"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
+
 [[package]]
 name = "gpiod"
 version = "0.2.3"
@@ -1251,6 +1306,15 @@ dependencies = [
  "digest 0.9.0",
 ]
 
+[[package]]
+name = "home"
+version = "0.5.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
+dependencies = [
+ "windows-sys 0.52.0",
+]
+
 [[package]]
 name = "http"
 version = "0.2.11"
@@ -1503,12 +1567,28 @@ version = "1.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
 
+[[package]]
+name = "lazycell"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
+
 [[package]]
 name = "libc"
 version = "0.2.152"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7"
 
+[[package]]
+name = "libloading"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161"
+dependencies = [
+ "cfg-if",
+ "windows-sys 0.48.0",
+]
+
 [[package]]
 name = "libm"
 version = "0.2.8"
@@ -1637,6 +1717,12 @@ dependencies = [
  "unicase",
 ]
 
+[[package]]
+name = "minimal-lexical"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
+
 [[package]]
 name = "miniz_oxide"
 version = "0.7.1"
@@ -1726,6 +1812,16 @@ dependencies = [
  "libc",
 ]
 
+[[package]]
+name = "nom"
+version = "7.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
+dependencies = [
+ "memchr",
+ "minimal-lexical",
+]
+
 [[package]]
 name = "num-traits"
 version = "0.2.17"
@@ -1885,6 +1981,22 @@ version = "1.0.14"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
 
+[[package]]
+name = "peeking_take_while"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
+
+[[package]]
+name = "peekpoke"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c0d3446e3a050c7a2727b1a6318a1043cbf5c0a0a2fc5db3bc5dd84234bddbcf"
+dependencies = [
+ "bindgen",
+ "cc",
+]
+
 [[package]]
 name = "percent-encoding"
 version = "2.3.1"
@@ -2183,6 +2295,12 @@ version = "0.1.23"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
 
+[[package]]
+name = "rustc-hash"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
+
 [[package]]
 name = "rustc_version"
 version = "0.4.0"
@@ -2425,6 +2543,12 @@ dependencies = [
  "digest 0.10.7",
 ]
 
+[[package]]
+name = "shlex"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
+
 [[package]]
 name = "signal-hook-registry"
 version = "1.4.1"
@@ -2964,6 +3088,18 @@ dependencies = [
  "wasm-bindgen",
 ]
 
+[[package]]
+name = "which"
+version = "4.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
+dependencies = [
+ "either",
+ "home",
+ "once_cell",
+ "rustix",
+]
+
 [[package]]
 name = "winapi"
 version = "0.3.9"
index 542eccaae179db28bf76fd07d1591a23a5d7574b..fb2cc8c7b15a089536a7e5475a0ec7a54579b09b 100644 (file)
@@ -35,6 +35,7 @@ inotify = "0.10.2"
 log = "0.4.20"
 nix = { version = "0.27.1", features = ["fs", "feature"] }
 openssl = "0.10.63"
+peekpoke = "0.3.0"
 pin-project = "1.1.4"
 pwhash = "1.0.0"
 rand = "0.8.5"
index e79f1ee863d3c1bf602ac08b98e31f06563fe33a..4bef15f3168c48100a7e89042156b41df5947147 100644 (file)
@@ -171,7 +171,7 @@ async fn api_entry(
         ("other", false) => get_system_information().await.into(),
         ("power", true) => set_node_power(bmc, query).await,
         ("power", false) => get_node_power(bmc).await.into(),
-        ("reboot", true) => reboot().await.into(),
+        ("reboot", true) => reboot(query).await.into(),
         ("reload", true) => reload_self().into(),
         ("reset", true) => reset_node(bmc, query).await.into(),
         ("sdcard", true) => format_sdcard().into(),
@@ -240,8 +240,10 @@ async fn get_info() -> impl Into<LegacyResponse> {
     )
 }
 
-async fn reboot() -> LegacyResult<()> {
-    BmcApplication::reboot().await.map_err(Into::into)
+async fn reboot(query: Query) -> LegacyResult<()> {
+    BmcApplication::reboot(query.contains_key("fel"))
+        .await
+        .map_err(Into::into)
 }
 
 async fn reset_node(bmc: &BmcApplication, query: Query) -> LegacyResult<()> {
index 40c4247a5a75aa476e80e75cc3e41ea5f3c7015d..f84aa9e283b2afcb7c17e2212557db335c82c32c 100644 (file)
@@ -290,7 +290,12 @@ impl BmcApplication {
             .context("error clearing usbboot")
     }
 
-    pub async fn reboot() -> anyhow::Result<()> {
+    pub async fn reboot(fel: bool) -> anyhow::Result<()> {
+        if fel {
+            peekpoke::write(0x0709_0108, 0x5AA5_A55A);
+            log::warn!("system reboot into FEL");
+        }
+
         tokio::fs::write("/sys/class/leds/fp:reset/brightness", b"1").await?;
         Command::new("shutdown").args(["-r", "now"]).spawn()?;
         Ok(())
index f5265e62d577014fa67ebf5fc8d8a971b218bad8..4283f619430748d570e3389839327a317bd9c20d 100644 (file)
@@ -43,7 +43,7 @@ pub fn run_event_listener(instance: Arc<BmcApplication>) -> anyhow::Result<()> {
         tokio::spawn(async move { bmc.toggle_power_states(false).await });
     })
     .add_action(Key::KEY_RESTART, 1, |_| {
-        tokio::spawn(BmcApplication::reboot());
+        tokio::spawn(BmcApplication::reboot(false));
     })
     .run()
     .context("event_listener error")