3mdeb / meta-rte

Yocto meta layer for the RTE https://3mdeb.com/products/open-source-hardware/rte/ board
MIT License
7 stars 3 forks source link

recipes-devtools/dediprog-flasher: add recipe #69

Closed tym2k1 closed 4 months ago

tym2k1 commented 4 months ago

Adds the DediProgSW/SF100Linux utility for cases where dpcmd can provide reliable flashing method, alternative to flashrom.

Addresses https://github.com/3mdeb/meta-rte/issues/64

tym2k1 commented 4 months ago

The problem im encountering is there seem to be problems with the libusb library. OpenEmbedded has 2 related recipes:

The DediProgSW/SF100Linux includes <libusb-1.0/libusb.h> and requires libusb-1.0 as a dependancy.

Yet adding either of them to DEPENDS puts out an error:

ERROR: dediprog-flasher-1.0+AUTOINC+e691f2d432-r0 do_compile: oe_runmake failed
ERROR: dediprog-flasher-1.0+AUTOINC+e691f2d432-r0 do_compile: Execution of '/build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/temp/run.do_compile.
312' failed with exit code 1:
  CC  dpcmd.o
  CC  usbdriver.o
  CC  FlashCommand.o
  CC  SerialFlash.o
In file included from usbdriver.c:1:
usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
    6 | #include <libusb-1.0/libusb.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:43: usbdriver.o] Error 1
make: *** Waiting for unfinished jobs....
In file included from dpcmd.c:7:
usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
    6 | #include <libusb-1.0/libusb.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:43: dpcmd.o] Error 1
In file included from FlashCommand.c:6:
usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
    6 | #include <libusb-1.0/libusb.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:43: FlashCommand.o] Error 1
In file included from SerialFlash.c:5:
usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
    6 | #include <libusb-1.0/libusb.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:43: SerialFlash.o] Error 1
WARNING: exit code 1 from a shell command.

ERROR: Logfile of failure stored in: /build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/temp/log.do_compile.312
Log data follows:
| DEBUG: Executing shell function do_compile
| NOTE: make -j 16
|   CC  dpcmd.o
|   CC  usbdriver.o
|   CC  FlashCommand.o
|   CC  SerialFlash.o
| In file included from usbdriver.c:1:
| usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
|     6 | #include <libusb-1.0/libusb.h>
|       |          ^~~~~~~~~~~~~~~~~~~~~
| compilation terminated.
| make: *** [Makefile:43: usbdriver.o] Error 1
| make: *** Waiting for unfinished jobs....
| In file included from dpcmd.c:7:
| usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
|     6 | #include <libusb-1.0/libusb.h>
|       |          ^~~~~~~~~~~~~~~~~~~~~
| compilation terminated.
| make: *** [Makefile:43: dpcmd.o] Error 1
| In file included from FlashCommand.c:6:
| usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
|     6 | #include <libusb-1.0/libusb.h>
|       |          ^~~~~~~~~~~~~~~~~~~~~
| compilation terminated.
| make: *** [Makefile:43: FlashCommand.o] Error 1
| In file included from SerialFlash.c:5:
| usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
|     6 | #include <libusb-1.0/libusb.h>
|       |          ^~~~~~~~~~~~~~~~~~~~~
| compilation terminated.
| make: *** [Makefile:43: SerialFlash.o] Error 1
| ERROR: oe_runmake failed
| WARNING: exit code 1 from a shell command.
| ERROR: Execution of '/build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/temp/run.do_compile.312' failed with exit code 1:
|   CC  dpcmd.o
|   CC  usbdriver.o
|   CC  FlashCommand.o
|   CC  SerialFlash.o
| In file included from usbdriver.c:1:
| usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
|     6 | #include <libusb-1.0/libusb.h>
|       |          ^~~~~~~~~~~~~~~~~~~~~
| compilation terminated.
| make: *** [Makefile:43: usbdriver.o] Error 1
| make: *** Waiting for unfinished jobs....
| In file included from dpcmd.c:7:
| usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
|     6 | #include <libusb-1.0/libusb.h>
|       |          ^~~~~~~~~~~~~~~~~~~~~
| compilation terminated.
| make: *** [Makefile:43: dpcmd.o] Error 1
| In file included from FlashCommand.c:6:
| usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
|     6 | #include <libusb-1.0/libusb.h>
|       |          ^~~~~~~~~~~~~~~~~~~~~
| compilation terminated.
| make: *** [Makefile:43: FlashCommand.o] Error 1
| In file included from SerialFlash.c:5:
| usbdriver.h:6:10: fatal error: libusb-1.0/libusb.h: No such file or directory
|     6 | #include <libusb-1.0/libusb.h>
|       |          ^~~~~~~~~~~~~~~~~~~~~
| compilation terminated.
| make: *** [Makefile:43: SerialFlash.o] Error 1
| WARNING: exit code 1 from a shell command.
|
ERROR: Task (/repo/recipes-devtools/dediprog-flasher/dediprog-flasher.bb:do_compile) failed with exit code '1'

