This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PROCESSOR-SDK-AM62P: Uboot cannot access SPI flash

Part Number: PROCESSOR-SDK-AM62P


Tool/software:

Hi TI experts,

Our project is booted from SD Card. but we need to save the u-boot environment to a spi-flash.

I use the TI-SDK 10 with the following DTS.

&main_pmx0 {
	// MAIN_SPI0
	main_spi0_pins_default: main-spi0-pins-default {
		pinctrl-single,pins = <
			AM62PX_IOPAD(0x01bc, PIN_INPUT, 0) /* (B21) SPI0_CLK */
			AM62PX_IOPAD(0x01b4, PIN_INPUT, 0) /* (D20) SPI0_CS0 */
			AM62PX_IOPAD(0x01c0, PIN_INPUT, 0) /* (B20) SPI0_D0 */
			AM62PX_IOPAD(0x01c4, PIN_INPUT, 0) /* (C21) SPI0_D1 */
		>;
	};
}

&main_spi0 {
		status = "okay";
		pinctrl-names = "default";
		pinctrl-0 = <&main_spi0_pins_default>;
		#address-cells = <1>;
		#size-cells= <0>;
		ti,pindir-d0-out-d1-in = <1>;

		flash@0{
				compatible = "jedec,spi-nor";
				reg = <0x0>;
				spi-tx-bus-width = <1>;
				spi-rx-bus-width = <1>;
				spi-max-frequency = <48000000>;
				#address-cells = <1>;
				#size-cells= <1>;

				partition@0 {
						label = "env";
						reg = <0x0 0x20000>;
				};
				partition@1 {
						label = "env.backup";
						reg = <0x20000 0x20000>;
				};
				partition@2 {
						label = "hwid";
						reg = <0x40000 0x20000>;
				};
				partition@3 {
						label = "persistent";
						reg = <0x60000 0x80000>;
				};
				partition@4 {
						label = "Application";
						reg = <0xE0000 0x7F20000>;
				};
		};
};

But the u-boot will crash and restart when I issue the command "sf probe" in u-boot. 

But I can access the flash in the kernel.

