How to enable remoteproc and rpmsg in Google Coral Dev Board (NXP i.MX 8M) - cortex-m

Hi I'm using a Google coral with NXP i.MX 8M and I'm trying to enable communication between Cortex-A53 and Cortex M4F. For that I need the remoteproc and rpmsg.
So I already flashed the Mendel OS on the board. (https://coral.ai/docs/dev-board/get-started/)
Then I followed the exampled to enable the CORTEX M4F:
https://coral.googlesource.com/mcuxpresso_sdk/+/refs/heads/master/boards/evkmimx8mq/demo_apps/hello_world_tflite/
I was able to compile, and run the example with sucess on Cortex M4F.
Then I tried to follow the example to enable multicore: https://coral.googlesource.com/mcuxpresso_sdk/+/refs/heads/master/boards/evkmimx8mq/multicore_examples/rpmsg_lite_str_echo_rtos/readme.txt*https://coral.googlesource.com/mcuxpresso_sdk/+/refs/heads/master/boards/evkmimx8mq/multicore_examples/rpmsg_lite_str_echo_rtos/readme.txt
I was able to compile the bin file on the example and "flash" it on the Cortex-M4F using the same method as hello world:
On the device:
sudo cp hello_world_tflite.bin /boot
cd /boot
sudo ln -sf hello_world_tflite.bin m4_fw.bin
On the device, in u-boot:
setenv m4enabled 1
saveenv
boot
But no output is visible...
How do I enable the remoteproc on Mendel side?
What is missing?
I want to be able to control the cortex m4 with mendel-os.

Related

How to debug custom kernel with GDB and QEMU [duplicate]

I'm new to kernel development and I would like to know how to run/debug the linux kernel using QEMU and gdb. I'm actually reading Robert Love's book but unfortunately it doesn't help the reader on how to install proper tools to run or debug the kernel... So what I did was to follow this tutorial http://opensourceforu.efytimes.com/2011/02/kernel-development-debugging-using-eclipse/. I'm using eclipse as an IDE to develop on the kernel but I wanted first to get it work under QEMU/gdb. So what I did so far was:
1) To compile the kernel with:
make defconfig (then setting the CONFIG_DEBUG_INFO=y in the .config)
make -j4
2) Once the compilation is over I run Qemu using:
qemu-system-x86_64 -s -S /dev/zero -kernel /arch/x86/boot/bzImage
which launch the kernel in "stopped" state
3) Thus I have to use gdb, I try the following command:
gdb ./vmlinux
which run it correctly but... Now I don't know what to do... I know that I have to use remote debugging on the port 1234 (default port used by Qemu), using the vmlinux as the symbol table file for debugging.
So my question is: What should I do to run the kernel on Qemu, attach my debugger to it and thus, get them work together to make my life easier with kernel development.
I'd try:
(gdb) target remote localhost:1234
(gdb) continue
Using the '-s' option makes qemu listen on port tcp::1234, which you can connect to as localhost:1234 if you are on the same machine. Qemu's '-S' option makes Qemu stop execution until you give the continue command.
Best thing would probably be to have a look at a decent GDB tutorial to get along with what you are doing. This one looks quite nice.
Step-by-step procedure tested on Ubuntu 16.10 host
To get started from scratch quickly I've made a minimal fully automated QEMU + Buildroot example at: https://github.com/cirosantilli/linux-kernel-module-cheat/blob/c7bbc6029af7f4fab0a23a380d1607df0b2a3701/gdb-step-debugging.md Major steps are covered below.
First get a root filesystem rootfs.cpio.gz. If you need one, consider:
a minimal init-only executable image: https://unix.stackexchange.com/questions/122717/custom-linux-distro-that-runs-just-one-program-nothing-else/238579#238579
a Busybox interactive system: https://unix.stackexchange.com/questions/2692/what-is-the-smallest-possible-linux-implementation/203902#203902
Then on the Linux kernel:
git checkout v4.15
make mrproper
make x86_64_defconfig
cat <<EOF >.config-fragment
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_KERNEL=y
CONFIG_GDB_SCRIPTS=y
EOF
./scripts/kconfig/merge_config.sh .config .config-fragment
make -j"$(nproc)"
qemu-system-x86_64 -kernel arch/x86/boot/bzImage \
-initrd rootfs.cpio.gz -S -s \
-append nokaslr
On another terminal, from inside the Linux kernel tree, supposing you want to start debugging from start_kernel:
gdb \
-ex "add-auto-load-safe-path $(pwd)" \
-ex "file vmlinux" \
-ex 'set arch i386:x86-64:intel' \
-ex 'target remote localhost:1234' \
-ex 'break start_kernel' \
-ex 'continue' \
-ex 'disconnect' \
-ex 'set arch i386:x86-64' \
-ex 'target remote localhost:1234'
and we are done!!
For kernel modules see: How to debug Linux kernel modules with QEMU?
For Ubuntu 14.04, GDB 7.7.1, hbreak was needed, break software breakpoints were ignored. Not the case anymore in 16.10. See also: https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/901944
The messy disconnect and what come after it are to work around the error:
Remote 'g' packet reply is too long: 000000000000000017d11000008ef4810120008000000000fdfb8b07000000000d352828000000004040010000000000903fe081ffffffff883fe081ffffffff00000000000e0000ffffffffffe0ffffffffffff07ffffffffffffffff9fffff17d11000008ef4810000000000800000fffffffff8ffffffffff0000ffffffff2ddbf481ffffffff4600000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007f0300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000801f0000
Related threads:
https://sourceware.org/bugzilla/show_bug.cgi?id=13984 might be a GDB bug
Remote 'g' packet reply is too long
http://wiki.osdev.org/QEMU_and_GDB_in_long_mode osdev.org is as usual an awesome source for these problems
https://lists.nongnu.org/archive/html/qemu-discuss/2014-10/msg00069.html
nokaslr: https://unix.stackexchange.com/questions/397939/turning-off-kaslr-to-debug-linux-kernel-using-qemu-and-gdb/421287#421287
Known limitations:
the Linux kernel does not support (and does not even compile without patches) with -O0: How to de-optimize the Linux kernel to and compile it with -O0?
GDB 7.11 will blow your memory on some types of tab completion, even after the max-completions fix: Tab completion interrupt for large binaries Likely some corner case which was not covered in that patch. So an ulimit -Sv 500000 is a wise action before debugging. Blew up specifically when I tab completed file<tab> for the filename argument of sys_execve as in: https://stackoverflow.com/a/42290593/895245
See also:
https://github.com/torvalds/linux/blob/v4.9/Documentation/dev-tools/gdb-kernel-debugging.rst official Linux kernel "documentation"
Linux kernel live debugging, how it's done and what tools are used?
When you try to start vmlinux exe using gdb, then first thing on gdb is to issue cmds:
(gdb) target remote localhost:1234
(gdb) break start_kernel
(continue)
This will break the kernel at start_kernel.
BjoernID's answer did not really work for me. After the first continuation, no breakpoint is reached and on interrupt, I would see lines such as:
0x0000000000000000 in ?? ()
(gdb) break rapl_pmu_init
Breakpoint 1 at 0xffffffff816631e7
(gdb) c
Continuing.
^CRemote 'g' packet reply is too long: 08793000000000002988d582000000002019[..]
I guess this has something to do with different CPU modes (real mode in BIOS vs. long mode when Linux has booted). Anyway, the solution is to run QEMU first without waiting (i.e. without -S):
qemu-system-x86_64 -enable-kvm -kernel arch/x86/boot/bzImage -cpu SandyBridge -s
In my case, I needed to break at something during boot, so after some deciseconds, I ran the gdb command. If you have more time (e.g. you need to debug a module that is loaded manually), then the timing doesn't really matter.
gdb allows you to specify commands that should be run when started. This makes automation a bit easier. To connect to QEMU (which should now already be started), break on a function and continue execution, use:
gdb -ex 'target remote localhost:1234' -ex 'break rapl_pmu_init' -ex c ./vmlinux
As for me the best solution for debugging the kernel - is to use gdb from Eclipse environment. You should just set appropriate port for gdb (must be the same with one you specified in qemu launch string) in remote debugging section. Here is the manual:
http://www.sw-at.com/blog/2011/02/11/linux-kernel-development-and-debugging-using-eclipse-cdt/
On Linux systems, vmlinux is a statically linked executable file that contains
the Linux kernel in one of the object file formats supported by Linux, which
includes ELF, COFF and a.out. The vmlinux file might be required for kernel
debugging, symbol table generation or other operations, but must be made
bootable before being used as an operating system kernel by adding a multiboot
header, bootsector and setup routines.
An image of this initial root file system must be stored somewhere accessible
by the Linux bootloader to the boot firmware of the computer. This can be the
root file system itself, a boot image on an optical disc, a small partition on
a local disk (a boot paratition, usually using ext4 or FAT file systems), or a
TFTP server (on systems that can boot from Ethernet).
Compile linux kernel
Build the kernel with this series applied, enabling CONFIG_DEBUG_INFO (but leave CONFIG_DEBUG_INFO_REDUCED off)
https://www.kernel.org/doc/html/latest/admin-guide/README.html
https://wiki.archlinux.org/index.php/Kernel/Traditional_compilation
https://lwn.net/Articles/533552/
Install GDB and Qemu
sudo pacman -S gdb qemu
Create initramfs
#!/bin/bash
# Os : Arch Linux
# Kernel : 5.0.3
INIT_DIR=$(pwd)
BBOX_URL="https://busybox.net/downloads/busybox-1.30.1.tar.bz2"
BBOX_FILENAME=$(basename ${BBOX_URL})
BBOX_DIRNAME=$(basename ${BBOX_FILENAME} ".tar.bz2")
RAM_FILENAME="${INIT_DIR}/initramfs.cpio.gz"
function download_busybox {
wget -c ${BBOX_URL} 2>/dev/null
}
function compile_busybox {
tar xvf ${BBOX_FILENAME} && cd "${INIT_DIR}/${BBOX_DIRNAME}/"
echo "[*] Settings > Build options > Build static binary (no shared libs)"
echo "[!] Please enter to continue"
read tmpvar
make menuconfig && make -j2 && make install
}
function config_busybox {
cd "${INIT_DIR}/${BBOX_DIRNAME}/"
rm -rf initramfs/ && cp -rf _install/ initramfs/
rm -f initramfs/linuxrc
mkdir -p initramfs/{dev,proc,sys}
sudo cp -a /dev/{null,console,tty,tty1,tty2,tty3,tty4} initramfs/dev/
cat > "${INIT_DIR}/${BBOX_DIRNAME}/initramfs/init" << EOF
#!/bin/busybox sh
mount -t proc none /proc
mount -t sysfs none /sys
exec /sbin/init
EOF
chmod a+x initramfs/init
cd "${INIT_DIR}/${BBOX_DIRNAME}/initramfs/"
find . -print0 | cpio --null -ov --format=newc | gzip -9 > "${RAM_FILENAME}"
echo "[*] output: ${RAM_FILENAME}"
}
download_busybox
compile_busybox
config_busybox
Boot Linux Kernel With Qemu
#!/bin/bash
KER_FILENAME="/home/debug/Projects/kernelbuild/linux-5.0.3/arch/x86/boot/bzImage"
RAM_FILENAME="/home/debug/Projects/kerneldebug/initramfs.cpio.gz"
qemu-system-x86_64 -s -kernel "${KER_FILENAME}" -initrd "${RAM_FILENAME}" -nographic -append "console=ttyS0"
$ ./qemuboot_vmlinux.sh
SeaBIOS (version 1.12.0-20181126_142135-anatol)
iPXE (http://ipxe.org) 00:03.0 C980 PCI2.10 PnP PMM+07F92120+07EF2120 C980
Booting from ROM...
Probing EDD (edd=off to disable)... o
[ 0.019814] Spectre V2 : Spectre mitigation: LFENCE not serializing, switching to generic retpoline
can't run '/etc/init.d/rcS': No such file or directory
Please press Enter to activate this console.
/ # uname -a
Linux archlinux 5.0.3 #2 SMP PREEMPT Mon Mar 25 10:27:13 CST 2019 x86_64 GNU/Linux
/ #
Debug Linux Kernel With GDB
~/Projects/kernelbuild/linux-5.0.3 ➭ gdb vmlinux
...
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0xffffffff89a4b852 in ?? ()
(gdb) break start_kernel
Breakpoint 1 at 0xffffffff826ccc08
(gdb)
Display all 190 possibilities? (y or n)
(gdb) info functions
All defined functions:
Non-debugging symbols:
0xffffffff81000000 _stext
0xffffffff81000000 _text
0xffffffff81000000 startup_64
0xffffffff81000030 secondary_startup_64
0xffffffff810000e0 verify_cpu
0xffffffff810001e0 start_cpu0
0xffffffff810001f0 __startup_64
0xffffffff81000410 pvh_start_xen
0xffffffff81001000 hypercall_page
0xffffffff81001000 xen_hypercall_set_trap_table
0xffffffff81001020 xen_hypercall_mmu_update
0xffffffff81001040 xen_hypercall_set_gdt
0xffffffff81001060 xen_hypercall_stack_switch
0xffffffff81001080 xen_hypercall_set_callbacks
0xffffffff810010a0 xen_hypercall_fpu_taskswitch
0xffffffff810010c0 xen_hypercall_sched_op_compat
0xffffffff810010e0 xen_hypercall_platform_op

openocd fails to load board/ti_cc26x0_launchpad.cfg

Has anyone got openocd to work with the TI cc2640r2 launchpad? I built the latest openocd source but it fails to initialise.
OS is Ubuntu 18.04.1 LTS and openocd was built with
configure --enable-xds110 --enable-cmsis-dap
make
make install
Running
openocd -f board/ti_cc26x0_launchpad.cfg
gets the output
Open On-Chip Debugger 0.10.0+dev-00676-g346ce2f1 (2019-02-05-00:53)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
adapter speed: 2500 kHz
Error: The 'jtag configure' command must be used after 'init'.
placing 'debug level 3' statements inside the script files show that it is failing within target/ti_cc26x0.cfg at line 25, which is
jtag configure $_CHIPNAME.cpu -event tap-enable "icepick_c_tapenable $_CHIPNAME.jrc 0"
The scripts must have worked (at least once) as they are part of the source distribution.
I use the zephyr folk of open-ocd:
git clone https://github.com/zephyrproject-rtos/openocd.git
cd open-ocd
configure
make
make install
I also needed to reduce the JTAG clock speed:
diff --git a/tcl/board/ti_cc26x0_launchpad.cfg b/tcl/board/ti_cc26x0_launchpad.cfg
index 3613a47f7..2580faa52 100644
--- a/tcl/board/ti_cc26x0_launchpad.cfg
+++ b/tcl/board/ti_cc26x0_launchpad.cfg
## -2,6 +2,6 ##
# TI CC26x0 LaunchPad Evaluation Kit
#
source [find interface/xds110.cfg]
-adapter_khz 2500
+adapter_khz 1500
transport select jtag
source [find target/ti_cc26x0.cfg]

Centos7 Kickstart on VirtualBox/VMware Workstation

I am trying to create a kickstart for Centos 7.3. I have a windows desktop with VMware Workstation Player installed. I started with a dvd that has Centos 7.3 on it. I then created a vm in VMware Workstation Player and installed the os. I restarted the vm and copied over all the files from /dev/sr0 from my dvd to a new place. I copied the anaconda file and renamed it to ks.cfg. I then used the command below to make an iso.
mkisofs -o /home/kickstart.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-road-size 4 -boot-info-able -J -R -v "centos7.3"
Next I took this and burned it to a blank cd using
growisofs --dvd-compat -Z /dev/cdrom=/home/kickstart.iso
When I use this in VirtualBox as the optical drive mounted the installer gets stuck on
Started Show Plymouth Boot Screen
Started Device-Mapper Multipath Device Controller
Starting Open-iSCSI...
Reached target Paths.
Reached target Basic System.
Started Open-iSCSI.
Starting dracut initqueue hook..
then on VMware Workstation Player it goes to
Started Show Plymouth Boot Screen
Started Device-Mapper Multipath Device Controller
Starting Open-iSCSI...
Reached target Paths.
Reached target Basic System.
Started Open-iSCSI.
Starting dracut initqueue hook..
... [sda] Assuming cache: write though
Why is it hanging on these spots? I have tried looked everywhere and can't seem to find any solutions so far.
you've probably found something else for this but in case not, or in case someone else encounters this... I encountered some issues with this as well. I don't know if I have the exact issue, though it was hanging on dracut init, and changing this bit allowed the install to continue.
What it turned out to be was the -V flag on the mkisofs command. Whatever you name it with the -V flag (which it doesn't look like you have), it needs to be the value of LABEL in your /isolinux/isolinux.cfg file. In my fiddling I was using "MyLinuxISO" for this value.
in my /isolinux/isolinux.cfg:
label linux
menu label ^Install CentOS Linux 7 with KS
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=MyLinuxISO ks=cdrom:/ks.cfg
using mkisofs
mkisofs -o /home/kickstart.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-road-size 4 -boot-info-able -J -R -v -V "MyLinuxISO"
Don't know if this will help you but give it a shot?
Cheers

How to flash stm32 using only Linux terminal?

So, threre are Archlinux distro, stm32 mc, and C code. How to flash stm32, without some IDE, only using console?
With Texane stlink
Install as described in the README
Convert your firmware to .bin if necessary
arm-none-eabi-objcopy -O binary firmware.elf firmware.bin
/opt/stlink/st-flash write firmware.bin 0x8000000
With OpenOCD, if your board is not supported by Texane
Get it from the link above and install (ignore the eclipse-specific parts)
Find your board description file in openocd/scripts/board, create one if necessary.
openocd -d0 -f board/yourboard.cfg -c "init;targets;halt;flash write_image erase firmware.hex;shutdown"
If you have USB to UART adapter, you can use stm32flash. Basically connect USART1 to the adapter, pull BOOT0 to high (there might be a jumper or button on the board) and power up / reset the board. Then you should be able to follow stm32flash -h to see what to do.
Some STM32 (e.g. STM32F042) has USB DFU bootloader built in, so you can also connect the MCU to USB directly and use dfu-utils.

Can't open serial port on Matlab UNIX

I'm trying to establsih serial communication with an Arduino through USB (running Arch Linux). I can do it in a straightforward way trough a C++ program and using boost::asio, but recently I installed Matlab and been encoutering some issues. I manage to create the serial object with s0=serial('/dev/ttyACM0') but when I call fopen(s0) I get the following error:
Error using serial/fopen (line 72)
Open failed: Port: /dev/ttyACM0 is not available. No ports are available.
Here is what I did to get serial port communication work in Matlab R2014a on Arch Linux 64 bit:
1a) follow the steps described here: http://www.matlabarduino.org/serial-communication.html:
sudo chmod 777 /dev/ttyACM0
Alternatively, add your user to the group uucp: > sudo gpasswd --add username uucp
sudo nano $MATLABROOT/bin/$ARCH/java.opts --> add: -Dgnu.io.rxtx.SerialPorts=/dev/ttyS0:/dev/ttyUSB0:/dev/ttyACM0
1b) check that the connection works in gtkterm (select port ttyACM0)
2) additionally (critical only for Matlab):
sudo chmod 777 /run/lock
/run/lock was symlinked from /var/lock on my distro, so you might have to do this with the latter dir (was 755); alternatively, you can manage access rights to /run/lock/ by ACL.
How I got to this solution:
sudo strace -p 4668 -f -s100 2>&1 | grep -C3 --color -i -e /dev -e serialports -e uucp
-p: process ID == second column from > sudo ps -aux | grep -i matlab
Then, in Matlab type >> sps=instrhwinfo('serial') (which in my case always returned a structure of empty cell-arrays) and monitor the output of strace.
Hope that helps!
cheers :)
By default, only root can use the serial port.
And you can add your id to the serial group "dialout", so you can use the serial port.
Just make soft link from /dev/ttyACM0 to /dev/ttyS[0-255].
ln -sf /dev/ttyACM0 /dev/ttyS100 # for example
Below Matlab R2017a may face this issue.
Detailed Description can find here:
Why is my serial port not recognized with MATLAB on Linux or Solaris?
Hope this can be helped.