Inside the bitbake dediprog-flasher.bb -c devshell i can see the dpkg --list output and files available at $PKG_CONFIG_PATH

$ dpkg --list | grep usb
$
$ echo $PKG_CONFIG_PATH
/build/tmp/work/armv7vet2hf-neon-rte-linux-gnuethe abi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/recipe-sysroot/usr/lib/pkgconfig:
/build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/recipe-sysroot/usr/share/pkgconfig
$ ls /build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/recipe-sysroot/usr/share/pkgconfig| grep usb
$ ls /build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/recipe-sysroot/usr/lib/pkgconfig | grep usb
libusb-1.0.pc
libusb.pc
$ cat libusb.pc
prefix=/usr
exec_prefix=/usr
libdir=/lib
includedir=/usr/include

emulated=1
emulated_by=libusb-1.0

Name: libusb
Description: USB access library (libusb-1.0 compat wrapper)
Version: 0.1.12
Requires.private: libusb-1.0
Libs: -L${libdir} -lusb
Cflags: -I${includedir}

$ cat libusb-1.0.pc
prefix=/usr
exec_prefix=/usr
libdir=/lib
includedir=/usr/include

Name: libusb-1.0
Description: C API for USB device access from Linux, Mac OS X, Windows, OpenBSD/NetBSD and Solaris userspace
Version: 1.0.22
Libs: -L${libdir} -lusb-1.0
Libs.private: -ludev  -pthread
Cflags: -I${includedir}/libusb-1.0

Adding the -native suffix didn't yield any valid results.

The recipe is a copy of imx-usb-loader_git.bb that also includes <libusb-1.0/libusb.h>

macpijan commented 4 months ago

@tym2k1 I suggest to include following patch in the build - possibly sending a PR to their repo as well:

Author: Maciej Pijanowski <maciej.pijanowski@3mdeb.com>
Date:   Fri Jul 5 16:39:13 2024 +0200

    Makefile: allow overriding CC

    Signed-off-by: Maciej Pijanowski <maciej.pijanowski@3mdeb.com>

diff --git a/Makefile b/Makefile
index 139e5c0c3c3c..226303a6921e 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ endif
 endif

 PROGRAM = dpcmd
-CC      = gcc
+CC     ?= gcc
 PREFIX ?= /usr/local

 PKG_CONFIG ?= pkg-config

This Makefile is not suited for cross compilation, which is not surprising at all. Although I must admit, it is high quality overall, we typically deal with much worse when creating recipes.

https://danyspin97.org/blog/makefiles-best-practices/

tym2k1 commented 4 months ago

I've added the patch and addressed all threads but now the build fails at do_install. There seems to be some problem with the strip command and how it parses the built dpcmd binary.

ERROR: dediprog-flasher-1.0+AUTOINC+e691f2d432-r0 do_install: oe_runmake failed
ERROR: dediprog-flasher-1.0+AUTOINC+e691f2d432-r0 do_install: Execution of '/build/tmp/work/armv7vet2hf-
neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/temp/run.do_install.2499' failed with
exit code 1:
install: creating directory '/build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/image/usr'
install: creating directory '/build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/image/usr/bin'
install: creating directory '/build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/image/usr/share'
install: creating directory '/build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/image/usr/share/DediProg'
install: 'dpcmd' -> '/build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/image/usr/bin/dpcmd'
strip: Unable to recognise the format of the input file `/build/tmp/work/armv7vet2hf-neon-rte-linux-gnueabi/dediprog-flasher/1.0+AUTOINC+e691f2d432-r0/image/usr/bin/dpcmd'
make: *** [Makefile:61: install] Error 1
WARNING: exit code 1 from a shell command.

Working on it

macpijan commented 4 months ago

@tym2k1 Well, the strip is also part of the toolchain. If we simply use strip as in this Makefile, the native strip binary would be used.

Check if yocto provides path to strip from toolchain via env variable and modify the Makefile so it can be overriden as well.

If more commands than simply gcc from toolchain get used, one may also define the CROSS_COMPILE variable to simplify that. Please refer to the Makefile in linux tree. But simply defining STRIP next to CC should be enough here probably.

tym2k1 commented 4 months ago

As I stated in the patch I think it's best to leave stripping of binaries to built-in bitbake functionalities. As stated in https://github.com/3mdeb/meta-rte/issues/64#issuecomment-2210830251 I'll try to upstream this recipe when we'll tackle https://github.com/3mdeb/meta-rte/issues/67 as current version has reached EOL and we need to ensure it builds for currently supported Yocto versions.

tym2k1 commented 4 months ago

The dpcmd utility also always checks for the ChipInfoDb.dedicfg at relative path ../share/Dediprog/ChipInfoDb.dedicfg. Currently it's placed at /usr/bin/dpcmd and the ChipInfoDb.dedicfg is placed at /usr/share/DediProg/ChipInfoDb.dedicfg so everything works correctly. @macpijan shall we leave it this way or is more work needed to add more robustness to the way the script handles ChipInfoDb.dedicfg ?