Any Support for booting from Spi Flash?

Run some code to blink led but nothing. No uart output, No led lights up.

RT: [54.952492]Pre system init done
RT: [54.955418]CVIRTOS Build Date:Aug 24 2024  (Time :19:44:54) 
RT: [54.960909]Post system init done
RT: [54.964070]create cvi task
RT: [54.966782][cvi_spinlock_init] succeess
RT: [54.970477]prvCmdQuRunTask run
RT: [56.690976]Pre system init done
RT: [56.693901]CVIRTOS Build Date:Aug 24 2024  (Time :19:44:54) 
RT: [56.699392]Post system init done
RT: [56.702554]create cvi task
RT: [56.705265][cvi_spinlock_init] succeess
RT: [56.708960]prvCmdQuRunTask run
1 Like

Have you tested the identical ELF on the standard SD build, and did the LED blink then? If so, what diagnostics do you have from your current build? What does git diff between your build and mine show as different?

1 Like

I think its a loading issue. Increasing the RTOS Ram in memmap

   # ==============
    # C906L FreeRTOS
    # ==============
    FREERTOS_SIZE = 24576 * SIZE_1K
    # FreeRTOS is at the end of DRAM
    FREERTOS_ADDR = DRAM_BASE + DRAM_SIZE - FREERTOS_SIZE
    FSBL_C906L_START_ADDR = FREERTOS_ADDR 
 

using this it failed to work because the ELF file is forced to load at 0x83f40000. But the new RTOS RUN ADDR is 0x82800000. If i change it back to using 768K is works though there is still an error if you upload via arduino. But if you run it from linux it works. I thought Elf files were relocatable. It seems that either arduino is forcing it to load that address or something is hardcoded.

Right now im looking at the compiler scripts on Arduinos end

1 Like

Success! The problem was the duo build settings in arduino. They were hardcoded to 0x83f40000. I changed the link.ld and board.txt like so.

C:\Users[ User Name ]\AppData\Local\Arduino15\packages\sophgo\hardware\SG200X\0.2.4\board.txt

changed duo.build.start_addr to 0x82800000. duo.build.image_size is the size of RAM for Rtos (768K = 0xc0000). I will change it to 24 MB later.

duo.build.tarch=riscv64
duo.build.target=unknown
duo.build.mcu=sg200x
duo.build.core=sg200x
duo.build.variant=duo
duo.build.board=DUO_DEV
duo.build.extra_flags=
duo.build.bootloader_addr=0x0
duo.build.start_addr=0x82800000 
duo.build.image_size=0xc0000

For the linker
C:\Users[ User Name ]\AppData\Local\Arduino15\packages\sophgo\hardware\SG200X\0.2.4\variants\duo\link.ld

changed ORIGIN to 0x82800000. You also have to change LENGTH to the same value as duo.build.image_size in board.txt file assuming you changed it.

/* Define Memories in the system */
/* LENGTH is the Total Memory ,  Old ORIGIN = 0x83f40000 */

MEMORY
{
   psu_ddr_0_MEM_0 : ORIGIN = 0x82800000 , LENGTH = 0xc0000
}

After that close arduino ide. And delete all the folders in the temporary folder "C:\Users[ User Name ]\AppData\Local\Temp\arduino". If you dont delete it arduino ide will use the precious duo settings because it precompiles some part of it.

dmesg output

[   16.392603] random: fast init done
[   16.395752] remoteproc remoteproc0: powering up c906l_rproc@0
[   16.499160] remoteproc remoteproc0: Booting fw image arduino2.elf, size 576112
[   16.518330] cvitek-rproc c906l_rproc@0: Allocated carveout doesn't fit device address request
[   16.521571] cvitek-rproc c906l_rproc@0: Started from 0x82800000
[   16.521592] remoteproc remoteproc0: remote processor c906l_rproc@0 is now up

Now going to check on the usb upload side of things

1 Like

Problem seems to be burnd.

