diff --git a/loader/Cargo.lock b/loader/Cargo.lock index 223d5ba7a..bdb8bbe9f 100644 --- a/loader/Cargo.lock +++ b/loader/Cargo.lock @@ -33,10 +33,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] -name = "cfg-if" -version = "0.1.10" +name = "block-buffer" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" @@ -60,14 +75,65 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] -name = "getrandom" -version = "0.1.14" +name = "cpufeatures" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" dependencies = [ - "cfg-if", "libc", - "wasi", +] + +[[package]] +name = "curve25519-dalek" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "639891fde0dbea823fc3d798a0fdf9d2f9440a42d64a78ab3488b0ca025117b3" +dependencies = [ + "byteorder", + "digest", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "ed25519" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d0860415b12243916284c67a9be413e044ee6668247b99ba26d94b2bc06c8f6" +dependencies = [ + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek", + "ed25519", + "sha2", + "zeroize", +] + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", ] [[package]] @@ -87,16 +153,17 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.74" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "loader" version = "0.1.0" dependencies = [ + "curve25519-dalek", + "ed25519-dalek", "lazy_static", - "rand", "utralib", ] @@ -107,10 +174,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" [[package]] -name = "ppv-lite86" -version = "0.2.8" +name = "opaque-debug" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "proc-macro2" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +dependencies = [ + "unicode-xid", +] [[package]] name = "quick-xml" @@ -122,26 +198,12 @@ dependencies = [ ] [[package]] -name = "rand" -version = "0.7.3" +name = "quote" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ - "getrandom", - "libc", - "rand_chacha", - "rand_core", - "rand_hc", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core", + "proc-macro2", ] [[package]] @@ -149,18 +211,25 @@ name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + +[[package]] +name = "sha2" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" dependencies = [ - "getrandom", + "block-buffer", + "cfg-if", + "cpufeatures", + "digest", + "opaque-debug", ] [[package]] -name = "rand_hc" -version = "0.2.0" +name = "signature" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core", -] +checksum = "c19772be3c4dd2ceaacf03cb41d5885f2a02c4d8804884918e3a258480803335" [[package]] name = "strsim" @@ -168,6 +237,12 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "subtle" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" + [[package]] name = "svd2utra" version = "0.1.0" @@ -178,6 +253,29 @@ dependencies = [ "quick-xml", ] +[[package]] +name = "syn" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "synstructure" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-xid", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -187,12 +285,24 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "typenum" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" + [[package]] name = "unicode-width" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + [[package]] name = "utralib" version = "0.1.0" @@ -207,10 +317,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" +name = "version_check" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" [[package]] name = "winapi" @@ -233,3 +343,24 @@ 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 = "zeroize" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c1e130bebaeab2f23886bf9acbaca14b092408c452543c857f66399cd6dab1" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] diff --git a/loader/Cargo.toml b/loader/Cargo.toml index e00c26420..2e8d2ff6a 100644 --- a/loader/Cargo.toml +++ b/loader/Cargo.toml @@ -8,15 +8,25 @@ description = "Initial kernel loader for Xous" [dependencies] utralib = {path = "../utralib"} +[dependencies.curve25519-dalek] +version = "3.1.0" +default-features = false +features = ["u32_backend"] + +[dependencies.ed25519-dalek] +version="1.0.1" +default-features = false +features = ["u32_backend"] + [dev-dependencies] lazy_static = "1.4.0" -rand = "0.7.3" +#rand = "0.7.3" [features] debug-print = [] earlyprintk = [] -#default = ["debug-print"] -default = [] +default = ["debug-print"] +#default = [] [profile.release] codegen-units = 1 # 1 better optimizations diff --git a/loader/bin/riscv32i-unknown-none-elf.a b/loader/bin/riscv32i-unknown-none-elf.a old mode 100644 new mode 100755 index 2a092a4b0..ec3693020 Binary files a/loader/bin/riscv32i-unknown-none-elf.a and b/loader/bin/riscv32i-unknown-none-elf.a differ diff --git a/loader/bin/riscv32imac-unknown-none-elf.a b/loader/bin/riscv32imac-unknown-none-elf.a old mode 100644 new mode 100755 index a307283d9..4e25c296a Binary files a/loader/bin/riscv32imac-unknown-none-elf.a and b/loader/bin/riscv32imac-unknown-none-elf.a differ diff --git a/loader/bin/riscv32imc-unknown-none-elf.a b/loader/bin/riscv32imc-unknown-none-elf.a old mode 100644 new mode 100755 index a307283d9..4e25c296a Binary files a/loader/bin/riscv32imc-unknown-none-elf.a and b/loader/bin/riscv32imc-unknown-none-elf.a differ diff --git a/loader/bin/riscv64gc-unknown-none-elf.a b/loader/bin/riscv64gc-unknown-none-elf.a old mode 100644 new mode 100755 index 72c00d117..b7e586264 Binary files a/loader/bin/riscv64gc-unknown-none-elf.a and b/loader/bin/riscv64gc-unknown-none-elf.a differ diff --git a/loader/bin/riscv64imac-unknown-none-elf.a b/loader/bin/riscv64imac-unknown-none-elf.a old mode 100644 new mode 100755 index 72c00d117..b7e586264 Binary files a/loader/bin/riscv64imac-unknown-none-elf.a and b/loader/bin/riscv64imac-unknown-none-elf.a differ diff --git a/loader/link.x b/loader/link.x index f57e21ef4..ac1f4fd36 100644 --- a/loader/link.x +++ b/loader/link.x @@ -1,7 +1,7 @@ MEMORY { RAM : ORIGIN = 0x40000000, LENGTH = 16M - FLASH : ORIGIN = 0x20500000, LENGTH = 4608k + FLASH : ORIGIN = 0x20501000, LENGTH = 4604k MEMLCD: ORIGIN = 0xB0000000, LENGTH = 32k } /* diff --git a/loader/src/asm.S b/loader/src/asm.S index e164ceaaf..748503f44 100644 --- a/loader/src/asm.S +++ b/loader/src/asm.S @@ -7,8 +7,8 @@ _start: csrw medeleg, t0 // Place the stack pointer at the end of RAM - lw t0, 16(a0) // SRAM start - lw t1, 20(a0) // SRAM length + li t0, 0x40000000 // SRAM start hard-coded into loader -- don't trust kernel boot args to tell us where RAM is, we haven't validated them yet! + li t1, 0x01000000 // SRAM length add sp, t0, t1 // Install a machine mode trap handler diff --git a/loader/src/main.rs b/loader/src/main.rs index d853566a3..3778eeeca 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -43,6 +43,8 @@ mod debug; mod fonts; +use ed25519_dalek::*; + // Install a panic handler when not running tests. #[cfg(not(test))] mod panic_handler { @@ -1245,7 +1247,7 @@ fn boot_sequence(args: KernelArguments, _signature: u32) -> ! { // so that attempts to mess with the args during a resume can't lead to overwriting // critical parameters like these kernel arguments. unsafe { - let backup_args: *mut [u32; 7] = 0x40FF_F000 as *mut[u32; 7]; + let backup_args: *mut [u32; 7] = 0x40FF_E000 as *mut[u32; 7]; (*backup_args)[0] = arg_offset as u32; (*backup_args)[1] = ip_offset as u32; (*backup_args)[2] = rpt_offset as u32; @@ -1275,7 +1277,7 @@ fn boot_sequence(args: KernelArguments, _signature: u32) -> ! { } } else { unsafe { - let backup_args: *mut [u32; 7] = 0x40FF_F000 as *mut[u32; 7]; + let backup_args: *mut [u32; 7] = 0x40FF_E000 as *mut[u32; 7]; #[cfg(feature="debug-print")] { println!("Using backed up kernel args:"); @@ -1313,7 +1315,7 @@ fn check_resume(cfg: &mut BootConfig) -> (bool, bool, u32) { const NUM_SECTORS: usize = 8; const WORDS_PER_PAGE: usize = PAGE_SIZE / 4; - let suspend_marker = cfg.sram_start as usize + cfg.sram_size - PAGE_SIZE * 2; + let suspend_marker = cfg.sram_start as usize + cfg.sram_size - PAGE_SIZE * 3; let marker: *mut[u32; WORDS_PER_PAGE] = suspend_marker as *mut[u32; WORDS_PER_PAGE]; let boot_seed = CSR::new(utra::seed::HW_SEED_BASE as *mut u32); @@ -1395,13 +1397,14 @@ fn phase_1(cfg: &mut BootConfig) { // Mark all pages as in-use by the kernel. // NOTE: This causes the .text section to be owned by the kernel! This // will require us to transfer ownership in `stage3`. - // Note also that we skip the first index, causing the stack to be + // Note also that we skip the first four indices, causing the stack to be // returned to the process pool. - // We also skip the second index as that is the clean suspend page. This + + // We also skip the an additional index as that is the clean suspend page. This // needs to be claimed by the susres server before the kernel allocates it. // Lower numbered indices corresponding to higher address pages. println!("Marking pages as in-use"); - for i in 3..(cfg.init_size / PAGE_SIZE) { + for i in 4..(cfg.init_size / PAGE_SIZE) { cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - i] = 1; } } @@ -1481,5 +1484,6 @@ pub fn phase_2(cfg: &mut BootConfig) { ); // mark pages used by suspend/resume according to their needs cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - 1] = 1; // claim the loader stack -- do not allow tampering, as it contains backup kernel args - cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - 2] = 0; // allow clean suspend page to be mapped in Xous + cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - 2] = 1; // 8k in total (to allow for digital signatures to be computed) + cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - 3] = 0; // allow clean suspend page to be mapped in Xous } diff --git a/precursors/soc.svd b/precursors/soc.svd index 206f703ee..a7bcce264 100755 --- a/precursors/soc.svd +++ b/precursors/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -38,7 +38,7 @@ peripherals]]> ADDR 0x0004 - 0x00 + 0x80000000 32 @@ -1222,10 +1222,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0xafcc1323 + 0x68fd49d7 32 @@ -1242,7 +1242,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x2a + 0x31 32 @@ -3467,7 +3467,7 @@ inject too fast.]]> SEED1 0x0000 - 0x3cbf0070 + 0x8004bf8 32 @@ -3482,7 +3482,7 @@ inject too fast.]]> SEED0 0x0004 - 0x57a58b0 + 0x56fa5c4d 32 @@ -4698,31 +4698,9 @@ generators]]> - - RO_RUNSLIMIT5 - 0x004c - 0x1c807 - 32 - - - min - 10 - [10:0] - 0 - - - - max - 21 - [21:11] - 11 - - - - RO_RUN0_CTRL - 0x0050 + 0x004c 0x3ff 32 @@ -4740,14 +4718,14 @@ undefined behavior occurs]]> RO_RUN0_FRESH - 0x0054 + 0x0050 0x00 32 ro_run0_fresh - 4 - [4:0] + 3 + [3:0] 0 @@ -4755,7 +4733,7 @@ updated at least once since the last readout of any register]]> RO_RUN0_COUNT1 - 0x0058 + 0x0054 0x00 32 @@ -4770,7 +4748,7 @@ updated at least once since the last readout of any register]]> RO_RUN0_COUNT2 - 0x005c + 0x0058 0x00 32 @@ -4785,7 +4763,7 @@ updated at least once since the last readout of any register]]> RO_RUN0_COUNT3 - 0x0060 + 0x005c 0x00 32 @@ -4800,7 +4778,7 @@ updated at least once since the last readout of any register]]> RO_RUN0_COUNT4 - 0x0064 + 0x0060 0x00 32 @@ -4812,24 +4790,9 @@ updated at least once since the last readout of any register]]> - - RO_RUN0_COUNT5 - - 0x0068 - 0x00 - 32 - - - ro_run0_count5 - 10 - [10:0] - 0 - - - RO_RUN1_CTRL - 0x006c + 0x0064 0x3ff 32 @@ -4847,14 +4810,14 @@ undefined behavior occurs]]> RO_RUN1_FRESH - 0x0070 + 0x0068 0x00 32 ro_run1_fresh - 4 - [4:0] + 3 + [3:0] 0 @@ -4862,7 +4825,7 @@ updated at least once since the last readout of any register]]> RO_RUN1_COUNT1 - 0x0074 + 0x006c 0x00 32 @@ -4877,7 +4840,7 @@ updated at least once since the last readout of any register]]> RO_RUN1_COUNT2 - 0x0078 + 0x0070 0x00 32 @@ -4892,7 +4855,7 @@ updated at least once since the last readout of any register]]> RO_RUN1_COUNT3 - 0x007c + 0x0074 0x00 32 @@ -4907,7 +4870,7 @@ updated at least once since the last readout of any register]]> RO_RUN1_COUNT4 - 0x0080 + 0x0078 0x00 32 @@ -4919,24 +4882,9 @@ updated at least once since the last readout of any register]]> - - RO_RUN1_COUNT5 - - 0x0084 - 0x00 - 32 - - - ro_run1_count5 - 10 - [10:0] - 0 - - - RO_RUN2_CTRL - 0x0088 + 0x007c 0x3ff 32 @@ -4954,14 +4902,14 @@ undefined behavior occurs]]> RO_RUN2_FRESH - 0x008c + 0x0080 0x00 32 ro_run2_fresh - 4 - [4:0] + 3 + [3:0] 0 @@ -4969,7 +4917,7 @@ updated at least once since the last readout of any register]]> RO_RUN2_COUNT1 - 0x0090 + 0x0084 0x00 32 @@ -4984,7 +4932,7 @@ updated at least once since the last readout of any register]]> RO_RUN2_COUNT2 - 0x0094 + 0x0088 0x00 32 @@ -4999,7 +4947,7 @@ updated at least once since the last readout of any register]]> RO_RUN2_COUNT3 - 0x0098 + 0x008c 0x00 32 @@ -5014,7 +4962,7 @@ updated at least once since the last readout of any register]]> RO_RUN2_COUNT4 - 0x009c + 0x0090 0x00 32 @@ -5026,24 +4974,9 @@ updated at least once since the last readout of any register]]> - - RO_RUN2_COUNT5 - - 0x00a0 - 0x00 - 32 - - - ro_run2_count5 - 10 - [10:0] - 0 - - - RO_RUN3_CTRL - 0x00a4 + 0x0094 0x3ff 32 @@ -5061,14 +4994,14 @@ undefined behavior occurs]]> RO_RUN3_FRESH - 0x00a8 + 0x0098 0x00 32 ro_run3_fresh - 4 - [4:0] + 3 + [3:0] 0 @@ -5076,7 +5009,7 @@ updated at least once since the last readout of any register]]> RO_RUN3_COUNT1 - 0x00ac + 0x009c 0x00 32 @@ -5091,7 +5024,7 @@ updated at least once since the last readout of any register]]> RO_RUN3_COUNT2 - 0x00b0 + 0x00a0 0x00 32 @@ -5106,7 +5039,7 @@ updated at least once since the last readout of any register]]> RO_RUN3_COUNT3 - 0x00b4 + 0x00a4 0x00 32 @@ -5121,7 +5054,7 @@ updated at least once since the last readout of any register]]> RO_RUN3_COUNT4 - 0x00b8 + 0x00a8 0x00 32 @@ -5133,24 +5066,9 @@ updated at least once since the last readout of any register]]> - - RO_RUN3_COUNT5 - - 0x00bc - 0x00 - 32 - - - ro_run3_count5 - 10 - [10:0] - 0 - - - AV_EXCURSION0_CTRL - 0x00c0 + 0x00ac 0x190140 32 @@ -5179,7 +5097,7 @@ updated at least once since the last readout of any register]]> AV_EXCURSION0_STAT - 0x00c4 + 0x00b0 0x00 32 @@ -5201,7 +5119,7 @@ updated at least once since the last readout of any register]]> AV_EXCURSION0_LAST_ERR - 0x00c8 + 0x00b4 0x00 32 @@ -5223,7 +5141,7 @@ updated at least once since the last readout of any register]]> AV_EXCURSION1_CTRL - 0x00cc + 0x00b8 0x190140 32 @@ -5252,7 +5170,7 @@ updated at least once since the last readout of any register]]> AV_EXCURSION1_STAT - 0x00d0 + 0x00bc 0x00 32 @@ -5274,7 +5192,7 @@ updated at least once since the last readout of any register]]> AV_EXCURSION1_LAST_ERR - 0x00d4 + 0x00c0 0x00 32 @@ -5296,7 +5214,7 @@ updated at least once since the last readout of any register]]> READY - 0x00d8 + 0x00c4 0x00 32 @@ -5326,7 +5244,7 @@ updated at least once since the last readout of any register]]> EV_STATUS - 0x00dc + 0x00c8 0x00 32 @@ -5370,7 +5288,7 @@ updated at least once since the last readout of any register]]> EV_PENDING - 0x00e0 + 0x00cc 0x00 32 @@ -5414,7 +5332,7 @@ updated at least once since the last readout of any register]]> EV_ENABLE - 0x00e4 + 0x00d0 0x00 32 @@ -5457,7 +5375,7 @@ updated at least once since the last readout of any register]]> CHACHA - 0x00e8 + 0x00d4 0x100c8002 32 @@ -5490,7 +5408,7 @@ standby power)]]> - 0x00ec + 0x00d8 0x00 32 @@ -5506,7 +5424,7 @@ write.]]> URANDOM - 0x00f0 + 0x00dc 0x00 32 @@ -5521,7 +5439,7 @@ want to use this.]]> URANDOM_VALID - 0x00f4 + 0x00e0 0x00 32 @@ -5535,7 +5453,7 @@ want to use this.]]> TEST - 0x00f8 + 0x00e4 0x00 32 @@ -5552,7 +5470,7 @@ case in testing. Not harmful in production, just wasteful.]]> 0 - 0xfc + 0xe8 registers @@ -6997,13 +6915,8 @@ of the PLL]]> ROM - 0x00000000 - 0x0000000C - - - SRAM - 0x10000000 - 0x00004000 + 0x80000000 + 0x00010000 VEXRISCV_DEBUG @@ -7049,7 +6962,7 @@ of the PLL]]> - + diff --git a/precursors/soc_csr.bin b/precursors/soc_csr.bin index 184a7d083..503b8a3cf 100755 Binary files a/precursors/soc_csr.bin and b/precursors/soc_csr.bin differ diff --git a/services/shellchat/src/cmds/aes.rs b/services/shellchat/src/cmds/aes.rs index 46e5c0921..cd6e69d0f 100644 --- a/services/shellchat/src/cmds/aes.rs +++ b/services/shellchat/src/cmds/aes.rs @@ -135,9 +135,13 @@ software: -151mA @ 100% CPU usage, 158.36us/block enc+dec AES128 (500 iters, 819 hardware: -148mA @ 100% CPU usage, 103.73us/block enc+dec AES256 (500 iters, 8192 len) software: -149mA @ 100% CPU usage, 217.95us/block enc+dec AES256 (500 iters, 8192 len) -with L2 cache on: +with L2 cache on (128k): hardware 92.24us/block enc+dec aes256 (500 iters, 8192 len) software 158.48us/block enc+dec aes256 (500 iters, 8192 len) + +with L2 cache on (64k): +hardware 92.24us/block enc+dec aes256 (500 iters, 8192 len) +software 154.05us/block enc+dec aes256 (500 iters, 8192 len) */ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32); diff --git a/services/shellchat/src/cmds/engine.rs b/services/shellchat/src/cmds/engine.rs index 226044bb3..5d1b4a45a 100644 --- a/services/shellchat/src/cmds/engine.rs +++ b/services/shellchat/src/cmds/engine.rs @@ -159,7 +159,8 @@ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { 26ms/2xop (200 iters -hw) -- affine done in hardware 13.54ms/2xop (200 iters -hw) -- microcode pre-loaded, minimal registers transferred using MontgomeryJob call - 12.2ms/2xop (200 iters -hw) -- with L2 cache on + 12.2ms/2xop (200 iters -hw) -- with L2 cache on (128k) + 12.29ms/2xop (200 iters -hw) -- with L2 cache on (64k) */ Some(BenchOp::StartDh) => { let mut passes = 0; diff --git a/services/shellchat/src/cmds/sha.rs b/services/shellchat/src/cmds/sha.rs index ef0f86138..ac658050d 100644 --- a/services/shellchat/src/cmds/sha.rs +++ b/services/shellchat/src/cmds/sha.rs @@ -35,8 +35,10 @@ TEST_MAX_LEN = 1024 (fixed length) / TEST_ITERS = 1000: hw 7.257ms/hash, sw 11.6 TEST_MAX_LEN = 8192 (random length) / TEST_ITERS = 1000: hw 10.528ms/hash, sw 40.631ms/hash TEST_MAX_LEN = 8192 (fixed length) / TEST_ITERS = 1000: hw 17.035ms/hash, sw 78.633ms/hash -with L2 cache on: +with 128k L2 cache on: TEST_MAX_LEN = 8192 (fixed length) / TEST_ITERS = 1000: hw 13.798ms/hash, sw 29.034ms/hash +with 64k L2 cache on: +TEST_MAX_LEN = 8192 (fixed length) / TEST_ITERS = 1000: hw 13.798ms/hash, sw 30.029ms/hash power consumption - 4.1V system voltage diff --git a/services/susres/src/main.rs b/services/susres/src/main.rs index 3334a3767..a09989454 100644 --- a/services/susres/src/main.rs +++ b/services/susres/src/main.rs @@ -141,7 +141,7 @@ mod implementation { // note that mapping a page zeroes it out. Plus, this should have been zero'd by the bootloader. let marker = xous::syscall::map_memory( - xous::MemoryAddress::new(0x40FFE000), // this is a special, hard-coded location + xous::MemoryAddress::new(0x4100_0000 - 0x3000), // this is a special, hard-coded location; 0x2000 is the size of the bootloader's stack area None, 4096, xous::MemoryFlags::R | xous::MemoryFlags::W, diff --git a/tools/sign_image.py b/tools/sign_image.py index 55c9a3a0b..f3124e546 100755 --- a/tools/sign_image.py +++ b/tools/sign_image.py @@ -9,10 +9,13 @@ import os.path import binascii DEVKEY_PATH='../devkey/dev.key' +LOADER_VERSION=1 -def loader_sign(source, output, key): +def loader_sign(source, output, key, defile=False): + global LOADER_VERSION with open(source, "rb") as source_f: source = list(source_f.read()) + source += int(LOADER_VERSION).to_bytes(4, 'little') # protect the version number source += len(source).to_bytes(4, 'little') # append the length to the image, and sign that # NOTE NOTE NOTE @@ -23,11 +26,15 @@ def loader_sign(source, output, key): with open(output, "wb") as output_f: written = 0 - written += output_f.write(int(1).to_bytes(4, 'little')) # version number 1 record + written += output_f.write(int(LOADER_VERSION).to_bytes(4, 'little')) # version number record - mirrored inside the signed data, too written += output_f.write(len(source).to_bytes(4, 'little')) # record the length of the final signed record (which /also/ includes a length) written += output_f.write(signature.signature) output_f.write(bytearray([0] * (4096 - written))) # pad out to one page beyond - output_f.write(signature.message) # the actual signed message + message = bytearray(signature.message) + if defile is True: + print("WARNING: defiling the loader image. This corrupts the binary and should cause it to fail the signature check.") + message[16778] ^= 0x1 # flip one bit at some random offset + output_f.write(message) # the actual signed message def main(): global DEVKEY_PATH @@ -45,17 +52,25 @@ def main(): parser.add_argument( "--kernel-key", required=False, help="kernel signing key", type=str, nargs='?', metavar=('kernel signing key'), const=DEVKEY_PATH ) + parser.add_argument( + "--loader-output", required=False, help="loader output image", type=str, nargs='?', metavar=('loader output image'), const='../target/riscv32imac-unknown-none-elf/release/loader.bin' + ) + parser.add_argument( + "--defile", help="patch the resulting image, to create a test file to catch signature failure", default=False, action="store_true" + ) args = parser.parse_args() + if not len(sys.argv) > 1: + print("No arguments specified, doing nothing. Use --help for more information.") + exit(1) if args.loader_image and (args.loader_key is None): loader_key = DEVKEY_PATH else: loader_key = args.loader_key - - if args.kernel_image and (args.kernel_key is None): - kernel_key = DEVKEY_PATH + if args.loader_image and (args.loader_output is None): + loader_output = '../target/riscv32imac-unknown-none-elf/release/loader.bin' else: - kernel_key = args.kernel_key + loader_output = args.loader_output if loader_key is not None and loader_key is not DEVKEY_PATH: with open(loader_key) as loader_f: @@ -73,6 +88,17 @@ def main(): else: loader_pkey = None + if loader_pkey != None: + loader_sign(args.loader_image, loader_output, loader_pkey, defile=args.defile) + + + + + if args.kernel_image and (args.kernel_key is None): + kernel_key = DEVKEY_PATH + else: + kernel_key = args.kernel_key + if kernel_key is not None and kernel_key is not DEVKEY_PATH: kernel_pass = input("Enter loader key passphrase, enter if none: ") with open(kernel_key) as kernel_f: @@ -90,15 +116,6 @@ def main(): else: kernel_pkey = None - if loader_pkey != None: - output_image = os.path.dirname(os.path.abspath(args.loader_image)) + "{}loader.bin".format(os.path.sep) - loader_sign(args.loader_image, output_image, loader_pkey) - - - if not len(sys.argv) > 1: - print("No arguments specified, doing nothing. Use --help for more information.") - exit(1) - if __name__ == "__main__": main() exit(0) diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 4eb0dcbd6..7c5d06841 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -7,3 +7,5 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +#"ed25519-dalek" = "1" +#"pem" = "0.8" \ No newline at end of file diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 94dfe1b03..e7c1746fb 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -5,6 +5,11 @@ use std::{ path::{Path, PathBuf, MAIN_SEPARATOR}, process::Command, }; +/* +extern crate ed25519_dalek; +extern crate pem; +use ed25519_dalek::{Keypair, Signature, PublicKey, PrivateKey}; +*/ type DynError = Box; @@ -109,6 +114,8 @@ fn try_main() -> Result<(), DynError> { let aestest_pkgs = ["ticktimer-server", "log-server", "aes-test"]; let mut args = env::args(); let task = args.nth(1); + let lkey = args.nth(3); + let kkey = args.nth(4); match task.as_deref() { Some("renode-image") => renode_image(false, &hw_pkgs)?, Some("renode-test") => renode_image(false, &cbtest_pkgs)?, @@ -116,29 +123,32 @@ fn try_main() -> Result<(), DynError> { Some("renode-aes-test") => renode_image(false, &aestest_pkgs)?, Some("renode-image-debug") => renode_image(true, &hw_pkgs)?, Some("run") => run(false, &hw_pkgs)?, - Some("hw-image") => build_hw_image(false, env::args().nth(2), &hw_pkgs, None)?, - Some("benchmark") => build_hw_image(false, env::args().nth(2), &benchmark_pkgs, None)?, - Some("minimal") => build_hw_image(false, env::args().nth(2), &minimal_pkgs, None)?, - Some("cbtest") => build_hw_image(false, env::args().nth(2), &cbtest_pkgs, None)?, + Some("hw-image") => build_hw_image(false, env::args().nth(2), &hw_pkgs, lkey, kkey, None)?, + Some("benchmark") => build_hw_image(false, env::args().nth(2), &benchmark_pkgs, lkey, kkey, None)?, + Some("minimal") => build_hw_image(false, env::args().nth(2), &minimal_pkgs, lkey, kkey, None)?, + Some("cbtest") => build_hw_image(false, env::args().nth(2), &cbtest_pkgs, lkey, kkey, None)?, Some("trng-test") => build_hw_image( false, env::args().nth(2), &hw_pkgs, + lkey, kkey, Some(&["--features", "urandomtest"]), )?, Some("ro-test") => build_hw_image( false, env::args().nth(2), &hw_pkgs, + lkey, kkey, Some(&["--features", "ringosctest"]), )?, Some("av-test") => build_hw_image( false, env::args().nth(2), &hw_pkgs, + lkey, kkey, Some(&["--features", "avalanchetest"]), )?, - Some("sr-test") => build_hw_image(false, env::args().nth(2), &sr_pkgs, None)?, + Some("sr-test") => build_hw_image(false, env::args().nth(2), &sr_pkgs, lkey, kkey, None)?, Some("debug") => run(true, &hw_pkgs)?, Some("burn-kernel") => update_usb(true, false, false)?, Some("burn-loader") => update_usb(false, true, false)?, @@ -156,7 +166,7 @@ renode-test builds a test image for renode renode-image-debug builds a test image for renode in debug mode libstd-test [pkg1] [..] builds a test image that includes the minimum packages, plus those specified on the command line (e.g. built externally) -hw-image [soc.svd] builds an image for real hardware +hw-image [soc.svd] [loader.key] [kernel.key] builds an image for real hardware run runs a release build using a hosted environment debug runs a debug build using a hosted environment benchmark [soc.svd] builds a benchmarking image for real hardware @@ -235,6 +245,8 @@ fn build_hw_image( debug: bool, svd: Option, packages: &[&str], + lkey: Option, + kkey: Option, extra_args: Option<&[&str]>, ) -> Result<(), DynError> { let svd_file = match svd { @@ -250,7 +262,24 @@ fn build_hw_image( // Tools use this environment variable to know when to rebuild the UTRA crate. std::env::set_var("XOUS_SVD_FILE", path.canonicalize().unwrap()); - // std::fs::copy(path, std::path::Path::new("emulation/soc/renode.svd"))?; + // extract key file names; replace with defaults if not specified + let loaderkey_file = if let Some(lkf) = lkey { + lkf + } else { + String::from("../devkey/dev.key") + }; + let kernelkey_file = if let Some(kkf) = kkey { + kkf + } else { + String::from("../devkey/dev.key") + }; + /* + let mut lkf = File::open(loaderkey_file)?; + let mut lk_str = Vec::::new(); + lkf.read_to_end(&mut lk_str); + let lk_pems = pem::parse(lk_str); + println!("lk_pems: {:?}", lk_pems); + */ let kernel = build_kernel(debug)?; let mut init = vec![]; @@ -278,6 +307,8 @@ fn build_hw_image( let mut loader_bin = output_bundle.parent().unwrap().to_owned(); loader_bin.push("loader.bin"); + let mut loader_presign = output_bundle.parent().unwrap().to_owned(); + loader_presign.push("loader_presign.bin"); let status = Command::new(cargo()) .current_dir(project_root()) .args(&[ @@ -288,12 +319,28 @@ fn build_hw_image( "copy-object", "--", loader.as_os_str().to_str().unwrap(), - loader_bin.as_os_str().to_str().unwrap(), + loader_presign.as_os_str().to_str().unwrap(), ]) .status()?; if !status.success() { return Err("cargo build failed".into()); } + // sign_loader(loader_presign, loader_bin, loader_signing_key)?; + let status = Command::new("python3") + .current_dir(project_root().join("tools")) + .args(&[ + "sign_image.py", + "--loader-image", + loader_presign.to_str().unwrap(), + "--loader-key", + loaderkey_file.as_str(), + "--loader-output", + loader_bin.to_str().unwrap(), + ]).status()?; + if !status.success() { + return Err("loader image sign failed".into()) + } + println!("Signed loader at {}", loader_bin.to_str().unwrap()); let mut xous_img_path = output_bundle.parent().unwrap().to_owned(); xous_img_path.push("xous.img"); @@ -313,6 +360,17 @@ fn build_hw_image( Ok(()) } +/* +fn sign_loader(in_path: Pathbuf, out_path: Pathbuf) -> Result<(), DynError> { + let mut in_file = File::open(in_path)?; + let mut out_file = File::open(out_path)?; + + let mut loader = Vec::::new(); + in_file.read_to_end(&mut loader); + + +}*/ + fn renode_image(debug: bool, packages: &[&str]) -> Result<(), DynError> { let path = std::path::Path::new("emulation/soc/renode.svd"); std::env::set_var("XOUS_SVD_FILE", path.canonicalize().unwrap());