Any Support for booting from Spi Flash?

yep same thing.

U-Boot 2021.10 (Aug 04 2024 - 15:05:57 -0300)cvitek_cv180x

DRAM:  63.3 MiB
gd->relocaddr=0x823f3000. offset=0x21f3000
MMC:   cv-sd@4310000: 0
Loading Environment from SPIFlash... spinor id = EF 40 19
SF: Detected W25Q256JV-IQ with page size 256 Bytes, erase size 4 KiB, total 32 MiB
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   
Warning: ethernet@4070000 (eth0) using random MAC address - ee:69:b0:67:14:0a
eth0: ethernet@4070000
Hit any key to stop autoboot:  1  0 
spinor id = EF 40 19
SF: Detected W25Q256JV-IQ with page size 256 Bytes, erase size 4 KiB, total 32 MiB
device 0 offset 0xa0000, size 0x400000
SF: 4194304 bytes @ 0xa0000 Read: OK
sf read speed 31.775 MB/s
Wrong Image Format for bootm command
ERROR: can't get kernel image!
## Error: "nandboot" not defined
## Error: "emmcboot" not defined
cv180x_c906# 

Also using sf cmds u gave gives this

cv180x_c906# sf read 0x81400000 0x0 256
device 0 offset 0x0, size 0x256
SF: 598 bytes @ 0x0 Read: OK
sf read speed 0.99 MB/s
cv180x_c906# md.b 0x81400000 64
81400000: c3 56 42 4c 38 31 0a 40 00 00 00 00 81 10 fe ca  .VBL81.@........
81400010: 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  @...............
81400020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
81400030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
81400040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
81400050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
81400060: 00 00 00 00                                      ....
cv180x_c906# 

so yeh it doesnt like the other chip. Flashing this chip works but as you can see the first byte is somehow corrupted when using sf and it fails to load kernel And if for example you wanted to load the kernel which is at 0xA0000 , you would have to do sf read 0x813FFFFF 256 and then md.b 0x81400000 so the first byte wouldnt be corrupted…so

1 Like

That is very strange since you are using the flash image I extracted from mtdblock over ssh from my running Duo. Does the read result in the same issue every time, e.g. for 5 times?

1 Like

Yep. But its even stranger…if boot.spinor supposed to be the “linux image”. Why doesnt manually loading the whole 3 MB image into memory work… cuz i tried using both bootm and booti after loading the image to memory with sf read. But it still says wrong image format

I also tried modifying where it loads the linux image and made it display some values

This is from bootm.c

static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc,
			 char *const argv[])
{
	const void *os_hdr;
	bool ep_found = false;
	int ret;

	/* get kernel image header, start address and length */
	os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
			&images, &images.os.image_start, &images.os.image_len);
	/*if (images.os.image_len == 0) {
		puts("ERROR: can't get kernel image!\n");
		return 1;
	}*/
 
 	if (images.os.image_start == 0) {
		puts("ERROR: Kernel Start is 0 \n");
	}
	else{
		char buffer[21];  // 20 digits for unsigned long plus null terminator
        snprintf(buffer, sizeof(buffer), "%lu", images.os.image_start);

		puts("Start Address : ");
		puts(buffer);
		puts(" \n");
	}

but apparently The start address is 0 along with the length of the image…

I dont know much about the image format uboot expects the os to be in…but looking around it seems there are many different images supported even architectures which makes the code all the more confusing.

1 Like

The flash address I was focussing on was 0x0. This is from where the ROM boots the FSBL fip.bin. So we can see the CPU can technically read this correctly using its ROM code. However the U-Boot read behaves differently. Could you increase u-boot verbosity and retry. Append CONFIG_LOGLEVEL=7 to

build/boards/cv180x/cv1800b_milkv_duo_spinor/u-boot/cvitek_cv1800b_milkv_duo_spinor_defconfig

rebuild and reload fip.bin.

1 Like

did that but didnt show any new info

1 Like

Seems that log level helps for NAND but not NOR. Have you made any changes at all to the image? For example disabling ION impacts U-Boot and SPI NOR.

1 Like

@hannahKobain had built me images with and without ion from the start and they did the same thing

If youre using the milk v duo S then something could be different from the board i have.

Even flashing with memory card seems to not work good run to run. When i had the milk v sd img on there. It worked but as i said earlier in the thread. It practically wear out the sdcard causing it to be undetectable. When i flash the chip(s) manually with a custom programmer the data on chip is identical to the source fip.bin and boot.spinor…but only fip.bin works.

So only thing that can possible work rn is fip.bin also had the kernel embed in it.

i wanted to try executing “go” cmd but again i dont know much about image format uboot expects to load. If i did i might be able to “hack” something in. Like for example if the kernel main() is located at address 0x8000 then just force uboot to load that address if it doesnt find any “valid” image. The crc thing also concerns me but again the image on the flash is identical lmao.

