David Brown | 9a95b96 | 2017-07-27 10:40:42 -0600 | [diff] [blame] | 1 | Zephyr Test Plan |
| 2 | ================ |
| 3 | |
| 4 | The following roughly describes how mcuboot is tested on Zephyr. The |
| 5 | testing is done with the code in ``samples/zephyr``. These examples |
| 6 | were written using the FRDM-K64F, but other boards should be similar. |
| 7 | At this time, however, the partitions are hardcoded in the Makefile |
| 8 | targets to flash. |
| 9 | |
| 10 | Note that at the time of release of 0.9.0-rc2, the change `MPU flash |
| 11 | write`_ had not been merged. This change fixes a problem interaction |
| 12 | between the MPU and the flash drivers. Without this change, if the |
| 13 | MPU is enabled (the default), the bootloader will abort immediately on |
| 14 | boot, generally before printing any messages. |
| 15 | |
| 16 | .. _MPU flash write: https://github.com/zephyrproject-rtos/zephyr/pull/654 |
| 17 | |
| 18 | At this time, most of the test variants are done by modifying either |
| 19 | the code or Makefiles. A future goal is to automate this testing. |
| 20 | |
| 21 | Sanity Check |
| 22 | ------------ |
| 23 | |
| 24 | Begin by running make in ``samples/zephyr``:: |
| 25 | |
| 26 | $ make clean |
| 27 | $ make all |
| 28 | |
| 29 | This will result in three binaries: ``mcuboot.bin``, |
| 30 | ``signed-hello1.bin``, and ``signed-hello2.bin``. |
| 31 | |
| 32 | The second file is marked as an "upgrade" by the image tool, so |
| 33 | has an appended image trailer. |
| 34 | |
| 35 | Begin by doing a full erase, and programming the first image:: |
| 36 | |
| 37 | $ pyocd-flashtool -ce |
| 38 | $ make flash_boot |
| 39 | |
| 40 | After it resets, look for "main: Starting bootloader", a few debug |
| 41 | messages, and lastly: "main: Unable to find bootable image". |
| 42 | |
| 43 | Then, load hello1:: |
| 44 | |
| 45 | $ make flash_hello1 |
| 46 | |
| 47 | This should print "main: Jumping to the first image slot", and you |
| 48 | should get an image "Hello World number 1!". |
| 49 | |
| 50 | For kicks, program slot 2's image into slot one. This has to be done |
| 51 | manually, and it is good to verify these addresses in the Makefile:: |
| 52 | |
| 53 | $ pyocd-flashtool -a 0x20000 signed-hello1.bin |
| 54 | |
| 55 | This should boot, printing "Upgraded hello!". |
| 56 | |
| 57 | Now put back image 1, and put image 2 in as the upgrade:: |
| 58 | |
| 59 | $ make flash_hello1 |
| 60 | $ make flash_hello2 |
| 61 | |
| 62 | This should print a message: "boot_swap_type: Swap type: test", and |
| 63 | you should see "Upgraded hello!". |
| 64 | |
| 65 | Now reset the target:: |
| 66 | |
| 67 | $ pyocd-tool reset |
| 68 | |
| 69 | And you should see a revert and "Hello world number 1" running. |
| 70 | |
| 71 | Repeat this, to make sure we can mark the image as OK, and that a |
| 72 | revert doesn't happen:: |
| 73 | |
| 74 | $ make flash_hello1 |
| 75 | $ make flash_hello2 |
| 76 | |
| 77 | We should have just booted the Upgraded hello. Mark this as OK:: |
| 78 | |
| 79 | $ pyocd-flashtool -a 0x7ffe8 image_ok.bin |
| 80 | $ pyocd-tool reset |
| 81 | |
| 82 | And make sure this stays in the "Upgraded hello" image. |
| 83 | |
| 84 | Other Signature Combinations |
| 85 | ---------------------------- |
| 86 | |
| 87 | .. note:: Make sure you don't have changes in your tree, as the |
| 88 | following step will undo them. |
| 89 | |
| 90 | As part of the above sanity check, we have tested the RSA signature |
| 91 | algorithm, along with the new RSA-PSS signature algorithm. To test |
| 92 | other configurations, we need to make some modifications to the code. |
| 93 | This is easiest to do by applying some patches (in |
| 94 | ``testplan/zephyr``). For each of these patches, perform something |
| 95 | along the lines of:: |
| 96 | |
| 97 | $ cd ../.. |
| 98 | $ git apply testplan/zephyr/0001-try-rsa-pkcs1-v15.patch |
| 99 | $ cd samples/zephyr |
| 100 | $ make clean |
| 101 | $ make all |
| 102 | $ pyocd-flashtool -ce |
| 103 | $ make flash_boot |
| 104 | $ make flash_hello1 |
| 105 | |
| 106 | Make sure image one boots if it is supposed to (and doesn't if it is |
| 107 | not supposed to). Then try the upgrade:: |
| 108 | |
| 109 | $ make flash_hello2 |
| 110 | |
| 111 | After this, make sure that the the image does or doesn't perform the |
| 112 | upgrade (see test table below). |
| 113 | |
| 114 | After the upgrade runs, reset to make sure the revert works (or |
| 115 | doesn't for the noted cases below):: |
| 116 | |
| 117 | $ pyocd-tool reset |
| 118 | |
| 119 | Then undo the change:: |
| 120 | |
| 121 | $ cd ../.. |
| 122 | $ git checkout -- . |
| 123 | |
| 124 | and repeat the above steps for each patch. |
| 125 | |
| 126 | The following patches are available: |
| 127 | |
| 128 | .. list-table:: Test configurations |
| 129 | :header-rows: 1 |
| 130 | |
| 131 | * - Patch |
| 132 | - hello1 boot? |
| 133 | - Upgrade? |
| 134 | * - 0001-bad-old-rsa-in-boot-not-in-image.patch |
| 135 | - no |
| 136 | - no |
| 137 | * - 0001-bad-old-RSA-no-slot0-check.patch |
| 138 | - yes |
| 139 | - no |
| 140 | * - 0001-good-rsa-pkcs-v1.5-good.patch |
| 141 | - yes |
| 142 | - yes |
| 143 | * - 0001-bad-ECDSA-P256-bootloader-not-in-images.patch |
| 144 | - no |
| 145 | - no |
| 146 | * - 0001-partial-ECDSA-P256-bootloader-slot0-ok-slot1-bad.patch |
| 147 | - yes |
| 148 | - no |
| 149 | * - 0001-good-ECDSA-P256-bootloader-images-signed.patch |
| 150 | - yes |
| 151 | - yes |
| 152 | * - 0001-partial-ECDSA-P256-bootloader-slot-0-bad-sig.patch |
| 153 | - no |
| 154 | - yes[1]_ |
| 155 | * - 0001-partial-ECDSA-P256-bootloader-slot-1-bad-sig.patch |
| 156 | - yes |
| 157 | - no |
| 158 | * - 0001-partial-ECDSA-P256-slot-0-bad-no-verification.patch |
| 159 | - no |
| 160 | - yes[1]_ |
| 161 | |
| 162 | .. [1] These tests with hello1 bad should perform an upgrade when |
| 163 | hello2 is flashed, but they should not revert the image |
| 164 | afterwards. |