diff --git a/IDE/XilinxSDK/.cproject b/IDE/XilinxSDK/.cproject index 6e6866ec..e047d41f 100644 --- a/IDE/XilinxSDK/.cproject +++ b/IDE/XilinxSDK/.cproject @@ -30,7 +30,8 @@ - + + @@ -68,7 +69,8 @@ - + + @@ -125,7 +127,7 @@ - + @@ -158,9 +160,10 @@ - + - + + @@ -198,7 +201,8 @@ - + + @@ -255,7 +259,7 @@ - + diff --git a/IDE/XilinxSDK/README.md b/IDE/XilinxSDK/README.md index 6d101bc2..8cc880c6 100644 --- a/IDE/XilinxSDK/README.md +++ b/IDE/XilinxSDK/README.md @@ -86,7 +86,7 @@ the_ROM_image: ``` ```sh -bootgen -image boot.bif -arch zynqmp -o BOOT.bin +bootgen -image boot.bif -arch zynqmp -w -o BOOT.bin ****** Xilinx Bootgen v2022.1 **** Build date : Apr 18 2022-16:02:32 @@ -106,6 +106,21 @@ bootgen -image boot.bif -arch zynqmp -o BOOT.bin | QSPI32 | 0 0 1 0 | on, on, off,on | | SD | 1 1 1 0 | off,off,off,on | +## Example boot output + +``` +wolfBoot Secure Boot +Read FlashID Lower: Ret 0, 20 BB 20 +Read FlashID Upper: Ret 0, 20 BB 20 +Versions: Boot 1, Update 0 +Trying Boot partition at 800000 +Boot partition: 800000 (size 226024, version 0x1) +Firmware Valid +Loading 226024 bytes to RAM at 10000000 +DTB boot partition: 7B0000 +Failed parsing DTB to load +Booting at 10000000 +``` ### Adding RSA Authentication @@ -139,6 +154,16 @@ bootgen -image boot.bif -arch zynqmp -o BOOT.bin Note: To generate a report of a boot.bin use the `bootgen_utility`: `bootgen_utility -arch zynqmp -bin boot.bin -out boot.bin.txt` +## Post Quantum + +XMSS + +```sh +./tools/keytools/keygen --xmss -g wolfboot_signing_private_key.der +./tools/keytools/sign --xmss test-app/image.bin wolfboot_signing_private_key.der 1 +``` + + ### References: * [ZAPP1319](https://www.xilinx.com/support/documentation/application_notes/xapp1319-zynq-usp-prog-nvm.pdf): Programming BBRAM and eFUSEs * [UG1283](https://www.xilinx.com/support/documentation/sw_manuals/xilinx2018_2/ug1283-bootgen-user-guide.pdf): Bootgen User Guide diff --git a/config/examples/zynqmp.config b/config/examples/zynqmp.config index 5f43538e..95595b4f 100644 --- a/config/examples/zynqmp.config +++ b/config/examples/zynqmp.config @@ -1,8 +1,26 @@ ARCH?=AARCH64 TARGET?=zynq +# Default to ZCU102 as hardware platform (QSPI sizes) +CFLAGS_EXTRA+=-DZCU102 + +# RSA 4096-bit with SHA3-384 SIGN?=RSA4096 HASH?=SHA3 -DEBUG?=0 +IMAGE_HEADER_SIZE?=1024 + +# XMSS/XMSS^MT is a post-quantum, stateful, hash-based signature scheme. +# Use the helper script `tools/xmss/xmss_siglen.sh` +# to calculate your signature length given an xmss parameter string. +#SIGN?=XMSS +#HASH?=SHA256 +#XMSS_PARAMS='XMSS-SHA2_10_256' +#IMAGE_SIGNATURE_SIZE=2500 +#IMAGE_HEADER_SIZE?=5000 + +DEBUG?=1 +DEBUG_UART=1 +#DEBUG_ZYNQ=1 + VTOR?=1 CORTEX_M0?=0 NO_ASM?=0 @@ -13,7 +31,6 @@ V?=0 SPMATH?=1 RAM_CODE?=0 DUALBANK_SWAP?=0 -IMAGE_HEADER_SIZE?=1024 PKA?=1 WOLFTPM?=0 EXT_FLASH?=1 @@ -38,3 +55,10 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x63E0000 WOLFBOOT_LOAD_DTS_ADDRESS?=0x11800000 WOLFBOOT_DTS_BOOT_ADDRESS?=0x7B0000 WOLFBOOT_DTS_UPDATE_ADDRESS?=0x39B0000 + + +CROSS_COMPILE=aarch64-none-elf- +#CROSS_COMPILE=aarch64-linux-gnu- + +# Speed up reads from flash by using larger blocks +CFLAGS_EXTRA+=-DWOLFBOOT_SHA_BLOCK_SIZE=4096 diff --git a/hal/zynq.c b/hal/zynq.c index 56a23f08..5977a363 100644 --- a/hal/zynq.c +++ b/hal/zynq.c @@ -25,10 +25,7 @@ #if defined(__QNXNTO__) && !defined(NO_QNX) #define USE_QNX #elif defined(USE_BUILTIN_STARTUP) - /* we are using Xilinx SDK to build, so use Xilinx QSPI driver */ - #ifndef USE_XQSPIPSU - #define USE_XQSPIPSU - #endif + /* to use the Xilinx QSPI driver define USE_XQSPIPSU */ #endif #include @@ -183,7 +180,7 @@ #define GQSPI_QSPI_MODE GQSPI_GEN_FIFO_MODE_QSPI #endif #ifndef GQPI_USE_DUAL_PARALLEL -#define GQPI_USE_DUAL_PARALLEL 0 /* default is single QSPI chip. Use 1=stripe */ +#define GQPI_USE_DUAL_PARALLEL 1 /* 0=no stripe, 1=stripe */ #endif #ifndef GQPI_USE_4BYTE_ADDR #define GQPI_USE_4BYTE_ADDR 1 @@ -195,18 +192,25 @@ /* Flash Parameters: - * Micron Serial NOR Flash Memory 64KB Sector Erase MT25QU01GBBB - * Stacked device (two 512Mb die) + * Micron Serial NOR Flash Memory 64KB Sector Erase MT25QU512ABB + * Stacked device (two 512Mb (64MB)) * Dual Parallel so total addressable size is double */ #ifndef FLASH_DEVICE_SIZE -#define FLASH_DEVICE_SIZE 0x10000000 + #ifdef ZCU102 + /* 64*2 (dual parallel) = 128MB */ + #define FLASH_DEVICE_SIZE (2 * 64 * 1024 * 1024) /* MT25QU512ABB */ + #else + /* 128*2 (dual parallel) = 256MB */ + #define FLASH_DEVICE_SIZE (2 * 128 * 1024 * 1024) /* MT25QU01GBBB */ + #endif #endif #ifndef FLASH_PAGE_SIZE -#define FLASH_PAGE_SIZE 512 -#endif -#ifndef FLASH_NUM_PAGES -#define FLASH_NUM_PAGES 0x80000 + #ifdef ZCU102 + #define FLASH_PAGE_SIZE 256 /* MT25QU512ABB */ + #else + #define FLASH_PAGE_SIZE 512 /* MT25QU01GBBB */ + #endif #endif #define FLASH_NUM_SECTORS (FLASH_DEVICE_SIZE/WOLFBOOT_SECTOR_SIZE) @@ -817,17 +821,22 @@ static int qspi_write_enable(QspiDev_t* dev) cmd[0] = WRITE_ENABLE_CMD; ret = qspi_transfer(&mDev, cmd, 1, NULL, 0, NULL, 0, 0, GQSPI_GEN_FIFO_MODE_SPI); +#if defined(DEBUG_ZYNQ) && DEBUG_ZYNQ >= 2 wolfBoot_printf("Write Enable: Ret %d\n", ret); - +#endif ret = qspi_wait_ready(dev); - wolfBoot_printf("wait ready: Ret %d\n", ret); +#if defined(DEBUG_ZYNQ) && DEBUG_ZYNQ >= 2 + wolfBoot_printf("Wait ready: Ret %d\n", ret); +#endif ret = qspi_wait_we(dev); - wolfBoot_printf("wait we: Ret %d\n", ret); +#if defined(DEBUG_ZYNQ) && DEBUG_ZYNQ >= 2 + wolfBoot_printf("Wait we: Ret %d\n", ret); +#endif qspi_status(dev, &status); if ((status & WRITE_EN_MASK) == 0) { - wolfBoot_printf("status %02x\n", status); + wolfBoot_printf("Write enable failed: status %02x\n", status); ret = -1; } @@ -842,7 +851,9 @@ static int qspi_write_disable(QspiDev_t* dev) cmd[0] = WRITE_DISABLE_CMD; ret = qspi_transfer(dev, cmd, 1, NULL, 0, NULL, 0, 0, GQSPI_GEN_FIFO_MODE_SPI); +#if defined(DEBUG_ZYNQ) && DEBUG_ZYNQ >= 2 wolfBoot_printf("Write Disable: Ret %d\n", ret); +#endif return ret; } @@ -855,7 +866,9 @@ static int qspi_flash_status(QspiDev_t* dev, uint8_t* status) cmd[0] = READ_FSR_CMD; ret = qspi_transfer(dev, cmd, 1, NULL, 0, cmd, 2, 0, GQSPI_GEN_FIFO_MODE_SPI); +#if defined(DEBUG_ZYNQ) && DEBUG_ZYNQ >= 2 wolfBoot_printf("Flash Status: Ret %d Cmd %02x %02x\n", ret, cmd[0], cmd[1]); +#endif if (ret == GQSPI_CODE_SUCCESS && status) { if (dev->stripe) { cmd[0] &= cmd[1]; @@ -874,7 +887,9 @@ static int qspi_status(QspiDev_t* dev, uint8_t* status) cmd[0] = READ_SR_CMD; ret = qspi_transfer(dev, cmd, 1, NULL, 0, cmd, 2, 0, GQSPI_GEN_FIFO_MODE_SPI); +#if defined(DEBUG_ZYNQ) && DEBUG_ZYNQ >= 2 wolfBoot_printf("Status: Ret %d Cmd %02x %02x\n", ret, cmd[0], cmd[1]); +#endif if (ret == GQSPI_CODE_SUCCESS && status) { if (dev->stripe) { cmd[0] &= cmd[1]; @@ -938,7 +953,9 @@ static int qspi_enter_4byte_addr(QspiDev_t* dev) if (ret == GQSPI_CODE_SUCCESS) { ret = qspi_transfer(dev, cmd, 1, NULL, 0, NULL, 0, 0, GQSPI_GEN_FIFO_MODE_SPI); + #if defined(DEBUG_ZYNQ) && DEBUG_ZYNQ >= 2 wolfBoot_printf("Enter 4-byte address mode: Ret %d\n", ret); + #endif if (ret == GQSPI_CODE_SUCCESS) { ret = qspi_wait_ready(&mDev); /* Wait for not busy */ } @@ -957,7 +974,9 @@ static int qspi_exit_4byte_addr(QspiDev_t* dev) if (ret == GQSPI_CODE_SUCCESS) { ret = qspi_transfer(dev, cmd, 1, NULL, 0, NULL, 0, 0, GQSPI_GEN_FIFO_MODE_SPI); + #if defined(DEBUG_ZYNQ) && DEBUG_ZYNQ >= 2 wolfBoot_printf("Exit 4-byte address mode: Ret %d\n", ret); + #endif if (ret == GQSPI_CODE_SUCCESS) { ret = qspi_wait_ready(&mDev); /* Wait for not busy */ } diff --git a/src/qspi_flash.c b/src/qspi_flash.c index 04a4915e..6959d969 100644 --- a/src/qspi_flash.c +++ b/src/qspi_flash.c @@ -44,9 +44,6 @@ #ifndef FLASH_PAGE_SIZE #define FLASH_PAGE_SIZE SPI_FLASH_PAGE_SIZE #endif -#ifndef FLASH_NUM_PAGES -#define FLASH_NUM_PAGES (FLASH_DEVICE_SIZE/FLASH_PAGE_SIZE) -#endif #ifndef FLASH_SECTOR_SIZE #define FLASH_SECTOR_SIZE SPI_FLASH_SECTOR_SIZE #endif diff --git a/tools/lms/lms_common.h b/tools/lms/lms_common.h index 6aef6005..ba7ba35b 100644 --- a/tools/lms/lms_common.h +++ b/tools/lms/lms_common.h @@ -43,10 +43,10 @@ static int lms_write_key(const byte * priv, word32 privSz, void * context) filename = context; /* Open file for read and write. */ - file = fopen(filename, "r+"); + file = fopen(filename, "rb+"); if (!file) { /* Create the file if it didn't exist. */ - file = fopen(filename, "w+"); + file = fopen(filename, "wb+"); if (!file) { fprintf(stderr, "error: fopen(%s, \"w+\") failed.\n", filename); return WC_LMS_RC_WRITE_FAIL; @@ -69,7 +69,7 @@ static int lms_write_key(const byte * priv, word32 privSz, void * context) /* Verify private key data has actually been written to persistent * storage correctly. */ - file = fopen(filename, "r+"); + file = fopen(filename, "rb+"); if (!file) { fprintf(stderr, "error: fopen(%s, \"r+\") failed.\n", filename); return WC_LMS_RC_WRITE_FAIL; diff --git a/tools/xmss/xmss_common.h b/tools/xmss/xmss_common.h index 5c31ea02..66e8a305 100644 --- a/tools/xmss/xmss_common.h +++ b/tools/xmss/xmss_common.h @@ -43,10 +43,10 @@ static enum wc_XmssRc xmss_write_key(const byte * priv, word32 privSz, void * co filename = context; /* Open file for read and write. */ - file = fopen(filename, "r+"); + file = fopen(filename, "rb+"); if (!file) { /* Create the file if it didn't exist. */ - file = fopen(filename, "w+"); + file = fopen(filename, "wb+"); if (!file) { fprintf(stderr, "error: fopen(%s, \"w+\") failed.\n", filename); return WC_XMSS_RC_WRITE_FAIL; @@ -69,7 +69,7 @@ static enum wc_XmssRc xmss_write_key(const byte * priv, word32 privSz, void * co /* Verify private key data has actually been written to persistent * storage correctly. */ - file = fopen(filename, "r+"); + file = fopen(filename, "rb+"); if (!file) { fprintf(stderr, "error: fopen(%s, \"r+\") failed.\n", filename); return WC_XMSS_RC_WRITE_FAIL;