Honestly i really want it to work as i planned to use this as the base cpu for a 2nd version of a custom Gaming console. esp32 p4 is $55 , stm32 @500Mhz is around $16. But dont have funds yet for these (life struggles). My console software is written in arduino so thats why i bought this milk v since it supported arduino. This turned out to be a semi rant but yeh lmao.

1 Like

One last thing to try (before adding debugging and/or different Duo) is to check the power rails – especially on the NOR. I have found I need 100nF capacitance on the NOR power rails typically. What is your circuit? Is NOR powered from 3.3V from Duo or elsewhere? Could you probe the rails with an oscilloscope? Try adding 100nF and then also 10uF to the power rails.

1 Like

What is the exact board and revision you are using please?

1 Like

Using the milk v duos 3.3v and Gnd connections.

Milk V Duo 64 MB Board version v1.2 ( DUO_MB_V1.2)

1 Like

How is the NOR connected to the Duo (PCB, etc.)? How much capacitance is added to the NOR and how close is it to the IC?

Your PCB revision is the same as mine. I do have custom PCBs to connect all sorts of SPI flash to this Duo. I’ve been using those in my demonstrations.

1 Like

Its connected with female to female jumper wires. All same length. flash is mounted on a small pcb with headers. each same length. The pin holes on the milk v have been populated with the included headers

1 Like

I had reliability issues when I started in this manner, hence ended up creating a PCB. Even a ‘home-made’ one made things rock solid for me. The SPI lines are quite fast so I recommend avoiding flying leads. In any case, use short cables and try and get the silicone ‘luxury’ ones.

Definitely try soldering a 100nF capacitor across the power pins on the flash IC. If you do not have 100nF, then use whatever you find. You could also try soldering short leads directly between Duo and breakout PCB. Anything to help with integrity and noise on power rails.

What pull-up resistors have you used and with what values?

1 Like

I shortened the wires by half. And it seems to work…though the first few times it wasnt working. So idk what made it work. Hopefully it was the length of wire. Rn the current length is about 10 cm.

I also found out that Just the 4.7k resistor connected between GND and WP pin is enough to get it to boot to NOR Flash.

@hannahKobain how do you build the image for arduino support. Because it doesnt even show the serial port when fully booted

SF: Detected W25Q256JV-IQ with page size 256 Bytes, erase size 4 KiB, total 32 MiB
device 0 offset 0xa0000, size 0x400000
SF: 4194304 bytes @ 0xa0000 Read: OK
sf read speed 31.536 MB/s
## Loading kernel from FIT Image at 81400000 ...
   Using 'config-cv1800b_milkv_duo_spinor' configuration
   Trying 'kernel-1' kernel subimage
     Description:  cvitek kernel
     Type:         Kernel Image
     Compression:  lzma compressed
     Data Start:   0x814000d8
     Data Size:    3124897 Bytes = 3 MiB
     Architecture: RISC-V
     OS:           Linux
     Load Address: 0x80200000
     Entry Point:  0x80200000
     Hash algo:    crc32
     Hash value:   b9a96e97
   Verifying Hash Integrity ... crc32+ OK
Start Address : 2168455384 
## Loading fdt from FIT Image at 81400000 ...
   Using 'config-cv1800b_milkv_duo_spinor' configuration
   Trying 'fdt-cv1800b_milkv_duo_spinor' fdt subimage
     Description:  cvitek device tree - cv1800b_milkv_duo_spinor
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x816fb098
     Data Size:    19789 Bytes = 19.3 KiB
     Architecture: RISC-V
     Hash algo:    sha256
     Hash value:   23567893e78ba317dac653460c316f91dd1aa25bfe2339293b24dd12d7267f8e
   Verifying Hash Integrity ... sha256+ OK
   Booting using the fdt blob at 0x816fb098
   Uncompressing Kernel Image
   Decompressing 6936064 bytes used 1152ms
   Loading Device Tree to 0000000081bc3000, end 0000000081bcad4c ... OK
1 Like

Which is already too much, IMO.

That’s weird, I didn’t remove anything, nor did I reconfigure the UART.

$ git checkout arduino; && ./build.sh milkv-duo-spinor — this is what I do when I want to build me an image for Duo (64M) & SPI NOR flash.

But for myself, I edited its RAM division configs so that no RAM is being reserved for ION. Also, this allows us leave more RAM to the second core, or the 80c51 core.

If it was higher than 40 Mhz then you’d need to shorten it further. On my Esp32 it doesnt pose a problem until 60-80 MHz. I probably will shorten it but i want to get the Arduino part working then i will make " short traces" on a solderable pcb board i have.

1 Like

You mean, over the USB? No CDC? This is possible, since the SPI flash image is much tinier than the normal one.

Yeh when i boot the nor img i built, it boots to Linux kernel → [root@milkv-duo]~#

The one you built for me panics later in the linux setup. Im retrying it rn to see if its just a bug

1 Like

@hannahKobain This is what your images gives

 0.120639] thermal_sys: Registered thermal governor 'step_wise'
