Bucket of problems doing upload of dhrystone

Just a bucket of problems dealing with this cute little device.

Looking at the Getting Started docs I see pretty clear directions to attach the unit to a USB port and I do that and I see the unit listed via “lsusb” :

$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 030: ID 0403:6010 Future Technology Devices International, Ltd FT2232C Dual USB-UART/FIFO IC
Bus 001 Device 007: ID 0430:00a2 Sun Microsystems, Inc. Type 7 Keyboard
Bus 001 Device 016: ID 0461:4d0f Primax Electronics, Ltd HP Optical Mouse
Bus 001 Device 005: ID 0430:100e Sun Microsystems, Inc. 24.1" LCD Monitor v4 / FID-638 Mouse
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$ udevadm info -q path -n /dev/ttyUSB0
/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/ttyUSB0/tty/ttyUSB0

Great.

“Chapter 6 Software Development Flow” is reasonable and so I make an area to work under /usr/local/riscv and then do the required “git clone” and “make” and that seems fine. I am able to compile the dhrystone demo ( should really be coremark but that can be done later ) and I get a 32-bit binary output file :slight_smile:

$ ./work/build/riscv-gnu-toolchain/riscv64-unknown-elf/prefix/riscv64-unknown-elf/bin/readelf -e ./software/dhrystone/dhrystone 
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           RISC-V
  Version:                           0x1
  Entry point address:               0x20400000
  Start of program headers:          52 (bytes into file)
  Start of section headers:          112236 (bytes into file)
  Flags:                             0x1, RVC, soft-float ABI
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         3
  Size of section headers:           40 (bytes)
  Number of section headers:         24
  Section header string table index: 23

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .init             PROGBITS        20400000 001000 000076 00  AX  0   0  1
  [ 2] .text             PROGBITS        20400078 001078 002f16 00  AX  0   0  4
  [ 3] .rodata           PROGBITS        20402f90 003f90 000978 00   A  0   0  8
  [ 4] .eh_frame         PROGBITS        20403908 004908 000054 00   A  0   0  4
  [ 5] .sdata2._global_i PROGBITS        2040395c 00495c 000004 00   A  0   0  4
  [ 6] .init_array       INIT_ARRAY      20403960 004960 000004 04  WA  0   0  4
  [ 7] .lalign           PROGBITS        20403964 005070 000000 00   W  0   0  1
  [ 8] .dalign           PROGBITS        80000000 005070 000000 00   W  0   0  1
  [ 9] .data             PROGBITS        80000000 005000 000070 00  WA  0   0  4
  [10] .bss              NOBITS          80000070 000000 002898 00  WA  0   0  4
  [11] .stack            NOBITS          80003800 000000 000800 00  WA  0   0  1
  [12] .debug_info       PROGBITS        00000000 005070 0083a6 00      0   0  1
  [13] .debug_abbrev     PROGBITS        00000000 00d416 002165 00      0   0  1
  [14] .debug_aranges    PROGBITS        00000000 00f580 0002b8 00      0   0  8
  [15] .debug_line       PROGBITS        00000000 00f838 005cee 00      0   0  1
  [16] .debug_str        PROGBITS        00000000 015526 001882 01  MS  0   0  1
  [17] .comment          PROGBITS        00000000 016da8 000011 01  MS  0   0  1
  [18] .debug_frame      PROGBITS        00000000 016dbc 000848 00      0   0  4
  [19] .debug_loc        PROGBITS        00000000 017604 002b62 00      0   0  1
  [20] .debug_ranges     PROGBITS        00000000 01a166 0004f8 00      0   0  1
  [21] .symtab           SYMTAB          00000000 01a660 0009c0 10     22  75  4
  [22] .strtab           STRTAB          00000000 01b020 00055a 00      0   0  1
  [23] .shstrtab         STRTAB          00000000 01b57a 0000f1 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  p (processor specific)

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x001000 0x20400000 0x20400000 0x03964 0x03964 RWE 0x1000
  LOAD           0x005000 0x80000000 0x20403964 0x00070 0x00070 RW  0x1000
  NULL           0x000000 0x80000070 0x80000070 0x00000 0x03098 RW  0x4

 Section to Segment mapping:
  Segment Sections...
   00     .init .text .rodata .eh_frame .sdata2._global_impure_ptr .init_array 
   01     .data 
   02     .bss 
$ 

Lovely.

Everything goes to hell from here.