We have applied this patch in U-Boot: u-boot-2024.04-ram-usage-fixed.patch for this issue

  • Hi,

    I will try this at my end and let you know.

    Thanks,
    Aparna

  • Hi Aparna, any update?

  • Hi,

    Is this tested on custom board? If yes, what is the flash part being used?

    Is this DTS change done in Linux DTS file only?

    You have to modify the U-boot DTS files as well, to reflect changes in U-boot.

    Regards,
    Aparna

  • Hi Apama

    Yes, our flash is MACRONIX - mx66l1g45g

    We also modify the U-boot DTS
    &main_pmx0 {
    	bootph-all;
    	// MAIN_SPI0
    	main_spi0_pins_default: main-spi0-pins-default {
    		pinctrl-single,pins = <
    			AM62PX_IOPAD(0x01bc, PIN_INPUT, 0) /* (B21) SPI0_CLK */
    			AM62PX_IOPAD(0x01b4, PIN_INPUT, 0) /* (D20) SPI0_CS0 */
    			AM62PX_IOPAD(0x01c0, PIN_INPUT, 0) /* (B20) SPI0_D0 */
    			AM62PX_IOPAD(0x01c4, PIN_INPUT, 0) /* (C21) SPI0_D1 */
    		>;
    	};
    };
    
    // MAIN_SPI0 for 128M Flash
    &main_spi0 {
    		status = "okay";
    		pinctrl-names = "default";
    		pinctrl-0 = <&main_spi0_pins_default>;
    		#address-cells = <1>;
    		#size-cells= <0>;
    		ti,pindir-d0-out-d1-in = <1>;
    
    		flash@0{
    				compatible = "macronix,mx66l1g45g", "jedec,spi-nor";
    				reg = <0x0>;
    				spi-tx-bus-width = <1>;
    				spi-rx-bus-width = <1>;
    				spi-max-frequency = <48000000>;
    				#address-cells = <1>;
    				#size-cells= <1>;
    
    				partition@0 {
    						label = "env";
    						reg = <0x0 0x20000>;
    				};
    				partition@1 {
    						label = "env.backup";
    						reg = <0x20000 0x20000>;
    				};
    				partition@2 {
    						label = "hwid";
    						reg = <0x40000 0x20000>;
    				};
    				partition@3 {
    						label = "persistent";
    						reg = <0x60000 0x80000>;
    				};
    				partition@4 {
    						label = "Application";
    						reg = <0xE0000 0x7F20000>;
    				};
    		};
    };
    Add the "CONFIG_SPI_FLASH_MACRONIX=y" to file am62px_evm_a53_defconfig
  • Hi Apama,

    If I only enable main_spi0 without configuring any devices on this bus (in u-boot DTS), this issue still can be reproduced.

  • Hi Apama,

    I can reproduce the same issue with SDK10 on TI's EVM.

    1. Using clean TI SDK-10

    2. Applied this patch in U-Boot: u-boot-2024.04-ram-usage-fixed.patch 

    3. Enabled the main_spi0 in u-boot dts (k3-am62p5-sk.dts), the modification as below

    @@ -24,7 +24,7 @@
                    mmc0 = &sdhci0;
                    mmc1 = &sdhci1;
                    mmc2 = &sdhci2;
    -               spi0 = &ospi0;
    +               spi0 = &main_spi0;
                    ethernet0 = &cpsw_port1;
                    ethernet1 = &cpsw_port2;
                    usb0 = &usb0;
    @@ -193,6 +193,16 @@
                    >;
            };
    
    +       // MAIN_SPI0
    +       main_spi0_pins_default: main-spi0-pins-default {
    +               pinctrl-single,pins = <
    +                       AM62PX_IOPAD(0x01bc, PIN_INPUT, 0) /* (B21) SPI0_CLK */
    +                       AM62PX_IOPAD(0x01b4, PIN_INPUT, 0) /* (D20) SPI0_CS0 */
    +                       AM62PX_IOPAD(0x01c0, PIN_INPUT, 0) /* (B20) SPI0_D0 */
    +                       AM62PX_IOPAD(0x01c4, PIN_INPUT, 0) /* (C21) SPI0_D1 */
    +               >;
    +       };
    +
            main_i2c1_pins_default: main-i2c1-default-pins {
                    pinctrl-single,pins = <
                            AM62PX_IOPAD(0x01e8, PIN_INPUT_PULLUP, 0) /* (C24) I2C1_SCL */
    @@ -750,6 +760,15 @@
            bootph-all;
     };
    
    +&main_spi0 {
    +               status = "okay";
    +               pinctrl-names = "default";
    +               pinctrl-0 = <&main_spi0_pins_default>;
    +               #address-cells = <1>;
    +               #size-cells= <0>;
    +               ti,pindir-d0-out-d1-in = <1>;
    +
    +};
     /* mcu_gpio0 and mcu_gpio_intr are reserved for mcu firmware usage */
     &mcu_gpio0 {
            status = "reserved";
    

    4. in u-boot issue the command  "sf probe"

  • Hi Apama, 

    any update?

  • Hi,

    Could you try the sf probe command on clean default SDK?
    What output do you get?

    Looks like the pinmux settings shared above is different from what is present in the SDK. The pinmux is specific to the SOC and should not be changed in most cases. If the default SDK doesnot work, we can work forward into porting the flash part.

    Regards,
    Aparna

  • Hi Petra,

    The sf probe command works fine on ospi0. but our board design uses the main_spi0

    My question is: Why does the sf probe crash when using main_spi0? I don’t intend to use ospi0. Can you understand this?

  • My question is: Why does the sf probe crash when using main_spi0? I don’t intend to use ospi0. Can you

    The best will be to use a JTAG debugger and trace the execution of the `sf probe` command to see where it is crashing.

    Before going there, you can use the `objdump` tool from your 64-bit cross-toolchain to look what source code corresponds to the elr / lr addresses in your exception dump:

    Do something like the below (note that is from MY machine/MY U-Boot build, and what you see here with your address plugged in is invalid, I'm just showing this to demonstrate the general principle to get what source corresponds go a certain address). Do this for both `elr` and `lr` addresses to see if this yields something interesting.

    $ aarch64-none-linux-gnu-objdump -S .out_a53/u-boot | grep -i -C 20 8083d3d0
        8083d3a0:   f94022d5        ldr     x21, [x22, #64]
                    bitmap_zero(ud->rflow_map, ud->rflow_cnt);
        8083d3a4:   b940ae62        ldr     w2, [x19, #172]
        8083d3a8:   f9406a60        ldr     x0, [x19, #208]
            if (IS_ERR(rm_res)) {
        8083d3ac:   b14006bf        cmn     x21, #0x1, lsl #12
        8083d3b0:   540011a9        b.ls    8083d5e4 <udma_probe+0x12b4>  // b.plast
                    int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
        8083d3b4:   93407c42        sxtw    x2, w2
                    memset(dst, 0, len);
        8083d3b8:   52800001        mov     w1, #0x0                        // #0
                    int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
        8083d3bc:   9100fc42        add     x2, x2, #0x3f
        8083d3c0:   d346fc42        lsr     x2, x2, #6
                    memset(dst, 0, len);
        8083d3c4:   937d7042        sbfiz   x2, x2, #3, #29
        8083d3c8:   9401e29a        bl      808b5e30 <memset>
            rm_res = tisci_rm->rm_ranges[RM_RANGE_TFLOW];
        8083d3cc:   f94026d5        ldr     x21, [x22, #72]
                    bitmap_zero(ud->tflow_map, ud->tflow_cnt);
        8083d3d0:   b940b262        ldr     w2, [x19, #176]
        8083d3d4:   f9407260        ldr     x0, [x19, #224]
            if (IS_ERR(rm_res)) {
        8083d3d8:   b14006bf        cmn     x21, #0x1, lsl #12
        8083d3dc:   54ffe248        b.hi    8083d024 <udma_probe+0xcf4>  // b.pmore
                    unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
        8083d3e0:   2a0203e2        mov     w2, w2
                    memset(dst, 0xff, len);
        8083d3e4:   52801fe1        mov     w1, #0xff                       // #255
                    unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
        8083d3e8:   9100fc42        add     x2, x2, #0x3f
        8083d3ec:   d346fc42        lsr     x2, x2, #6
                    memset(dst, 0xff, len);
        8083d3f0:   d37df042        lsl     x2, x2, #3
        8083d3f4:   9401e28f        bl      808b5e30 <memset>
        8083d3f8:   d2800003        mov     x3, #0x0                        // #0
            int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
        8083d3fc:   52800808        mov     w8, #0x40                       // #64
            unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
        8083d400:   92800007        mov     x7, #0xffffffffffffffff         // #-1
                    for (i = 0; i < rm_res->sets; i++) {
    

    Also, you can find more background on the specific exception you encountered by plugging it into an online tool, like here:

    https://esr.arm64.dev/#0x96000021

    It says "alignment fault" so likely some code issue/bug.

    Regards, Andreas

  • Hi Andreas,

    Thanks for your reply, I am using TI SDK10 - Yocto build env.

    Could you teach me how to get the file "aarch64-none-linux-gnu-objdump"?

    The u-boot image I can find from "build/arago-tmp-default-glibc/work/am62pxx_evm-oe-linux/u-boot-ti-staging/2024.04+git/deploy-u-boot-ti-staging/u-boot.img", is this file correct? 

    my-uboot

    Thanks!

  • Hi Andreas,

    Actually, I don't know what helps to do this objdump, or how to debug with it.

    Maybe you can simply tell me how to use main_spi0 to communicate with the flash in U-Boot on your SDK 10?

  • Actually, I don't know what helps to do this objdump, or how to debug with it.

    Maybe you can simply tell me how to use main_spi0 to communicate with the flash in U-Boot on your SDK 10?

    I don't have a HW that has a SPI flash connected to a regular SPI peripheral; and I need to be able to re-create this to efficiently debug it.

    Let me compile some instructions on how to do the reverse object dump in the setup you have and get back to you in a day or two.

    Regards, Andreas

  • Hi Andreas,

    I previously mentioned that this issue could be reproduced on your EVM, but it's not important now.
    The issue has been resolved. Thanks for your time.
  • The issue has been resolved.

    Can you please share how the issue was resolved?

    Thanks, Andreas

  • Hi ,

    I found that the root cause is that main_spi0 cannot find the driver.

    In k3-am62p-main.dtsi

    I haven't found the string "ti,am654-mcspi" in the driver, but "ti,omap4-mcspi" is present.

    So this issue was fixed after I added the "CONFIG_OMAP3_SPI=y" in u-boot's defconf.
    I recommend that TI SDK include this driver by default in U-Boot.