From 6a44a7f08d6ae3866d49853388b923cb3eeeb784 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 21 May 2021 19:05:04 +0800 Subject: [PATCH 1/6] Update flash.md --- docs/flash.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/flash.md b/docs/flash.md index c3e1f863f..1afa4ad54 100644 --- a/docs/flash.md +++ b/docs/flash.md @@ -64,6 +64,34 @@ of wear leveling, however. +-----------+----------------------------------------+ ``` +The EC update block is further structured as follows: +``` ++-----------+----------------------------------------+ ++ 27F8_0000 | wf200 firmware control page | ++ +1000 | | ++-----------+----------------------------------------+ ++ 27F8_1000 | up to 311k for wf200 firmware | ++ +4_D000 | padded with trailing 0xFF | ++-----------+----------------------------------------+ ++ 27FC_E000 | EC firmware control page | ++ +1000 | | ++-----------+----------------------------------------+ ++ 27FC_F000 | up to 199k EC fw | ++ +3_1000 | padded with trailing 0xFF | ++-----------+----------------------------------------+ + +``` + +The firmware control pages have the following structure: +``` +base + 0x0000: [u8; 32] = SHA-512/256 hash from base+0x20 to last byte of firmware +base + 0x0020: u32 = length of firmware in bytes, computed from start of first firmware page +base + 0x0024: [u8; 988] = [0xff as u8; 988] 0xff padding to start of first firmware page +base + 0x1000: [u8; FW_LEN] = actual firmware + +remainder of unused sectors are 0xff pad. +``` + The csr.csv block is further structured as follows: From 809ad764aaa6bacd626616da65afd6e08ab0ff80 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 21 May 2021 19:10:06 +0800 Subject: [PATCH 2/6] Update flash.md --- docs/flash.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/flash.md b/docs/flash.md index 1afa4ad54..e6dca0049 100644 --- a/docs/flash.md +++ b/docs/flash.md @@ -84,9 +84,11 @@ The EC update block is further structured as follows: The firmware control pages have the following structure: ``` -base + 0x0000: [u8; 32] = SHA-512/256 hash from base+0x20 to last byte of firmware -base + 0x0020: u32 = length of firmware in bytes, computed from start of first firmware page -base + 0x0024: [u8; 988] = [0xff as u8; 988] 0xff padding to start of first firmware page +base + 0x0000: [u8; 32] = SHA-512/256 hash from base+0x20 to last byte of firmware +base + 0x0020: [u8; 4] = [0x70, 0x72, 0x65, 0x63]; // signature 'prec' +base + 0x0024: u32 = firmware control page version number (currently 1) +base + 0x0028: u32 = length of firmware in bytes, computed from start of first firmware page +base + 0x002c: [u8; 4052] = [0xff as u8; 4052] 0xff padding to start of first firmware page base + 0x1000: [u8; FW_LEN] = actual firmware remainder of unused sectors are 0xff pad. From c05da31ea5750b2b8ba3b5daa0339ffdc30510e4 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 21 May 2021 19:12:02 +0800 Subject: [PATCH 3/6] Update flash.md --- docs/flash.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/flash.md b/docs/flash.md index e6dca0049..ab23fb879 100644 --- a/docs/flash.md +++ b/docs/flash.md @@ -91,7 +91,8 @@ base + 0x0028: u32 = length of firmware in bytes, computed from start of base + 0x002c: [u8; 4052] = [0xff as u8; 4052] 0xff padding to start of first firmware page base + 0x1000: [u8; FW_LEN] = actual firmware -remainder of unused sectors are 0xff pad. +remainder of unused sectors are 0xff pad. The 0xff pad is not hashed for performance reasons, and should +be considered insecure/untrusted. ``` From e277acb59c63eddab6a86007965e4f335d4c277f Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 22 May 2021 00:15:54 +0800 Subject: [PATCH 4/6] Update flash.md --- docs/flash.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/flash.md b/docs/flash.md index ab23fb879..59b4a6e66 100644 --- a/docs/flash.md +++ b/docs/flash.md @@ -85,7 +85,7 @@ The EC update block is further structured as follows: The firmware control pages have the following structure: ``` base + 0x0000: [u8; 32] = SHA-512/256 hash from base+0x20 to last byte of firmware -base + 0x0020: [u8; 4] = [0x70, 0x72, 0x65, 0x63]; // signature 'prec' +base + 0x0020: [u8; 4] = [0x70, 0x72, 0x65, 0x63]; // signature 'cerp' ('prec' in big endian) base + 0x0024: u32 = firmware control page version number (currently 1) base + 0x0028: u32 = length of firmware in bytes, computed from start of first firmware page base + 0x002c: [u8; 4052] = [0xff as u8; 4052] 0xff padding to start of first firmware page From a68330b06e9ef365d2060fa50f906fb93e66e115 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 22 May 2021 02:02:01 +0800 Subject: [PATCH 5/6] Update flash.md --- docs/flash.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/flash.md b/docs/flash.md index 59b4a6e66..710f0d4fa 100644 --- a/docs/flash.md +++ b/docs/flash.md @@ -85,7 +85,7 @@ The EC update block is further structured as follows: The firmware control pages have the following structure: ``` base + 0x0000: [u8; 32] = SHA-512/256 hash from base+0x20 to last byte of firmware -base + 0x0020: [u8; 4] = [0x70, 0x72, 0x65, 0x63]; // signature 'cerp' ('prec' in big endian) +base + 0x0020: [u8; 4] = EC: [0x70, 0x72, 0x65, 0x63]; // signature 'cerp' ('prec' in big endian) or WF200: [0x77, 0x66, 0x32, 0x30]; // 'wf20' base + 0x0024: u32 = firmware control page version number (currently 1) base + 0x0028: u32 = length of firmware in bytes, computed from start of first firmware page base + 0x002c: [u8; 4052] = [0xff as u8; 4052] 0xff padding to start of first firmware page From d5318ba643162e9f26a683c6f715fe21e0054152 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 30 May 2021 19:56:57 +0800 Subject: [PATCH 6/6] Update memory.md --- docs/memory.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/memory.md b/docs/memory.md index 9b9a5c5ca..9e43fbf93 100644 --- a/docs/memory.md +++ b/docs/memory.md @@ -44,6 +44,7 @@ the need from ever switching back to process 1. Note that the kernel takes up a single 4 MB megapage, so it can be assigned to every process simply by mapping megapage 1023 (`0xffc00000`). +``` | Address | Description | ---------- | ----------- | 0x00100000 | Default entrypoint for riscv64-unknown-elf-ld (as shown by `riscv64-unknown-elf-ld --verbose`) @@ -54,12 +55,14 @@ assigned to every process simply by mapping megapage 1023 (`0xffc00000`). | 0xff801000 | Context data (registers, etc.) | 0xff802000 | Return address from syscalls (never allocated) | 0xffc00000 | Kernel arguments, allocation tables +| 0xffcd0000 | Kernel WFI CSR page | 0xffce0000 | Kernel TRNG CSR page | 0xffcf0000 | Supervisor UART CSR page | 0xffd00000 | Kernel binary image and data section | 0xfffefffc | "default" stack pointer (used by interrupt handlers) | 0xffff0000 | Kernel stack top | 0xfff00000 | {unused} +``` Note that the stack pointer is not necessarily fixed, and may be changed in a later revision.