$ make upload PROGRAM=dhrystone BOARD=freedom-e300-hifive1
work/build/openocd/prefix/bin/openocd -f bsp/env/freedom-e300-hifive1/openocd.cfg & \
/usr/local/riscv/freedom-e-sdk/work/build/riscv-gnu-toolchain/riscv64-unknown-elf/prefix/bin/riscv64-unknown-elf-gdb software/dhrystone/dhrystone --batch -ex "set remotetimeout 240" -ex "target extended-remote localhost:3333" -ex "monitor reset halt" -ex "monitor flash protect 0 64 last off" -ex "load" -ex "monitor resume" -ex "monitor shutdown" -ex "quit" && \
echo "Successfully uploaded 'dhrystone' to freedom-e300-hifive1."
Open On-Chip Debugger 0.10.0+dev (2018-08-02-02:13)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
adapter speed: 10000 kHz
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Error: no device found
Error: unable to open ftdi device with vid 0403, pid 6010, description 'Dual RS232-HS', serial '*' at bus location '*'

Warn : Flash driver of onboard_spi_flash does not support free_driver_priv()
localhost:3333: Connection timed out.
"monitor" command not supported by this target.
"monitor" command not supported by this target.
You can't do that when your target is `exec'
"monitor" command not supported by this target.
"monitor" command not supported by this target.
Successfully uploaded 'dhrystone' to freedom-e300-hifive1.
$

That last line is a lie. Successful? No. Even worse the little unit is gone.
Sure enough the device is gone. Just gone.


$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 007: ID 0430:00a2 Sun Microsystems, Inc. Type 7 Keyboard
Bus 001 Device 016: ID 0461:4d0f Primax Electronics, Ltd HP Optical Mouse
Bus 001 Device 005: ID 0430:100e Sun Microsystems, Inc. 24.1" LCD Monitor v4 / FID-638 Mouse
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$

dmesg claims the device is not connected or just plain gone …

[383723.933197] usb 1-9: new high-speed USB device number 26 using xhci_hcd
[383724.885221] usb usb1-port9: Cannot enable. Maybe the USB cable is bad?
[383725.837235] usb usb1-port9: Cannot enable. Maybe the USB cable is bad?
[383725.837283] usb usb1-port9: attempt power cycle
[383727.105250] usb usb1-port9: Cannot enable. Maybe the USB cable is bad?
[383728.057285] usb usb1-port9: Cannot enable. Maybe the USB cable is bad?
[383728.057333] usb usb1-port9: unable to enumerate USB device

OKay so I fetch a new cable. Unplug the device and switch cables and the USB port also and try again. System logs claim yes we have a device attached …

[384081.667018] usb 1-8: new high-speed USB device number 30 using xhci_hcd
[384081.807496] usb 1-8: New USB device found, idVendor=0403, idProduct=6010
[384081.807507] usb 1-8: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[384081.807513] usb 1-8: Product: Dual RS232-HS
[384081.807518] usb 1-8: Manufacturer: FTDI
[384081.809010] ftdi_sio 1-8:1.0: FTDI USB Serial Device converter detected
[384081.809088] usb 1-8: Detected FT2232H
[384081.809783] usb 1-8: FTDI USB Serial Device converter now attached to ttyUSB0
[384081.810206] ftdi_sio 1-8:1.1: FTDI USB Serial Device converter detected
[384081.810264] usb 1-8: Detected FT2232H
[384081.810406] usb 1-8: FTDI USB Serial Device converter now attached to ttyUSB1
#
# ls -lap /dev/ttyUSB*
crw-rw-r-- 1 root dialout 188, 0 Aug  2 14:04 /dev/ttyUSB0
crw-rw-r-- 1 root dialout 188, 1 Aug  2 14:04 /dev/ttyUSB1
#

OKay so really ?

$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 030: ID 0403:6010 Future Technology Devices International, Ltd FT2232C Dual USB-UART/FIFO IC
Bus 001 Device 007: ID 0430:00a2 Sun Microsystems, Inc. Type 7 Keyboard
Bus 001 Device 016: ID 0461:4d0f Primax Electronics, Ltd HP Optical Mouse
Bus 001 Device 005: ID 0430:100e Sun Microsystems, Inc. 24.1" LCD Monitor v4 / FID-638 Mouse
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$ udevadm info -q path -n /dev/ttyUSB0
/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0/ttyUSB0/tty/ttyUSB0

Yes really.

So let’s try that upload again … once more with feeling …

