From 22433fa25c7968e419a11b34fdb5c26829b643f6 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 4 May 2025 17:03:00 +0800 Subject: [PATCH] reconfigure toml files for pddb target testing OK, i think this gets us to the starting point of shaving down the PDDB crate from the restored baseline --- services/pddb/Cargo.toml | 48 +++++++++++++++++++++++++++++---------- services/pddb/src/main.rs | 39 +++++++++++++++++++++++++++++++ xtask/src/main.rs | 4 +++- 3 files changed, 78 insertions(+), 13 deletions(-) diff --git a/services/pddb/Cargo.toml b/services/pddb/Cargo.toml index 3767a60f9..be8c56886 100644 --- a/services/pddb/Cargo.toml +++ b/services/pddb/Cargo.toml @@ -13,7 +13,7 @@ xous-ipc = "0.10.4" log-server = { package = "xous-api-log", version = "0.1.63" } ticktimer-server = { package = "xous-api-ticktimer", version = "0.9.63" } xous-names = { package = "xous-api-names", version = "0.9.65" } -susres = { package = "xous-api-susres", version = "0.9.63" } +susres = { package = "xous-api-susres", version = "0.9.63", optional = true } log = "0.4.14" num-derive = { version = "0.4.2", default-features = false } num-traits = { version = "0.2.14", default-features = false } @@ -21,10 +21,10 @@ rkyv = { version = "0.8.8", default-features = false, features = [ "std", "alloc", ] } -trng = { path = "../trng" } -spinor = { path = "../spinor" } +trng = { path = "../trng", optional = true } +spinor = { path = "../spinor", optional = true } aes = { path = "../aes" } -root-keys = { path = "../root-keys" } +root-keys = { path = "../root-keys", optional = true } cipher = "0.4.2" bitfield = "0.13.2" aes-gcm-siv = { version = "0.11.1", default-features = false, features = [ @@ -32,9 +32,9 @@ aes-gcm-siv = { version = "0.11.1", default-features = false, features = [ "aes", ] } # aes-gcm-siv = {git="https://github.com/RustCrypto/AEADs.git", branch="master"} -llio = { path = "../llio" } +llio = { path = "../llio", optional = true } subtle = { version = "2.4.1", default-features = false } -tts-frontend = { path = "../tts" } +tts-frontend = { path = "../tts", optional = true } rand_core = "0.6.4" # passwords @@ -48,9 +48,9 @@ zeroize_derive = "1.4.2" blowfish = { version = "0.9.1", features = ["bcrypt"] } # UX (for password entry and notifications) -gam = { path = "../gam" } -locales = { path = "../../locales" } -modals = { path = "../modals" } +gam = { path = "../gam", optional = true } +locales = { path = "../../locales", optional = true } +modals = { path = "../modals", optional = true } utralib = { version = "0.1.25", optional = true, default-features = false } @@ -65,10 +65,34 @@ hex = { version = "0.4.3", default-features = false, features = [ "alloc", ], optional = true } +# Gen-2 dependencies +keystore = { path = "../keystore", optional = true } # contains all key handlers +xous-swapper = { path = "../xous-swapper", optional = true } # contains spinor + [features] -precursor = ["utralib/precursor", "sha2/precursor"] -hosted = ["utralib/hosted", "sha2/hosted"] -renode = ["utralib/renode", "sha2/renode"] +gen1 = [ + "susres", + "trng", + "spinor", + "root-keys", + "llio", + "tts-frontend", + "gam", + "locales", + "modals", +] +gen2 = ["keystore"] +# gen 1 targets +precursor = ["utralib/precursor", "sha2/precursor", "gen1"] +hosted = ["utralib/hosted", "sha2/hosted", "gen1"] +renode = ["utralib/renode", "sha2/renode", "gen1"] + +# gen 2 targets +board-baosec = ["gen2", "xous-swapper/board-baosec"] # USB form factor token +hosted-baosec = ["gen2"] # emulated hardware on x86 platform +board-baosor = ["gen2", "xous-swapper/board-baosor"] # Precursor form factor +# board-dabao is not a valid target as it lacks external SPI flash + # when selected, physical disk addresses are set to 64 bits, otherwise, they are 32 bits. # 32 bit addressing is recommended for Precursor, as its disk is only 128MiB and it has limited RAM for bookkeeping. u64_pa = [] diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index bfbdf8101..4c2376504 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -363,6 +363,45 @@ extern crate bitfield; /// ``` // historical note: 389 hours, 11 mins elapsed since the start of the PDDB coding, and the first attempt at a // hardware test -- as evidenced by the uptime of the hardware validation unit. + +/* + Gen2 porting notes: + + Todo list: + -[ ] Rewrite xous-swapper/swap layer to understand virtual pages mapped to SPI flash (see notes below) + -[ ] Rewrite pddb to use 'keystore' server instead of rootkeys/modals/ux integrations. + + Xous-swapper refactor notes: + + SPINOR shares the same interface as the swap SRAM, and therefore, the Spinor interface + has to live inside xous-swapper. + + Xous also needs to be extended to implement Virtual Addresses that are not backed by + physical addresses, but are on-demand allocated by copying SPINOR contents into pages that + are allocated in SRAM. The general idea is something like this: + - A new flag is added that can be passed to xous::MapMemory(). This flag is the `Swapped` flag, + and it indicates to the kernel that the physical address should be `null` and marked as `swapped` + for the mapping in its initial page table map in the given process. + - A "special" range of virtual addresses needs to be carved out which is where the memory-mapped + FLASH memory would go to. Thus, a process would gain access to FLASH by simply calling MapMemory + with the FLASH memory VA range as the virtual address, `None` as the PA, and the Swapped flag + as one of the args in Memory Arguments + - When the virtual address is referenced, it will page fault; the page fault handler will pass + this to Xous-Swapper in the userspace, which will then add a check for the virtual address. + If the virtual address is in the magic range for SPINOR, the contents are fetched using the + SPINOR interface based on the linear mapping of the lower bits of the address onto the SPINOR + memory space. + - WHnever a write happens inside Xous-Swapper to a location in FLASH, the page table entry for + the mapped FLASH location needs to be marked as invalid and returned to the free pool. This + uses the swap system to keep the read-view of FLASH in sync with hte write-view. This also + means that Xous-Swapper's SPINOR map has to keep a scoreboard of what pages are mapped to + what processes, so that we can search for the mapping and clear it whenever a write comes in. + - Development of this can probably happen separately from the emu-layer version. The basic thing + would be to drill down into the kernel with the kernel and a simple test server that just + tries to map the SPINOR and read some contents out, and perhaps update a sector. This will + exercise the path in isolation and allow us to test this routine as a separate primitive + from the PDDB. +*/ extern crate bitflags; mod api; diff --git a/xtask/src/main.rs b/xtask/src/main.rs index e567caac1..0949e5262 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -607,13 +607,15 @@ fn main() -> Result<(), Box> { // - [planned] pddb server // - [planned] vault application let bao_rram_pkgs = ["xous-ticktimer", "xous-log", "xous-names" /* "usb-cramium" */].to_vec(); /* "usb-cramium" */ - let bao_swap_pkgs = ["cram-hal-service", "bao-console", "bao-video", "modals", "pddb"].to_vec(); /* "bao-video" */ + let bao_swap_pkgs = + ["cram-hal-service", "bao-console", "bao-video", "modals" /* "pddb" */].to_vec(); /* "bao-video" */ if !builder.is_swap_set() { builder.set_swap(0, 8 * 1024 * 1024); } builder.add_loader_feature("swap"); builder.add_kernel_feature("swap"); builder.add_feature("swap"); + builder.add_feature("spinor"); // required for PDDB builds - affects xous-swapper builder.add_loader_feature("debug-print"); // the following feature needs to be uncommented if we also enable