nrf5340: nRF Connect SDK Intermediate, Lesson 9, Exercise 5 (l9_e5_nrf5340_both_sol): with TFM, bootloops

Hi

SDK: ncs-v3.4.2

I wanted to compile the lesson as a starting point for a product in non-secure mode with TFM.

I don't have the nrf5340dk but one with the same chip and more or less most things are identical. I could reduce the problem to the folowing

Changes to the current git branch of l9_e5_nrf5340_both_sol

diff --git a/app.overlay b/app.overlay
index e6a2583..0ff152b 100644
--- a/app.overlay
+++ b/app.overlay
@@ -1,24 +1,34 @@
-/* STEP 1.1  - Add external flash to applciation */
-/delete-node/ &slot1_partition;
+/delete-node/ &mx25r64;
 
-&mx25r64 {
+&qspi {
 	status = "okay";
-	partitions {
-		compatible = "fixed-partitions";
-		#address-cells = <1>;
-		#size-cells = <1>;
-		slot1_partition: partition@0 {
-			label = "image-1";
-			reg = <0x0 0x74000>;
-			ranges = <0x0 0x0 0x74000>;
+	pinctrl-0 = <&qspi_default>;
+	pinctrl-1 = <&qspi_sleep>;
+	pinctrl-names = "default", "sleep";
+
+	by25d40es: by25d40es@0 {
+		compatible = "nordic,qspi-nor";
+		reg = <0>;
+		/* BY25D40ES supports only pp and pp2o */
+		writeoc = "pp";
+		/* BY25D40ES supports only fastread, read2o and read2io*/
+		readoc = "fastread";
+		sck-frequency = <16000000>; // 6-96MHz, Chip kann 104MHz
+		jedec-id = [68 40 13];
+		size-in-bytes = <524288>;
+		has-dpd;
+		t-enter-dpd = <25000>;
+		t-exit-dpd = <25000>;
+		status = "okay";
+		partitions {
+			compatible = "fixed-partitions";
 			#address-cells = <1>;
 			#size-cells = <1>;
-		};
-		/* Net core secondary slot for multi-image DFU */
-		slot3_partition: partition@74000 {
-			label = "image-3";
-			reg = <0x74000 0x40000>;
+			/* Net core secondary slot for multi-image DFU */
+			slot3_partition: partition@00000 {
+				label = "image-3";
+				reg = <0x00000 0x40000>;
+			};
 		};
 	};
-
-};
\ No newline at end of file
+};
diff --git a/sysbuild/mcuboot.overlay b/sysbuild/mcuboot.overlay
index dd2228c..7efb0b1 100644
--- a/sysbuild/mcuboot.overlay
+++ b/sysbuild/mcuboot.overlay
@@ -1,31 +1,40 @@
-/* STEP 1.1  - Add external flash to mcuboot */
-/delete-node/ &slot1_partition;
+/delete-node/ &mx25r64;
 
-&mx25r64 {
+&qspi {
 	status = "okay";
-	partitions {
-		compatible = "fixed-partitions";
-		#address-cells = <1>;
-		#size-cells = <1>;
-		slot1_partition: partition@0 {
-			label = "image-1";
-			reg = <0x0 0x74000>;
-			ranges = <0x0 0x0 0x74000>;
+	pinctrl-0 = <&qspi_default>;
+	pinctrl-1 = <&qspi_sleep>;
+	pinctrl-names = "default", "sleep";
+
+	by25d40es: by25d40es@0 {
+		compatible = "nordic,qspi-nor";
+		reg = <0>;
+		/* BY25D40ES supports only pp and pp2o */
+		writeoc = "pp";
+		/* BY25D40ES supports only fastread, read2o and read2io*/
+		readoc = "fastread";
+		sck-frequency = <16000000>; // 6-96MHz, Chip kann 104MHz
+		jedec-id = [68 40 13];
+		size-in-bytes = <524288>;
+		has-dpd;
+		t-enter-dpd = <25000>;
+		t-exit-dpd = <25000>;
+		status = "okay";
+		partitions {
+			compatible = "fixed-partitions";
 			#address-cells = <1>;
 			#size-cells = <1>;
+			/* Net core secondary slot for multi-image DFU */
+			slot3_partition: partition@00000 {
+				label = "image-3";
+				reg = <0x00000 0x40000>;
+			};
 		};
-		/* Net core secondary slot for multi-image DFU */
-		slot3_partition: partition@74000 {
-			label = "image-3";
-			reg = <0x74000 0x40000>;
-		};
-
 	};
-
 };
 
 / {
 	chosen {
 		zephyr,code-partition = &boot_partition;
 	};
-};
\ No newline at end of file
+};

are only in app.overlay and mcuboot.overlay to support a different memory chip. As they is less in space I dropped the slot1_partition. As they has the same size I will use the default internal one.

  • In the "Build configuration" is only selected "nrf5340dk/nrf5340/cpuapp/ns" to build with TFM.
  • The build is running fine without errors, but I have a boot loop after starting the first image slot from mcuboot.
  • UART0 log

*** Booting MCUboot v2.3.0-dev-5d8736c1fd98 ***
*** Using nRF Connect SDK v3.4.2-f0b8ad4c7377 ***
*** Using Zephyr OS v4.4.2-9133dab6b066 ***
I: Starting bootloader
I: LCS-awareness disabled, skipping LCS check
I: Image index: 0, Swap type: none
I: Image index: 1, Swap type: none
I: Verifying RSA PSS with signature len: 256
I: RSA signature verification successful
I: Bootloader chainload address offset: 0x10000
I: Image version: v2.9.0
I: Jumping to the first image slot
ÿ*** Booting MCUboot v2.3.0-dev-5d8736c1fd98 ***
*** Using nRF Connect SDK v3.4.2-f0b8ad4c7377 ***
*** Using Zephyr OS v4.4.2-9133dab6b066 ***
I: Starting bootloader
I: LCS-awareness disabled, skipping LCS check
I: Image index: 0, Swap type: none
I: Image index: 1, Swap type: none
I: Verifying RSA PSS with signature len: 256
I: RSA signature verification successful
I: Bootloader chainload address offset: 0x10000
I: Image version: v2.9.0
I: Jumping to the first image slot
ÿ*** Booting MCUboot v2.3.0-dev-5d8736c1fd98 ***
*** Using nRF Connect SDK v3.4.2-f0b8ad4c7377 ***
*** Using Zephyr OS v4.4.2-9133dab6b066 ***
I: Starting bootloader
I: LCS-awareness disabled, skipping LCS check
I: Image index: 0, Swap type: none
I: Image index: 1, Swap type: none
I: Verifying RSA PSS with signature len: 256
I: RSA signature verification successful
I: Bootloader chainload address offset: 0x10000
I: Image version: v2.9.0
I: Jumping to the first image slot
ÿ*** Booting MCUboot v2.3.0-dev-5d8736c1fd98 ***
*** Using nRF Connect SDK v3.4.2-f0b8ad4c7377 ***
*** Using Zephyr OS v4.4.2-9133dab6b066 ***
I: Starting bootloader
I: LCS-awareness disabled, skipping LCS check
I: Image index: 0, Swap type: none
I: Image index: 1, Swap type: none
I: Verifying RSA PSS with signature len: 256
I: RSA signature verification successful
I: Bootloader chainload address offset: 0x10000
I: Image version: v2.9.0
I: Jumping to the first image slot

  • UART1 has no output. Should be, because log is not disabled and I2C is not used which would block it.
  • I have connected UART0 and also UART1. I tested both with changing the pin definition. Both UARTs are working well.
  • I have the same with my own dts for the product.
  • The "Build configuration" "nrf5340dk/nrf5340/cpuapp" and my own one without TFM is running well. Updates are possible by FOTA.

Has someone a hint what I can test?

  • Hi John, 

    I will try your problem tomorrow and get back to you by tomorrow evening. Thanks for your patience and sorry for the delay.

    Regards

    Pallavi

  • Now it would be very helpful.

    Also with Log Enable in mcuboot I see nothing as a starting point.

    • Image version and checks are correct
    • RSA signature correct
    • Bootloader chainload address offset: 0x10000 --> correct

    *** Booting MCUboot v2.3.0-dev-5d8736c1fd98 ***<\r><\n>
    *** Using nRF Connect SDK v3.4.2-f0b8ad4c7377 ***<\r><\n>
    *** Using Zephyr OS v4.4.2-9133dab6b066 ***<\r><\n>
    [0:0:0.879,760] <27>[0m<inf> mcuboot: Starting bootloader<27>[0m<\r><\n>
    [0:0:0.884,979] <27>[0m<inf> mcuboot: LCS-awareness disabled, skipping LCS check<27>[0m<\r><\n>
    [0:0:0.892,150] <27>[0m<dbg> mcuboot: context_boot_go: context_boot_go<27>[0m<\r><\n>
    [0:0:0.899,47] <27>[0m<inf> mcuboot: Image index: 0, Swap type: none<27>[0m<\r><\n>
    [0:0:0.905,792] <27>[0m<inf> mcuboot: Image index: 1, Swap type: none<27>[0m<\r><\n>
    [0:0:0.911,987] <27>[0m<dbg> mcuboot: boot_validate_slot: boot_validate_slot: slot 0, expected_swap_type 0<27>[0m<\r><\n>
    [0:0:0.921,386] <27>[0m<dbg> mcuboot: bootutil_img_validate: bootutil_img_validate: flash area 0xb590<27>[0m<\r><\n>
    [0:0:0.930,328] <27>[0m<dbg> mcuboot: bootutil_img_hash: bootutil_img_hash<27>[0m<\r><\n>
    [0:0:1.339,477] <27>[0m<dbg> mcuboot: bootutil_tlv_iter_begin: bootutil_tlv_iter_begin: type 65535, prot == 0<27>[0m<\r><\n>
    [0:0:1.349,121] <27>[0m<dbg> mcuboot: bootutil_img_validate: bootutil_img_validate: TLV off 408300, end 408632<27>[0m<\r><\n>
    [0:0:1.358,886] <27>[0m<dbg> mcuboot: bootutil_tlv_iter_next: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 408300 ending at 408632<27>[0m<\r><\n>
    [0:0:1.372,619] <27>[0m<dbg> mcuboot: bootutil_tlv_iter_next: bootutil_tlv_iter_next: TLV 16 found at 408304 (size 32)<27>[0m<\r><\n>
    [0:0:1.383,56] <27>[0m<dbg> mcuboot: bootutil_img_validate: bootutil_img_validate: EXPECTED_HASH_TLV == 16<27>[0m<\r><\n>
    [0:0:1.392,486] <27>[0m<dbg> mcuboot: bootutil_tlv_iter_next: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 408336 ending at 408632<27>[0m<\r><\n>
    [0:0:1.406,188] <27>[0m<dbg> mcuboot: bootutil_tlv_iter_next: bootutil_tlv_iter_next: TLV 1 found at 408340 (size 32)<27>[0m<\r><\n>
    [0:0:1.416,534] <27>[0m<dbg> mcuboot: bootutil_img_validate: bootutil_img_validate: EXPECTED_KEY_TLV == 1<27>[0m<\r><\n>
    [0:0:1.425,842] <27>[0m<dbg> mcuboot: bootutil_find_key: bootutil_find_key<27>[0m<\r><\n>
    [0:0:1.432,922] <27>[0m<dbg> mcuboot: bootutil_tlv_iter_next: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 408372 ending at 408632<27>[0m<\r><\n>
    [0:0:1.446,624] <27>[0m<dbg> mcuboot: bootutil_tlv_iter_next: bootutil_tlv_iter_next: TLV 32 found at 408376 (size 256)<27>[0m<\r><\n>
    [0:0:1.457,122] <27>[0m<dbg> mcuboot: bootutil_img_validate: bootutil_img_validate: EXPECTED_SIG_TLV == 32<27>[0m<\r><\n>
    [0:0:1.466,552] <27>[0m<dbg> mcuboot: bootutil_verify_sig: bootutil_verify_sig: RSA key_id 0<27>[0m<\r><\n>
    [0:0:1.474,731] <27>[0m<dbg> mcuboot: bootutil_verify: bootutil_verify_sig: RSA key_id 0<27>[0m<\r><\n>
    [0:0:1.482,574] <27>[0m<dbg> mcuboot: bootutil_verify: bootutil_verify: RSA key_id 0<27>[0m<\r><\n>
    [0:0:1.490,81] <27>[0m<dbg> mcuboot: rsa_verify: rsa_verify: PSA implementation, plain key<27>[0m<\r><\n>
    [0:0:1.498,77] <27>[0m<dbg> mcuboot: rsa_verify: Importing RSA PSS key of size: 270<27>[0m<\r><\n>
    [0:0:1.505,523] <27>[0m<dbg> mcuboot: rsa_verify: Key imported. key_id: 1073741824<27>[0m<\r><\n>
    [0:0:1.512,847] <27>[0m<inf> mcuboot: Verifying RSA PSS with signature len: 256<27>[0m<\r><\n>
    [0:0:1.549,591] <27>[0m<inf> mcuboot: RSA signature verification successful<27>[0m<\r><\n>
    [0:0:1.556,335] <27>[0m<dbg> mcuboot: rsa_verify: Destroyed imported key<27>[0m<\r><\n>
    [0:0:1.562,774] <27>[0m<dbg> mcuboot: bootutil_verify: bootutil_verify: rsa_verify status 1<27>[0m<\r><\n>
    [0:0:1.570,892] <27>[0m<dbg> mcuboot: bootutil_tlv_iter_next: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 408632 ending at 408632<27>[0m<\r><\n>
    [0:0:1.584,594] <27>[0m<dbg> mcuboot: bootutil_tlv_iter_next: bootutil_tlv_iter_next: TLV 65535 not found<27>[0m<\r><\n>
    [0:0:1.593,933] <27>[0m<dbg> mcuboot: boot_validate_slot: boot_validate_slot: slot 0, expected_swap_type 0<27>[0m<\r><\n>
    [0:0:1.603,332] <27>[0m<dbg> mcuboot: main: Left boot_go with success == 1<27>[0m<\r><\n>
    [0:0:1.609,954] <27>[0m<inf> mcuboot: Bootloader chainload address offset: 0x10000<27>[0m<\r><\n>
    [0:0:1.617,279] <27>[0m<inf> mcuboot: Image version: v2.9.0<27>[0m<\r><\n>
    [0:0:1.622,619] <27>[0m<inf> mcuboot: Jumping to the first image slot<27>[0m<\r>ÿ<\0>*** Booting MCUboot v2.3.0-dev-5d8736c1fd98 ***<\r><\n>
    *** Using nRF Connect SDK v3.4.2-f0b8ad4c7377 ***<\r><\n>
    *** Using Zephyr OS v4.4.2-9133dab6b066 ***<\r><\n>
    [0:0:0.291,229] <27>[0m<inf> mcuboot: Starting bootloader<27>[0m<\r><\n>
    

    • mcuboot could be debugged.
    • b0n debug is starting but then it is freezing at a switch statement
    • app has in thread viewer the Name: \252\252\252\252\252\252\252\252\252\252\252\252\252\252\252\252\252\
Related