[    0.138934] OF: /gpio@03020000/gpio-controller@0: could not find phandle
[    0.152157] OF: /gpio@03021000/gpio-controller@1: could not find phandle
[    0.159140] OF: /gpio@03022000/gpio-controller@2: could not find phandle
[    0.166133] OF: /gpio@03023000/gpio-controller@3: could not find phandle
[    0.173119] OF: /gpio@05021000/gpio-controller@4: could not find phandle
[    0.182190] clk reset: nr_reset=64 resource_size=8
[    0.187798] get audio clk=24576000
[    0.191351] cvitek-i2s-subsys 4108000.i2s_subsys: Set clk_sdma_aud0~3 to 24576000
[    0.218128] dw_dmac 4330000.dma: CVITEK DMA Controller, 8 channels, probe done!
[    0.226584] SCSI subsystem initialized
[    0.231091] usbcore: registered new interface driver usbfs
[    0.236902] usbcore: registered new interface driver hub
[    0.242509] usbcore: registered new device driver usb
[    0.251427] Ion: ion_parse_dt_heap_common: id 0 type 2 name carveout align 1000
[    0.259309] Ion: rmem_ion_device_init: heap carveout base 0x000000008235b4c0 size 0x0000000001acd000 dev (____ptrval____)
[    0.270588] ion_carveout_heap_create, size=0x1acd000
[    0.275904] cvi_get_rtos_ion_size, rtos ion_size get:0x0
[    0.411162] platform carveout: [ion] add heap id 0, type 2, base 0x8235b4c0, size 0x1acd000
[    0.420169] Advanced Linux Sound Architecture Driver Initialized.
[    0.426535] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
[    0.435526] Oops [#1]
[    0.437941] Modules linked in:
[    0.441176] CPU: 0 PID: 1 Comm: swapper Not tainted 5.10.4-tag- #1
[    0.447622] epc: ffffffe000284e3e ra : ffffffe000284dec sp : ffffffe000a5fc40
[    0.455058]  gp : ffffffe00089cbd8 tp : ffffffe000a60000 t0 : ffffffe000bc3800
[    0.462584]  t1 : 0000001d00000000 t2 : 00000000000000b0 s0 : 0000000000000000
[    0.470110]  s1 : 0000000000000cc0 a0 : 0000000000000001 a1 : 0000000000000001
[    0.477637]  a2 : 0000000000000000 a3 : 0000000000000cc0 a4 : 000000000000000f
[    0.485163]  a5 : ffffffe00235b190 a6 : 0000000000000cc0 a7 : 0000000000000063
[    0.492689]  s2 : 0000000000000004 s3 : 0000000200000022 s4 : ffffffe000787250
[    0.500216]  s5 : 0000000000000000 s6 : 0000000000000001 s7 : ffffffe0007cfbb0
[    0.507742]  s8 : 0000000000000004 s9 : 0000000000000cc0 s10: 0000000000000001
[    0.515269]  s11: 0000000000000010 t3 : 0000000000000000 t4 : 8080808080808080
[    0.522794]  t5 : ffffffe003e68780 t6 : ffffffe000a33251
[    0.528350] status: 0000000200000100 badaddr: 0000000000000000 cause: 000000000000000d
[    0.536593] Call Trace:
[    0.539215] [<ffffffe000284e3e>] pcpu_alloc+0x242/0x3e2
[    0.544668] [<ffffffe00020207a>] rdinit_setup+0x26/0x2a
[    0.550141] [<ffffffe000450f26>] loopback_xmit+0xaa/0xae
[    0.555689] [<ffffffe000531552>] alloc_netdev_mqs+0xa2/0x28a
[    0.561602] [<ffffffe0002145a2>] loopback_net_init+0x26/0x74
[    0.567510] [<ffffffe00021b186>] netdev_init+0x2a/0x4e
[    0.572887] [<ffffffe00052721a>] ops_init.constprop.0+0xb6/0xd2
[    0.579069] [<ffffffe0005272b0>] register_pernet_operations+0x7a/0xa2
[    0.585788] [<ffffffe00052733e>] register_pernet_device+0x28/0x5a
[    0.592148] [<ffffffe00021b1a6>] netdev_init+0x4a/0x4e
[    0.597525] [<ffffffe00021b2c0>] net_dev_init+0x116/0x16e
[    0.603180] [<ffffffe00022a104>] do_one_initcall+0x58/0xf2
[    0.608905] [<ffffffe00020207a>] rdinit_setup+0x26/0x2a
[    0.614372] [<ffffffe000202b38>] kernel_init_freeable+0x186/0x1a6
[    0.620743] [<ffffffe00064e7c0>] rest_init+0xba/0xbe
[    0.625930] [<ffffffe00064e7ce>] kernel_init+0xa/0xd6
[    0.631215] [<ffffffe00064e7c0>] rest_init+0xba/0xbe
[    0.636412] [<ffffffe00022b068>] ret_from_syscall_rejected+0x8/0xc
[    0.642920] ---[ end trace d3a061b01adec6f9 ]---
[    0.647721] note: swapper[1] exited with preempt_count 1
[    0.653276] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[    0.661233] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---
1 Like