[root@milkv-duo]~# dmesg -c
[  965.484828] remoteproc remoteproc0: stopped remote processor c906l_rproc@0
[  989.637590] burnd[395]: unhandled signal 11 code 0x1 at 0x0000000000000000 in burnd[10000+88000]
[  989.637652] CPU: 0 PID: 395 Comm: burnd Tainted: GF          O      5.10.4-tag- #1
[  989.637666] epc: 000000000001dd0e ra : 00000000000123b2 sp : 0000003fe57a2a20
[  989.637677]  gp : 000000000009fd20 tp : 0000003fe57a3c60 t0 : 000000000007422e
[  989.637688]  t1 : d363ec5c6b63e8e0 t2 : 0000000000000001 s0 : 00000000000a7880
[  989.637697]  s1 : 000000000009f5d0 a0 : 00000000000a7830 a1 : 0000000000000001
[  989.637708]  a2 : 0000000000000040 a3 : 0000000000000000 a4 : 0000000000000001
[  989.637718]  a5 : 000000000009f5d0 a6 : 0000000000000007 a7 : 0000003fe00015d0
[  989.637728]  s2 : 000000000009f5b0 s3 : 0000000000000040 s4 : 00000000000a75d0
[  989.637738]  s5 : ffffffffc1d61238 s6 : 0000000000000000 s7 : 0000003fe57a3480
[  989.637748]  s8 : 000000000009be98 s9 : 0000003fe57a3c60 s10: 0000000000000001
[  989.637758]  s11: 0000003fe57a3480 t3 : 0000000000000000 t4 : 0000000000000016
[  989.637767]  t5 : 0000000000000061 t6 : 0000000000000078
[  989.637777] status: 8000000201804020 badaddr: 0000000000000000 cause: 000000000000000d
1 Like

There’s no source code for burnd and its also been stripped, so do you have any options?

1 Like

putting this mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /lib/firmware make it “work”

#!/bin/sh

/etc/uhubon.sh device >> /tmp/ncm.log 2>&1
/etc/run_usb.sh probe ncm >> /tmp/ncm.log 2>&1
if test -e /usr/bin/burnd; then
  /etc/run_usb.sh probe acm >> /tmp/ncm.log 2>&1
fi
/etc/run_usb.sh start ncm >> /tmp/ncm.log 2>&1

sleep 0.5
ifconfig usb0 192.168.42.1

count=`ps | grep dnsmasq | grep -v grep | wc -l`
if [ ${count} -lt 1 ] ;then
  echo "/etc/init.d/S80dnsmasq start" >> /tmp/ncm.log 2>&1
  /etc/init.d/S80dnsmasq start >> /tmp/ncm.log 2>&1
fi

sleep 2
mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /lib/firmware
mkdir -p /lib/firmware
if test -e /usr/bin/burnd; then
  burnd &
  if test -e /lib/firmware/arduino.elf; then
    sleep 2
    echo stop  > /sys/class/remoteproc/remoteproc0/state
    echo start > /sys/class/remoteproc/remoteproc0/state
  fi
fi

Now im looking to make 4MB from the bottom of flash into jffs2 so I can save the firmware but dont know much about how to do that. Modified the partition xml but builds fail with it so idk.

1 Like

You’ll need to create the directory before mounting it. What did I do already in my branch?

What error do you get with JFFS? I had it working on earlier SDK builds.

1 Like

It fails if you dont have this mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /lib/firmware. The directory does exist in rootfs btw and even when the directory didnt exist it still need this.

for the jffs2 filesystem i did this in the makefile

jffs2:
	$(call print_target)
ifeq ($(STORAGE_TYPE),spinor)
	chmod 777 $(COMMON_TOOLS_PATH)/mkfs.jffs2
ifeq (${CONFIG_USE_4K_ERASE_SIZE_FOR_JFFS2},y)
	${Q}$(COMMON_TOOLS_PATH)/mkfs.jffs2 -d $(OUTPUT_DIR)/data -l -e 0x1000 --squash -o $(OUTPUT_DIR)/rawimages/data.spinor
else
	${Q}$(COMMON_TOOLS_PATH)/mkfs.jffs2 -d $(OUTPUT_DIR)/data -l -e 0x10000 --squash -o $(OUTPUT_DIR)/rawimages/data.spinor
