From 75b52bda0481c2911f983f1c9326a2625f40b20b Mon Sep 17 00:00:00 2001 From: Sven Rademakers Date: Sat, 6 May 2023 13:29:40 +0100 Subject: [PATCH] GH-22 GH-42 WIP this commit contains the following changes: * tpi_common is moved out of the buildroot folder. we intend on keeping this folder clean * renamed tpi_common to tpi_rust, so its more clear that from here the rust development grows. Later when this component matures it probably its a good time to revise the name * removed the dependency of the usbboot buildroot package as it seems that rust already have a crate which does this for us * added an "app app_persistency". For now is chosen to use sqlite as backend. We might choose something lighter in the future as its used as key/value store for now * WIP pin_controller * WIP evdev_controller --- app/bmc/Makefile | 4 +- app/bmc/bmc.c | 2 - app/tpi_common/Cargo.lock | 7 - app/tpi_common/Cargo.toml | 8 - app/tpi_common/src/lib.rs | 8 - app/tpi_common/tpi_common.h | 5 - buildroot/package/tpi_common/Config.in | 7 - buildroot/package/tpi_common/tpi_common.mk | 18 - tp2bmc/configs/tp2bmc_defconfig | 6 +- tp2bmc/package/bmc/Config.in | 2 +- tp2bmc/package/bmc/bmc.mk | 2 +- tp2bmc/package/tpi_rs/Cargo.lock | 1367 +++++++++++++++++ tp2bmc/package/tpi_rs/Cargo.toml | 29 + tp2bmc/package/tpi_rs/Config.in | 6 + .../package/tpi_rs}/LICENSE | 0 .../package/tpi_rs/src/app/bmc_application.rs | 123 ++ tp2bmc/package/tpi_rs/src/app/mod.rs | 1 + tp2bmc/package/tpi_rs/src/c_interface.rs | 102 ++ tp2bmc/package/tpi_rs/src/lib.rs | 3 + .../tpi_rs/src/middleware/app_persistency.rs | 172 +++ .../tpi_rs/src/middleware/evdev_controller.rs | 27 + .../tpi_rs/src/middleware/gpio_definitions.rs | 46 + tp2bmc/package/tpi_rs/src/middleware/mod.rs | 35 + .../tpi_rs/src/middleware/pin_controller.rs | 163 ++ .../package/tpi_rs/src/middleware/usbboot.rs | 0 tp2bmc/package/tpi_rs/tpi_rs.h | 28 + tp2bmc/package/tpi_rs/tpi_rs.mk | 35 + 27 files changed, 2144 insertions(+), 62 deletions(-) delete mode 100644 app/tpi_common/Cargo.lock delete mode 100644 app/tpi_common/Cargo.toml delete mode 100644 app/tpi_common/src/lib.rs delete mode 100644 app/tpi_common/tpi_common.h delete mode 100644 buildroot/package/tpi_common/Config.in delete mode 100644 buildroot/package/tpi_common/tpi_common.mk create mode 100644 tp2bmc/package/tpi_rs/Cargo.lock create mode 100644 tp2bmc/package/tpi_rs/Cargo.toml create mode 100644 tp2bmc/package/tpi_rs/Config.in rename {app/tpi_common => tp2bmc/package/tpi_rs}/LICENSE (100%) create mode 100644 tp2bmc/package/tpi_rs/src/app/bmc_application.rs create mode 100644 tp2bmc/package/tpi_rs/src/app/mod.rs create mode 100644 tp2bmc/package/tpi_rs/src/c_interface.rs create mode 100644 tp2bmc/package/tpi_rs/src/lib.rs create mode 100644 tp2bmc/package/tpi_rs/src/middleware/app_persistency.rs create mode 100644 tp2bmc/package/tpi_rs/src/middleware/evdev_controller.rs create mode 100644 tp2bmc/package/tpi_rs/src/middleware/gpio_definitions.rs create mode 100644 tp2bmc/package/tpi_rs/src/middleware/mod.rs create mode 100644 tp2bmc/package/tpi_rs/src/middleware/pin_controller.rs create mode 100644 tp2bmc/package/tpi_rs/src/middleware/usbboot.rs create mode 100644 tp2bmc/package/tpi_rs/tpi_rs.h create mode 100644 tp2bmc/package/tpi_rs/tpi_rs.mk diff --git a/app/bmc/Makefile b/app/bmc/Makefile index 23213c56..daac0bc9 100755 --- a/app/bmc/Makefile +++ b/app/bmc/Makefile @@ -1,5 +1,5 @@ -CPPFLAGS += -LDLIBS += -L./lib/ -lpthread -lgo -lcjson -ltpi_common +CPPFLAGS += +LDLIBS += -L./lib/ -lpthread -lgo -lcjson -ltpi_rs -ldl -lm all: bmc diff --git a/app/bmc/bmc.c b/app/bmc/bmc.c index 4bbc3bae..33abbbda 100755 --- a/app/bmc/bmc.c +++ b/app/bmc/bmc.c @@ -19,8 +19,6 @@ #include "comm_device_serial.h" -#include - #define RTL_RESET GPIO_PIN_PG(13) #define SYS_LED GPIO_PIN_PG(8) #define RESET_LED GPIO_PIN_PG(9) diff --git a/app/tpi_common/Cargo.lock b/app/tpi_common/Cargo.lock deleted file mode 100644 index 5d0a8e57..00000000 --- a/app/tpi_common/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "tpi_common" -version = "0.0.0" diff --git a/app/tpi_common/Cargo.toml b/app/tpi_common/Cargo.toml deleted file mode 100644 index 577f7e28..00000000 --- a/app/tpi_common/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "tpi_common" -version = "0.0.0" -edition = "2021" -license = "Apache-2.0" - -[lib] -crate-type = ["lib", "staticlib"] diff --git a/app/tpi_common/src/lib.rs b/app/tpi_common/src/lib.rs deleted file mode 100644 index c1f8d2af..00000000 --- a/app/tpi_common/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub fn add(x: i32, y: i32) -> i32 { - x + y -} - -#[no_mangle] -pub extern "C" fn c_add(x: i32, y: i32) -> i32 { - add(x, y) -} diff --git a/app/tpi_common/tpi_common.h b/app/tpi_common/tpi_common.h deleted file mode 100644 index 06c68243..00000000 --- a/app/tpi_common/tpi_common.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -int32_t c_add(int32_t x, int32_t y); diff --git a/buildroot/package/tpi_common/Config.in b/buildroot/package/tpi_common/Config.in deleted file mode 100644 index a510025e..00000000 --- a/buildroot/package/tpi_common/Config.in +++ /dev/null @@ -1,7 +0,0 @@ -config BR2_PACKAGE_TPI_COMMON - bool "tpi_common" - depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS - select BR2_PACKAGE_HOST_RUSTC - help - Static library with node flashing functionality for - version 1 of the TPI 2 firmware diff --git a/buildroot/package/tpi_common/tpi_common.mk b/buildroot/package/tpi_common/tpi_common.mk deleted file mode 100644 index 9f1099cd..00000000 --- a/buildroot/package/tpi_common/tpi_common.mk +++ /dev/null @@ -1,18 +0,0 @@ -########################################################### -# -# tpi_common -# -########################################################### - -TPI_COMMON_VERSION = 0.0.0 -TPI_COMMON_SITE = $(TOPDIR)/../app/tpi_common -TPI_COMMON_SITE_METHOD = local -TPI_COMMON_INSTALL_STAGING = YES -TPI_COMMON_INSTALL_TARGET = NO - -define TPI_COMMON_INSTALL_STAGING_CMDS - $(INSTALL) -D -m 0644 $(@D)/target/$(RUSTC_TARGET_NAME)/release/libtpi_common.a $(STAGING_DIR)/lib - $(INSTALL) -D -m 0644 $(@D)/tpi_common.h $(STAGING_DIR)/usr/include -endef - -$(eval $(cargo-package)) diff --git a/tp2bmc/configs/tp2bmc_defconfig b/tp2bmc/configs/tp2bmc_defconfig index acb4b272..8e850695 100644 --- a/tp2bmc/configs/tp2bmc_defconfig +++ b/tp2bmc/configs/tp2bmc_defconfig @@ -67,7 +67,6 @@ BR2_PACKAGE_HOST_GENIMAGE=y BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_4=y BR2_PACKAGE_HOST_MTOOLS=y -# wy modify BR2_PACKAGE_CJSON=y BR2_TARGET_GENERIC_ROOT_PASSWD="turing" BR2_PACKAGE_MTD=y @@ -91,9 +90,9 @@ BR2_PACKAGE_LIBTIRPC=y BR2_PACKAGE_LIBEVENT=y BR2_PACKAGE_COLLECTD=y BR2_PACKAGE_COLLECTD_CURL=y -BR2_PACKAGE_RPCBIND=y BR2_PACKAGE_KEYUTILS=y - +BR2_PACKAGE_LIBGPIOD=y +BR2_PACKAGE_EVTEST=y BR2_PACKAGE_BMC=y BR2_PACKAGE_TPI=y @@ -105,3 +104,4 @@ BR2_PACKAGE_TPI_COMMON=y BR2_PACKAGE_RASPBERRYPI_USBBOOT=y +BR2_PACKAGE_TPI_RS=y diff --git a/tp2bmc/package/bmc/Config.in b/tp2bmc/package/bmc/Config.in index 8e8a9e4f..486f248a 100644 --- a/tp2bmc/package/bmc/Config.in +++ b/tp2bmc/package/bmc/Config.in @@ -1,5 +1,5 @@ config BR2_PACKAGE_BMC bool "bmc" - depends on BR2_PACKAGE_TPI_COMMON || BR2_PACKAGE_RASPBERRYPI_USBBOOT + depends on BR2_PACKAGE_TPI_RS help This is a bmc diff --git a/tp2bmc/package/bmc/bmc.mk b/tp2bmc/package/bmc/bmc.mk index 141c8a4f..92098a4a 100644 --- a/tp2bmc/package/bmc/bmc.mk +++ b/tp2bmc/package/bmc/bmc.mk @@ -6,7 +6,7 @@ BMC_VERSION:= 1.0.0 BMC_SITE:= $(TOPDIR)/../app/bmc BMC_SITE_METHOD:=local BMC_INSTALL_TARGET:=YES -BMC_DEPENDENCIES = cjson tpi_common raspberrypi-usbboot +BMC_DEPENDENCIES = cjson tpi_rs define BMC_BUILD_CMDS $(MAKE) CC="$(TARGET_CC)" LD="$(TARGET_LD)" -C $(@D) all diff --git a/tp2bmc/package/tpi_rs/Cargo.lock b/tp2bmc/package/tpi_rs/Cargo.lock new file mode 100644 index 00000000..a115032c --- /dev/null +++ b/tp2bmc/package/tpi_rs/Cargo.lock @@ -0,0 +1,1367 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "anyhow" +version = "1.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" + +[[package]] +name = "async-trait" +version = "0.1.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.15", +] + +[[package]] +name = "atoi" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e" +dependencies = [ + "num-traits", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base64" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c6ed94e98ecff0c12dd1b04c15ec0d7d9458ca8fe806cea6f12954efe74c63b" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cpufeatures" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" + +[[package]] +name = "crossbeam-queue" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "evdev" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bed59fcc8cfd6b190814a509018388462d3b203cf6dd10db5c00087e72a83f3" +dependencies = [ + "bitvec", + "cfg-if", + "futures-core", + "libc", + "nix 0.23.2", + "thiserror", + "tokio", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "flume" +version = "0.10.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" +dependencies = [ + "futures-core", + "futures-sink", + "pin-project", + "spin 0.9.8", +] + +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" + +[[package]] +name = "futures-executor" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a604f7a68fbf8103337523b1fadc8ade7361ee3f112f7c680ad179651616aed5" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-macro" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.15", +] + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "futures-task" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" + +[[package]] +name = "futures-util" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gpiod" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "262a4f47f419475031188f70ca019e8d035ac3849f296fd7ccff8018804f6d53" +dependencies = [ + "gpiod-core", +] + +[[package]] +name = "gpiod-core" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e40a9a5455e6b1fb75d0020d14d8628932ce5f8020cd5fe378feb13761a98bf" +dependencies = [ + "nix 0.26.2", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashlink" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69fe1fcf8b4278d860ad0548329f892a3631fb63f82574df68275f34cdbe0ffa" +dependencies = [ + "hashbrown", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "js-sys" +version = "0.3.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68c16e1bfd491478ab155fd8b4896b86f9ede344949b641e61501e07c2b8b4d5" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.144" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" + +[[package]] +name = "libsqlite3-sys" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "mio" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.45.0", +] + +[[package]] +name = "nix" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset", +] + +[[package]] +name = "nix" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +dependencies = [ + "bitflags", + "cfg-if", + "libc", + "static_assertions", +] + +[[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.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "paste" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" + +[[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" + +[[package]] +name = "proc-macro2" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted", + "web-sys", + "winapi", +] + +[[package]] +name = "rustls" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" +dependencies = [ + "base64", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "slab" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "sqlformat" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c12bc9199d1db8234678b7051747c07f517cdcf019262d1847b94ec8b1aee3e" +dependencies = [ + "itertools", + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8de3b03a925878ed54a954f621e64bf55a3c1bd29652d0d1a17830405350188" +dependencies = [ + "sqlx-core", + "sqlx-macros", +] + +[[package]] +name = "sqlx-core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa8241483a83a3f33aa5fff7e7d9def398ff9990b2752b6c6112b83c6d246029" +dependencies = [ + "ahash", + "atoi", + "bitflags", + "byteorder", + "bytes", + "crc", + "crossbeam-queue", + "dotenvy", + "either", + "event-listener", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "hashlink", + "hex", + "indexmap", + "itoa", + "libc", + "libsqlite3-sys", + "log", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "rustls", + "rustls-pemfile", + "sha2", + "smallvec", + "sqlformat", + "sqlx-rt", + "stringprep", + "thiserror", + "tokio-stream", + "url", + "webpki-roots", +] + +[[package]] +name = "sqlx-macros" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9966e64ae989e7e575b19d7265cb79d7fc3cbbdf179835cb0d716f294c2049c9" +dependencies = [ + "dotenvy", + "either", + "heck", + "once_cell", + "proc-macro2", + "quote", + "sha2", + "sqlx-core", + "sqlx-rt", + "syn 1.0.109", + "url", +] + +[[package]] +name = "sqlx-rt" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "804d3f245f894e61b1e6263c84b23ca675d96753b5abfd5cc8597d86806e8024" +dependencies = [ + "once_cell", + "tokio", + "tokio-rustls", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "stringprep" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "thiserror" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.15", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aa32867d44e6f2ce3385e89dceb990188b8bb0fb25b0cf576647a6f98ac5105" +dependencies = [ + "autocfg", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.15", +] + +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls", + "tokio", + "webpki", +] + +[[package]] +name = "tokio-stream" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tpi_rs" +version = "0.0.0" +dependencies = [ + "anyhow", + "async-trait", + "evdev", + "futures", + "gpiod", + "log", + "once_cell", + "sqlx", + "tokio", +] + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + +[[package]] +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b6cb788c4e39112fbe1822277ef6fb3c55cd86b95cb3d3c4c1c9597e4ac74b4" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e522ed4105a9d626d885b35d62501b30d9666283a5c8be12c14a8bdafe7822" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.15", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "358a79a0cb89d21db8120cbfb91392335913e4890665b1a7981d9e956903b434" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4783ce29f09b9d93134d41297aded3a712b7b979e9c6f28c32cb88c973a94869" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.15", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a901d592cafaa4d711bc324edfaff879ac700b19c3dfd60058d2b445be2691eb" + +[[package]] +name = "web-sys" +version = "0.3.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b5f940c7edfdc6d12126d98c9ef4d1b3d470011c47c76a6581df47ad9ba721" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +dependencies = [ + "webpki", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] diff --git a/tp2bmc/package/tpi_rs/Cargo.toml b/tp2bmc/package/tpi_rs/Cargo.toml new file mode 100644 index 00000000..501d4683 --- /dev/null +++ b/tp2bmc/package/tpi_rs/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tpi_rs" +version = "0.0.0" +edition = "2021" +license = "Apache-2.0" + +[lib] +crate-type = ["lib", "staticlib"] + +[dependencies] +once_cell = "*" +tokio = { version = "*", features = [ + "rt-multi-thread", + "rt", + "time", + "macros" +] } +gpiod = "*" +evdev = { version = "*", features = [ + "tokio" +] } +futures = "*" +anyhow = "*" +async-trait = "*" +sqlx = { version = "*", features = [ + "runtime-tokio-rustls", + "sqlite" +] } +log = "*" diff --git a/tp2bmc/package/tpi_rs/Config.in b/tp2bmc/package/tpi_rs/Config.in new file mode 100644 index 00000000..28b1fbcd --- /dev/null +++ b/tp2bmc/package/tpi_rs/Config.in @@ -0,0 +1,6 @@ +config BR2_PACKAGE_TPI_RS + bool "tpi_rs" + depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS || BR2_PACKAGE_SQLITE + select BR2_PACKAGE_HOST_RUSTC + help + development of the rust version of the tp2 diff --git a/app/tpi_common/LICENSE b/tp2bmc/package/tpi_rs/LICENSE similarity index 100% rename from app/tpi_common/LICENSE rename to tp2bmc/package/tpi_rs/LICENSE diff --git a/tp2bmc/package/tpi_rs/src/app/bmc_application.rs b/tp2bmc/package/tpi_rs/src/app/bmc_application.rs new file mode 100644 index 00000000..b0155972 --- /dev/null +++ b/tp2bmc/package/tpi_rs/src/app/bmc_application.rs @@ -0,0 +1,123 @@ +use crate::middleware::{ + app_persistency::ApplicationPersistency, evdev_controller::linux_event_stream, + pin_controller::PinController, NodeId, +}; +use anyhow::Context; +use std::ops::Deref; +use std::{mem::size_of, sync::Arc}; + +const POWER_STATE_KEY: &str = "power_state"; + +#[derive(Debug)] +pub struct BmcApplication { + pin_controller: Arc, + app_db: ApplicationPersistency, +} + +impl BmcApplication { + pub async fn new() -> anyhow::Result { + let pin_controller = Arc::new(PinController::new().await?); + let app_db = ApplicationPersistency::new().await?; + + let instance = Self { + pin_controller, + app_db, + }; + + instance.initialize().await?; + Ok(instance) + } + + async fn initialize(&self) -> anyhow::Result<()> { + // power on nodes + if let Ok(power_state) = self.app_db.get::(POWER_STATE_KEY).await { + self.node_power_internal(power_state, 15, 0, power_state) + .await?; + } + + self.run_event_listener(); + Ok(()) + } + + fn run_event_listener(&self) { + tokio::spawn(async move { + let mut event_stream = linux_event_stream().unwrap(); + while let Ok(event) = event_stream.next_event().await { + todo!() + } + }); + } + + async fn node_power_internal( + &self, + node: u8, + mask: u8, + current_node_state: u8, + new_node_state: u8, + ) -> anyhow::Result<()> { + if let Some(on) = Self::need_atx_change(current_node_state, new_node_state) { + self.pin_controller.deref().atx_power(on).await?; + } + + self.pin_controller + .power_node(node, mask) + .await + .context("pin controller error") + } + + fn need_atx_change(current_node_state: u8, next_node_state: u8) -> Option { + if current_node_state == 0 && next_node_state > 0 { + // power down + Some(true) + } else if current_node_state > 0 && next_node_state == 0 { + // power up + Some(false) + } else { + // dont do anything + None + } + } + + pub async fn power_node(&self, node: NodeId, on: bool) -> anyhow::Result<()> { + let mut bits = node as u8; + if !on { + bits = !bits; + } + + let power_state = self.app_db.get::(POWER_STATE_KEY).await?; + let new_power_state = Self::append_bitfield_with_mask(power_state, bits, node as u8); + + self.node_power_internal(bits, node as u8, power_state, new_power_state) + .await?; + + self.app_db.set(POWER_STATE_KEY, new_power_state).await + } + + pub fn append_bitfield_with_mask(current: u8, bits: u8, mask: u8) -> u8 { + let mut result = current; + for n in 0..size_of::() { + // continue if bit is not to be written + if (mask & (1 << n)) == 0 { + continue; + } + + // check if bit need to written high or low + let high = (bits & (1 << n)) != 0; + + result = if high { + result | (1 << n) + } else { + result & !(1 << n) + }; + } + result + } + + pub async fn flash_node>( + &self, + node: NodeId, + node_image: P, + ) -> anyhow::Result<()> { + todo!() + } +} diff --git a/tp2bmc/package/tpi_rs/src/app/mod.rs b/tp2bmc/package/tpi_rs/src/app/mod.rs new file mode 100644 index 00000000..61408b1d --- /dev/null +++ b/tp2bmc/package/tpi_rs/src/app/mod.rs @@ -0,0 +1 @@ +pub mod bmc_application; diff --git a/tp2bmc/package/tpi_rs/src/c_interface.rs b/tp2bmc/package/tpi_rs/src/c_interface.rs new file mode 100644 index 00000000..e46eacc8 --- /dev/null +++ b/tp2bmc/package/tpi_rs/src/c_interface.rs @@ -0,0 +1,102 @@ +//! This module acts as a glue layer for the legacy bmc application. It exports +//! relevant API functions over FFI. This FFI interface is temporary and will be +//! removed as soon as the bmc application is end of life. +use crate::{app::bmc_application::BmcApplication, middleware::NodeId}; +use once_cell::sync::{Lazy, OnceCell}; +use std::{ffi::CStr, ops::Deref}; +use tokio::{runtime::Runtime, sync::Mutex}; + +/// we need means to synchronize async call to the outside. This runtime +/// enables us to execute async calls in a blocking fashion. +static RUNTIME: Lazy = + Lazy::new(|| Runtime::new().expect("fatal error initializing runtime")); +static APP: OnceCell> = OnceCell::new(); + +#[no_mangle] +pub extern "C" fn initialize() { + RUNTIME.block_on(async move { + APP.set(Mutex::new( + BmcApplication::new().await.expect("unable to initialize"), + )) + .expect("initialize to be called once"); + }); +} + +fn power_cycle_routine(node_id: NodeId, on: bool) { + RUNTIME.block_on(async move { + let lock = APP.get().unwrap().lock(); + lock.await.deref().power_node(node_id, on).await.unwrap(); + }); +} +/// Turns a given node on or off. +/// +/// # Arguments +/// +/// 'node_id' specify which node will be effected +/// 'on' when on==true, power on, on==false : power down. +#[no_mangle] +pub extern "C" fn power_cycle_node(node_id: NodeId, on: bool) { + power_cycle_routine(node_id, on); +} + +#[no_mangle] +pub extern "C" fn power_system_on() { + power_cycle_routine(NodeId::All, true); +} + +#[no_mangle] +pub extern "C" fn power_system_off() { + power_cycle_routine(NodeId::All, false); +} + +#[repr(C)] +pub enum NodeFlashProgress { + UnknownError, + // NodeDoesNotExist, + // /// The node is already undergoing a fwupdate. Fw update request is ignored + // Busy, + // /// Flashing is in progress, node does not respond and any subsequent fw + // /// update requests are ignored. + // InProgress, + // /// Cannot successfully progress the fw udate due to unsufficient storage + // /// space on the host. + // StorageFull, + // /// The node does not respond anymore + // Timeout, + // /// verification step after fw update failed. Upload may be corrupted + // ChecksumMismatch, + // /// The fw update completed successfully. + Done, +} + +/// C callback that reports the progress of an running firmware update to one of +/// the connected compute modules. +/// +/// # Arguments +/// +/// * 'status_code' reports the state of the running firmware update. A status +/// code [NodeFlashProgress::Done] is the end of the sequence and signals a +/// successful update +/// +/// * 'progress' reports the progress of the firmware update. Ranges from zero to +/// [u32::Max], where [u32::Max] == 100%. +type FlashProgressFn = extern "C" fn(status_code: NodeFlashProgress, progress: u32); + +#[no_mangle] +pub extern "C" fn flash_node( + nodeId: NodeId, + image_path: *mut std::os::raw::c_char, + progress_cb: FlashProgressFn, +) { + let str = unsafe { CStr::from_ptr(image_path) }.to_str().unwrap(); + let node_image = String::from(str); + + RUNTIME.block_on(async move { + let lock = APP.get().unwrap().lock(); + lock.await + .deref() + .flash_node(nodeId, node_image) + .await + .unwrap(); + }); +} diff --git a/tp2bmc/package/tpi_rs/src/lib.rs b/tp2bmc/package/tpi_rs/src/lib.rs new file mode 100644 index 00000000..169a8ddc --- /dev/null +++ b/tp2bmc/package/tpi_rs/src/lib.rs @@ -0,0 +1,3 @@ +pub mod app; +pub mod c_interface; +mod middleware; diff --git a/tp2bmc/package/tpi_rs/src/middleware/app_persistency.rs b/tp2bmc/package/tpi_rs/src/middleware/app_persistency.rs new file mode 100644 index 00000000..4ac9773c --- /dev/null +++ b/tp2bmc/package/tpi_rs/src/middleware/app_persistency.rs @@ -0,0 +1,172 @@ +use anyhow::bail; +use anyhow::Context; + +use sqlx::Row; +use sqlx::Sqlite; +use sqlx::SqlitePool; +use std::path::PathBuf; + +/// directory on target which the sqlite database is written to. +const DATABASE: &str = concat!("/var/lib/", env!("CARGO_PKG_NAME"), "/bmc.db"); + +/// [ApplicationPersistency] is a simple key-value store that stores application state. Decided is +/// to go for a sqlite implementation. Its stable and there are enough tools available for it. +/// Preferably we would like to have a binary representation that we could sync to disk. At the +/// moment of writing are the current available crates not convincing enough to go down the route +/// of having a propiatary memory layout. The downside is that sqlite's size on flash is more +/// significant. +#[derive(Debug)] +pub struct ApplicationPersistency { + connection: SqlitePool, +} + +impl ApplicationPersistency { + /// Initializes a new instance, It will consruct a new database if it does not exist. Throws an + /// error when the database version is not supported. + pub async fn new() -> anyhow::Result { + let path = PathBuf::from(DATABASE); + let sql_db = format!("sqlite:{}", DATABASE); + + let connection = SqlitePool::connect(&sql_db).await?; + + if !path.exists() { + if let Some(p) = path.parent() { + tokio::fs::create_dir_all(p).await? + } + Self::setup_new(&connection).await?; + } else { + Self::verify_version(&connection).await?; + } + + Ok(Self { connection }) + } + + async fn verify_version(connection: &SqlitePool) -> anyhow::Result<()> { + let result = sqlx::query("PRAGMA user_version") + .fetch_one(connection) + .await?; + + let version: u32 = result.get::(0); + if version != 1 { + bail!("database version {} is not supported {}", version, DATABASE); + } + Ok(()) + } + + async fn setup_new(connection: &SqlitePool) -> std::result::Result<(), sqlx::Error> { + let sql = r" + PRAGMA user_version = 1; + CREATE TABLE IF NOT EXISTS keyvalue (key TEXT PRIMARY KEY, value blob); + "; + + Ok(sqlx::query(sql).execute(connection).await.map(|_| ())?) + } + + /// get value by key + pub async fn get + for<'a> sqlx::Decode<'a, Sqlite>>( + &self, + key: &str, + ) -> anyhow::Result { + let result = sqlx::query("SELECT value FROM keyvalue WHERE key = ?") + .bind(key) + .fetch_one(&self.connection) + .await?; + Ok(result.get::("value")) + } + + /// Set a value given a key. a value can be anything that can be encoded to a sqlite object. + /// i.e. implements the [sqlx::Encode] trait. + pub async fn set(&self, key: &str, value: T) -> anyhow::Result<()> + where + T: Send + sqlx::Type + for<'a> sqlx::Encode<'a, Sqlite>, + { + sqlx::query("INSERT OR REPLACE INTO keyvalue (key, value) VALUES (?,?)") + .bind(key) + .bind(value) + .execute(&self.connection) + .await + .map(|_| ()) + .context("sqlite error") + } + + // /// Set a value represented as a bitfield. + // /// + // /// # Arguments + // /// + // /// * 'bits' value of the key/value pair to write. + // /// * 'mask' indicates which values need to be updated to either 'on' or 'off'. e.g. 0b1001 + // /// means that the value of the the 1st and the 4th bit will be written to the value of the + // /// corresponding bit in the 'bits' argument. + // pub async fn set_with_bitmask(&self, key: &str, bits: u32, mask: u32) -> anyhow::Result { + // let current: u32 = self.get(key).await?; + // let mut result = current; + // for n in 0..size_of::() { + // // continue if bit is not to be written + // if (mask & (1 << n)) == 0 { + // continue; + // } + // + // // check if bit need to written high or low + // let high = (bits & (1 << n)) != 0; + // + // result = if high { + // result | (1 << n) + // } else { + // result & !(1 << n) + // }; + // } + // + // if current != result { + // self.set(key, result).await?; + // } + // Ok(result) + // } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn test_wrong_version_check() { + let connection = SqlitePool::connect("sqlite::memory:").await.unwrap(); + let sql = r" + PRAGMA user_version = 3; + "; + + sqlx::query(sql).execute(&connection).await.unwrap(); + let result = ApplicationPersistency::verify_version(&connection).await; + assert!(result.is_err()); + } + + macro_rules! test_bits { + ($db: ident, $(($bits:literal,$mask:literal,$output:literal)),+ ) => { + $( $db.set_with_bitmask("foo", $bits, $mask).await.unwrap(); + assert_eq!($output, $db.get::("foo").await.unwrap()); + )* + }; + } + + #[tokio::test] + async fn test_power_bits() { + let connection = SqlitePool::connect("sqlite::memory:").await.unwrap(); + ApplicationPersistency::setup_new(&connection) + .await + .unwrap(); + ApplicationPersistency::verify_version(&connection) + .await + .unwrap(); + + let db = ApplicationPersistency { connection }; + db.set("foo", 0).await.unwrap(); + + test_bits!( + db, + (0b1111, 0b0000, 0b0000), + (0b1111, 0b1000, 0b1000), + (0b1111, 0b0000, 0b1000), + (0b0011, 0b1111, 0b0011), + (0b0000, 0b1111, 0b0000) + ); + } +} diff --git a/tp2bmc/package/tpi_rs/src/middleware/evdev_controller.rs b/tp2bmc/package/tpi_rs/src/middleware/evdev_controller.rs new file mode 100644 index 00000000..2a719f38 --- /dev/null +++ b/tp2bmc/package/tpi_rs/src/middleware/evdev_controller.rs @@ -0,0 +1,27 @@ +use evdev::EventStream; +use evdev::{Device, Key}; +use log::error; + +const DEVICE_PATH: &str = "/dev/input/event0"; + +pub fn linux_event_stream() -> std::io::Result { + let device = Device::open(DEVICE_PATH)?; + verify_required_keys(&device); + device.into_event_stream() +} + +fn verify_required_keys(device: &Device) { + let required_keys: [Key; 3] = [Key::KEY_POWER, Key::KEY_1, Key::KEY_RESTART]; + let verified_keys = device.supported_keys().map_or(Vec::new(), |k| { + k.iter() + .filter(|k| required_keys.contains(k)) + .collect::>() + }); + + if required_keys != verified_keys.as_slice() { + error!( + "not all required keys are supported by linux subsystem. need {:?}", + required_keys + ); + } +} diff --git a/tp2bmc/package/tpi_rs/src/middleware/gpio_definitions.rs b/tp2bmc/package/tpi_rs/src/middleware/gpio_definitions.rs new file mode 100644 index 00000000..1fa8b1ff --- /dev/null +++ b/tp2bmc/package/tpi_rs/src/middleware/gpio_definitions.rs @@ -0,0 +1,46 @@ +//! This module contains pin numbers of the connected gpios. A next step would +//! be to configure it in the dst as a new gpiochip +#![allow(dead_code)] +pub const GPIO_PIN_PG: u32 = 192; +pub const GPIO_PIN_PD: u32 = 96; + +pub const RTL_RESET: u32 = GPIO_PIN_PG + 13; +pub const SYS_LED: u32 = GPIO_PIN_PG + 8; +pub const RESET_LED: u32 = GPIO_PIN_PG + 9; +pub const SYS_RESET: u32 = GPIO_PIN_PG + 11; +pub const POWER_DETECT: u32 = GPIO_PIN_PG + 10; +pub const POWER_BOARD: u32 = GPIO_PIN_PG + 15; + +pub const PORT1_EN: u32 = GPIO_PIN_PD + 11; +pub const PORT2_EN: u32 = GPIO_PIN_PD + 10; +pub const PORT3_EN: u32 = GPIO_PIN_PD + 9; +pub const PORT4_EN: u32 = GPIO_PIN_PD + 8; + +pub const MODE1_EN: u32 = GPIO_PIN_PD + 7; +pub const MODE2_EN: u32 = GPIO_PIN_PD + 6; +pub const MODE3_EN: u32 = GPIO_PIN_PD + 5; +pub const MODE4_EN: u32 = GPIO_PIN_PD + 4; +pub const POWER_EN: u32 = GPIO_PIN_PD + 3; + +pub const PORT1_RST: u32 = GPIO_PIN_PD + 0; +pub const PORT2_RST: u32 = GPIO_PIN_PD + 20; +pub const PORT3_RST: u32 = GPIO_PIN_PD + 21; +pub const PORT4_RST: u32 = GPIO_PIN_PD + 22; + +pub const PORT1_USB_VBUS: u32 = GPIO_PIN_PD + 19; +pub const PORT2_USB_VBUS: u32 = GPIO_PIN_PD + 18; +pub const PORT3_USB_VBUS: u32 = GPIO_PIN_PD + 17; +pub const PORT4_USB_VBUS: u32 = GPIO_PIN_PD + 16; + +pub const PORT1_RPIBOOT: u32 = GPIO_PIN_PD + 15; +pub const PORT2_RPIBOOT: u32 = GPIO_PIN_PD + 14; +pub const PORT3_RPIBOOT: u32 = GPIO_PIN_PD + 12; +pub const PORT4_RPIBOOT: u32 = GPIO_PIN_PD + 13; + +pub const USB_SEL1: u32 = GPIO_PIN_PG + 1; +pub const USB_SEL2: u32 = GPIO_PIN_PG + 0; +pub const USB_OE1: u32 = GPIO_PIN_PG + 2; +pub const USB_OE2: u32 = GPIO_PIN_PG + 3; + +pub const USB_SWITCH: u32 = GPIO_PIN_PG + 5; +pub const USB_PWEN: u32 = GPIO_PIN_PG + 4; diff --git a/tp2bmc/package/tpi_rs/src/middleware/mod.rs b/tp2bmc/package/tpi_rs/src/middleware/mod.rs new file mode 100644 index 00000000..2bbf6f06 --- /dev/null +++ b/tp2bmc/package/tpi_rs/src/middleware/mod.rs @@ -0,0 +1,35 @@ +pub mod app_persistency; +pub mod evdev_controller; +mod gpio_definitions; +pub mod pin_controller; +pub mod usbboot; + +#[repr(C)] +#[derive(Debug, Eq, PartialEq, Clone, Copy)] +pub enum NodeId { + Node1, + Node2, + Node3, + Node4, + All, +} + +impl From for NodeId { + fn from(v: u32) -> Self { + match v { + 0 => NodeId::Node1, + 1 => NodeId::Node2, + 2 => NodeId::Node3, + 3 => NodeId::Node4, + x => panic!("node id {} does not exist", x), + } + } +} + +#[repr(C)] +#[derive(Debug, Eq, PartialEq, Clone, Copy)] +pub enum NodeType { + RaspberryPi4, + JetsonTx2, + RK1, +} diff --git a/tp2bmc/package/tpi_rs/src/middleware/pin_controller.rs b/tp2bmc/package/tpi_rs/src/middleware/pin_controller.rs new file mode 100644 index 00000000..68dc49d2 --- /dev/null +++ b/tp2bmc/package/tpi_rs/src/middleware/pin_controller.rs @@ -0,0 +1,163 @@ +use super::gpio_definitions::*; +use super::NodeId; +use gpiod::AsValuesMut; +use gpiod::{Chip, Lines, Masked, Options, Output}; +use std::io::ErrorKind; +use std::time::Duration; +use tokio::time::sleep; + +#[derive(Debug, Eq, PartialEq)] +pub enum UsbMode { + BMC, + UsbA, +} + +/// This middleware is responsible for managing the switching of nodes on the +/// board, including power regulators and USB multiplexers. Due to hardware +/// limitations, only one node can be connected over the USB bus at a time. This +/// structure the GPIOD device library internally. +pub struct PinController { + usb_mux: Lines, + rpi_boot: Lines, + mode: Lines, + enable: Lines, + reset: Lines, +} + +/// small helper macro which handles the code duplication of declaring lines. +macro_rules! create_output_lines { + ($chip:ident, $(($name:ident, $pins: expr, $description: literal)),+) => { + $(let $name = $chip + .request_lines(Options::output($pins).consumer($description)) + ?; + )* + }; +} + +impl PinController { + /// create a new Pin controller + pub async fn new() -> std::io::Result { + let chip = Chip::new("gpiochip0")?; + create_output_lines!( + chip, + ( + usb_mux, + [USB_SEL1, USB_OE1, USB_SEL2, USB_OE2], + "usb channel switcher" + ), + ( + rpi_boot, + [PORT1_RPIBOOT, PORT2_RPIBOOT, PORT3_RPIBOOT, PORT4_RPIBOOT], + "rpi boot" + ), + ( + mode, + [MODE1_EN, MODE2_EN, MODE3_EN, MODE4_EN, POWER_EN], + "5v power enable" + ), + ( + enable, + [PORT1_EN, PORT2_EN, PORT3_EN, PORT4_EN], + "power on/off signal" + ), + ( + reset, + [PORT1_RST, PORT2_RST, PORT3_RST, PORT4_RST], + "reset group" + ) + ); + + Ok(Self { + usb_mux, + rpi_boot, + mode, + enable, + reset, + }) + } + + pub async fn atx_power(&self, on: bool) -> std::io::Result<()> { + self.mode + .get_values(Masked::::default().with(4, Some(on)))?; + sleep(Duration::from_secs(1)).await; + Ok(()) + } + + /// changes the configuration in such a way that + pub async fn switch_usb(&self, node: NodeId, connect_to: UsbMode) -> std::io::Result<()> { + let values: u8 = match node { + NodeId::Node1 => 0b0011, + NodeId::Node2 => 0b1011, + NodeId::Node3 => 0b1100, + NodeId::Node4 => 0b1110, + NodeId::All => return Err(std::io::Error::from(ErrorKind::Unsupported)), + }; + + if connect_to == UsbMode::BMC { + } else { + } + + self.usb_mux.set_values(values) + } + + /// Set given node into usb boot mode. When powering the node on with this usb_boot mode + /// enabled, the given node will boot into USB mode. Typically means that booting of eMMC is + /// disabled. + pub async fn usb_boot(&self, node: NodeId, on: bool) -> std::io::Result<()> { + let mut bits = as_bits(node); + if !on { + bits = !bits; + } + + let mask = Masked { + bits, + mask: as_bits(node), + }; + self.rpi_boot.set_values(mask) + } + + pub async fn power_node(&self, bits: u8, mask: u8) -> std::io::Result<()> { + for n in 0..4 { + let output_mask = mask & (1 << n); + // continue if bit is not to be written + if output_mask == 0 { + continue; + } + + let masked = Masked { + bits, + mask: output_mask, + }; + self.mode.set_values(masked)?; + sleep(Duration::from_millis(100)).await; + self.enable.set_values(masked)?; + sleep(Duration::from_secs(1)).await; + } + Ok(()) + } + + pub async fn reset(&self, node: NodeId) -> std::io::Result<()> { + let mut mask = Masked { + bits: as_bits(node), + mask: as_bits(node), + }; + self.reset.set_values(mask)?; + sleep(Duration::from_secs(1)).await; + mask.bits = !mask.bits; + self.reset.set_values(mask) + } +} + +fn as_bits(node: NodeId) -> u8 { + if node == NodeId::All { + 15 + } else { + 1 << node as u8 + } +} + +impl std::fmt::Debug for PinController { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "PinController") + } +} diff --git a/tp2bmc/package/tpi_rs/src/middleware/usbboot.rs b/tp2bmc/package/tpi_rs/src/middleware/usbboot.rs new file mode 100644 index 00000000..e69de29b diff --git a/tp2bmc/package/tpi_rs/tpi_rs.h b/tp2bmc/package/tpi_rs/tpi_rs.h new file mode 100644 index 00000000..9c2cb8c2 --- /dev/null +++ b/tp2bmc/package/tpi_rs/tpi_rs.h @@ -0,0 +1,28 @@ +// this header file corresponds to the c_interface module. Refer to +// c_interface.rs for more detailed function description. +#pragma once +#include + +typedef enum { + Node1, + Node2, + Node3, + Node4, + All, +} node_id_t; + +void power_cycle_node(node_id_t node_id, bool on); + +typedef enum { + UnknownError, + NodeDoesNotExist, + Busy, + InProgress, + StorageFull, + Timeout, + ChecksumMismatch, + Done, +} node_flash_progress_t; + +void flash_node(node_id_t node_id, void(*on_progress)(node_flash_progress_t, uint32_t)); + diff --git a/tp2bmc/package/tpi_rs/tpi_rs.mk b/tp2bmc/package/tpi_rs/tpi_rs.mk new file mode 100644 index 00000000..47512247 --- /dev/null +++ b/tp2bmc/package/tpi_rs/tpi_rs.mk @@ -0,0 +1,35 @@ +########################################################### +# +# tpi_rs +# +########################################################### + +TPI_RS_VERSION = 0.0.0 +TPI_RS_SITE = $(TOPDIR)/../tp2bmc/package/tpi_rs +TPI_RS_SITE_METHOD = local +TPI_RS_INSTALL_STAGING = YES +TPI_RS_INSTALL_TARGET = NO + +# This build step is derived from the default build cmd. Removed the +# HOST_CONFIGURE_OPTS and $HOST_PKG_CARGO_ENV environment as some of the +# compiler flags where causing cross compilation to fail. Secondly, Removed the +# --offline requirement, having this package referenced locally causes some +# issues downloading all cargo dependencies as well +define TPI_RS_BUILD_CMDS + cd $(TPI_RS_SRCDIR) && \ + $(TARGET_MAKE_ENV) \ + $$(PKG_CARGO_ENV) \ + cargo build \ + $(if $(BR2_ENABLE_DEBUG),,--release) \ + --manifest-path Cargo.toml \ + --target $(RUSTC_TARGET_NAME) + --locked +endef + +define TPI_RS_INSTALL_STAGING_CMDS + $(INSTALL) -D -m 0644 $(@D)/target/$(RUSTC_TARGET_NAME)/release/libtpi_rs.a $(STAGING_DIR)/lib + $(INSTALL) -D -m 0644 $(@D)/tpi_rs.h $(STAGING_DIR)/usr/include +endef + + +$(eval $(cargo-package))