$ make upload PROGRAM=dhrystone BOARD=freedom-e300-hifive1
work/build/openocd/prefix/bin/openocd -f bsp/env/freedom-e300-hifive1/openocd.cfg & \
/usr/local/riscv/freedom-e-sdk/work/build/riscv-gnu-toolchain/riscv64-unknown-elf/prefix/bin/riscv64-unknown-elf-gdb software/dhrystone/dhrystone --batch -ex "set remotetimeout 240" -ex "target extended-remote localhost:3333" -ex "monitor reset halt" -ex "monitor flash protect 0 64 last off" -ex "load" -ex "monitor resume" -ex "monitor shutdown" -ex "quit" && \
echo "Successfully uploaded 'dhrystone' to freedom-e300-hifive1."
Open On-Chip Debugger 0.10.0+dev (2018-08-02-02:13)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
adapter speed: 10000 kHz
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 10000 kHz
Info : JTAG tap: riscv.cpu tap/device found: 0x10e31913 (mfg: 0x489 (SiFive, Inc.), part: 0x0e31, ver: 0x1)
Info : Examined RISCV core; XLEN=32, misa=0x40001105
Info : Listening on port 3333 for gdb connections
Info : [0] Found 2 triggers
halted at 0x204002a0 due to debug interrupt
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : accepting 'gdb' connection on tcp/3333
Info : Found flash device 'issi is25lp128' (ID 0x0018609d)
main () at dhry_1.c:149
149         Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
Info : JTAG tap: riscv.cpu tap/device found: 0x10e31913 (mfg: 0x489 (SiFive, Inc.), part: 0x0e31, ver: 0x1)
JTAG tap: riscv.cpu tap/device found: 0x10e31913 (mfg: 0x489 (SiFive, Inc.), part: 0x0e31, ver: 0x1)
halted at 0x204002a0 due to debug interrupt
halted at 0x204002a0 due to debug interrupt
cleared protection for sectors 64 through 255 on flash bank 0
cleared protection for sectors 64 through 255 on flash bank 0
Info : JTAG tap: riscv.cpu tap/device found: 0x10e31913 (mfg: 0x489 (SiFive, Inc.), part: 0x0e31, ver: 0x1)
halted at 0x204002a0 due to debug interrupt
Loading section .init, size 0x76 lma 0x20400000
Loading section .text, size 0x2f16 lma 0x20400078
Loading section .rodata, size 0x978 lma 0x20402f90
Loading section .eh_frame, size 0x54 lma 0x20403908
Loading section .sdata2._global_impure_ptr, size 0x4 lma 0x2040395c
Loading section .init_array, size 0x4 lma 0x20403960
Loading section .data, size 0x70 lma 0x20403964
Info : Padding image section 0 at 0x20400076 with 2 bytes
Info : Padding image section 1 at 0x20402f8e with 2 bytes
Info : Retrying memory read starting from 0x80000000 with more delays
Info : Retrying memory read starting from 0x800004d8 with more delays
halted at 0x80000004 due to software breakpoint
halted at 0x80000004 due to software breakpoint
halted at 0x80000004 due to software breakpoint
Info : JTAG tap: riscv.cpu tap/device found: 0x10e31913 (mfg: 0x489 (SiFive, Inc.), part: 0x0e31, ver: 0x1)
halted at 0x80000004 due to software breakpoint
Start address 0x20400000, load size 14800
Transfer rate: 38 KB/sec, 2114 bytes/write.
shutdown command invoked
shutdown command invoked
A debugging session is active.

        Inferior 1 [Remote target] will be detached.

Quit anyway? (y or n) [answered Y; input not from terminal]
Remote communication error.  Target disconnected.: Connection reset by peer.
Successfully uploaded 'dhrystone' to freedom-e300-hifive1.
$ Warn : Flash driver of onboard_spi_flash does not support free_driver_priv()

More lies … because the device is gone gone gone again.

dmesg tells me :

[384299.213831] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[384299.213840] ftdi_sio 1-8:1.0: device disconnected

sure enough the device is sort of gone ?

# ls -lap /dev/ttyUSB*
crw-rw-r-- 1 root dialout 188, 1 Aug  2 14:04 /dev/ttyUSB1
# 

No idea what it going on here … but this is a mess.

Any hints from anyone would be lovely … or I can just go back to qemu or wait for the unleashed board to become available again … any insights from anyone would be lovely.

Dennis

ps: the formatting of simple text on this forum is a mystery to me.