endif	
	${Q}mkdir -p $(OUTPUT_DIR)/System.jffs2
	${Q}mkdir -p $(OUTPUT_DIR)/System.jffs2/lib
	${Q}cp -arf $(TOP_DIR)/device/$(MV_BOARD)/overlay/lib/* $(OUTPUT_DIR)/System.jffs2/lib/
	${Q}$(COMMON_TOOLS_PATH)/mkfs.jffs2 -r $(OUTPUT_DIR)/System.jffs2 -l -e 0x1000 --squash -o $(OUTPUT_DIR)/rawimages/system.spinor
	$(call raw2cimg ,data.$(STORAGE_TYPE))
endif

the system.spinor just contain /lib/firmware folder. So i have successful got the partition made and flashed but I dont know if it automounts jffs2 or if i need mount it in some file.

my xml is modified like this

<physical_partition type="spinor">
    <partition label="fip" size_in_kb="640" readonly="false" file="fip.bin"/>
    <partition label="BOOT" size_in_kb="4096" readonly="false" file="boot.spinor"/>
    <partition label="ENV" size_in_kb="64" file="" />
    <partition label="ROOTFS" size_in_kb="23872" readonly="true" file="rootfs.spinor" />
    <partition label="SYSTEM" size_in_kb="4096" readonly="false" file="system.spinor" />
</physical_partition>

And it still fails after you mount, but doesn’t complain because the directory exists. You don’t need to create a directory that already exists.

Of course you cannot create a directory on a read-only filesystem to begin with. You’ll need to create it in the root filesystem.

Note in some places you have System.spinor and in others system.spinor. These should all be system.spinor. Check U-Boot writes it to flash and then try mounting the filesystem manually in Duo Linux. It it all works then decide when during boot you wish to mount this. Probably in /etc/fstab.

1 Like

there is System.jffs2 and system.spinor. Systen.jffs2 is folder that just stores the files and folders to put in the jffs2 filesystem. In my case it stores /firmware folder and cvirtos.elf which i renamed to arduino.elf . I will mount it on /lib with fstab.

Also i have this fstab

# <file system>	<mount pt>		<type>	<options>				<dump>	<pass>
/dev/root	/			ext2	rw,noauto				0	1
proc		/proc			proc	defaults				0	0
devpts		/dev/pts		devpts	defaults,gid=5,mode=620,ptmxmode=0666	0	0
tmpfs		/dev/shm		tmpfs	mode=0777				0	0
tmpfs		/tmp			tmpfs	mode=1777				0	0
tmpfs		/run			tmpfs	mode=0755,nosuid,nodev			0	0
sysfs		/sys			sysfs	defaults				0	0
debug		/sys/kernel/debug	debugfs	defaults				0	0
/dev/mmcblk0p1	/boot			vfat	defaults				0	0
/dev/mtdblock4	/lib  	jffs2	rw,defaults				0	0

1 Like

Having trouble with this error

[root@milkv-duo]~# /etc/init.d/S99user: /mnt/system//duo-init.sh: line 8: duo-pinmux: not found

both cvi-pinmux and duo-pinmux gives this error. All other functions work

1 Like

I think they may have skimmed duo-pinmux out to deflate the filesystem in the SPI flash images configurations.

the cvi-pinmux and duo-pinmux are present in usr/bin on the flash but inaccessible

1 Like

Check the PATH environment variable: it should contain /bin/:/usr/bin/, and alike.

i get this:

[root@milkv-duo]~# echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/mnt/system/usr/bin:/mnt/system/usr/sbin
1 Like

Do they have executable (+x) flag set? If not, you should make them executable. If it is on a read-only filesystem, then they should be marked executable in the process of firmware generation.

yehh…

[root@milkv-duo]~# ls -l  /usr/bin/cvi-pinmux
-rwxrwxrwx    1 root     root         38880 Aug 26  2024 e[1;32m/usr/bin/cvi-pinmuxe[m
1 Like