|  | 
|  | 1 | +# Runtime chosen image sample application | 
|  | 2 | + | 
|  | 3 | +This sample demonstrates how to use a non flash storage to retrieve the image | 
|  | 4 | +being booted. It was tested on a FRDM K64F. Both slots are used to store two | 
|  | 5 | +different images. The image to be booted is selected based on a button press. | 
|  | 6 | + | 
|  | 7 | +## Build | 
|  | 8 | + | 
|  | 9 | +Build mcuboot. First, ensure ZEPHYR_SDK_INSTALL_DIR is defined. From the | 
|  | 10 | +mcuboot directory, run the following commands: | 
|  | 11 | + | 
|  | 12 | +``` | 
|  | 13 | +  source <path-to-zephyr>/zephyr-env.sh | 
|  | 14 | +
 | 
|  | 15 | +  west build -p -b frdm_k64f boot/zephyr/ -- -DBUILD_RUNTIME_SOURCE_SAMPLE=1 \ | 
|  | 16 | +        -DEXTRA_CONF_FILE="../../samples/runtime-source/zephyr/sample.conf" | 
|  | 17 | +        -DEXTRA_DTC_OVERLAY_FILE=../../samples/runtime-source/zephyr/boards/frdm_k64f.overlay | 
|  | 18 | +
 | 
|  | 19 | +  west build -t flash | 
|  | 20 | +``` | 
|  | 21 | + | 
|  | 22 | +Then, build the sample application to be loaded. We need to build it twice, one | 
|  | 23 | +for each slot. From the sample | 
|  | 24 | +app directory (mcuboot/samples/non-flash-source/zephyr/app), run: | 
|  | 25 | + | 
|  | 26 | +``` | 
|  | 27 | +  west build -p -b frdm_k64f . | 
|  | 28 | +  west flash | 
|  | 29 | +``` | 
|  | 30 | + | 
|  | 31 | +Then change the overlay file to use the second slot. For instance, open | 
|  | 32 | +`boards/frdm_k64f.overlay` and change the line: | 
|  | 33 | + | 
|  | 34 | +``` | 
|  | 35 | +  zephyr,code-partition = &slot0_partition; | 
|  | 36 | +
 | 
|  | 37 | +``` | 
|  | 38 | + | 
|  | 39 | +to: | 
|  | 40 | + | 
|  | 41 | +``` | 
|  | 42 | +    zephyr,code-partition = &slot1_partition; | 
|  | 43 | +``` | 
|  | 44 | + | 
|  | 45 | +And build and flash again: | 
|  | 46 | + | 
|  | 47 | +``` | 
|  | 48 | +  west build -b frdm_k64f . | 
|  | 49 | +  west flash | 
|  | 50 | +``` | 
|  | 51 | + | 
|  | 52 | +## Run | 
|  | 53 | + | 
|  | 54 | +Open a serial terminal to see the output and reset the board. It shall boot the | 
|  | 55 | +image on slot0 by default. By keeping the SW2 button pressed during reset, the | 
|  | 56 | +bootloader will randomly select the image to be booted. | 
0 commit comments