Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Jul 19, 2024
Merged

Conversation

tym2k1
Copy link
Contributor

@tym2k1 tym2k1 commented Jul 4, 2024

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

Addresses #64

@tym2k1
Copy link
Contributor Author

tym2k1 commented Jul 5, 2024

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

  • libusb - libusb-0.1 compatibility layer for libusb1
  • libusb1 - A cross-platform library to access USB devices.

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
Copy link
Member

macpijan commented Jul 5, 2024

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

Author: Maciej Pijanowski <[email protected]>
Date:   Fri Jul 5 16:39:13 2024 +0200

    Makefile: allow overriding CC
    
    Signed-off-by: Maciej Pijanowski <[email protected]>

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
Copy link
Contributor Author

tym2k1 commented Jul 8, 2024

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
Copy link
Member

macpijan commented Jul 8, 2024

@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.

install -v -o 0 -g 0 -m 755 -d $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/share/DediProg
echo -n "install: " && install -v -o 0 -g 0 -m 0755 $(PROGRAM) $(DESTDIR)$(PREFIX)/bin/$(PROGRAM)
- strip $(DESTDIR)$(PREFIX)/bin/$(PROGRAM)
+ $(STRIP) $(DESTDIR)$(PREFIX)/bin/$(PROGRAM)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tym2k1 I think you should also set the default value of STRIP to strip so you do not break existing functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by removing strip entirely to leave striping to the do_patch bitbake task. When i'll try to upstream it a reviewer will for sure note if that's the correct approach

@tym2k1
Copy link
Contributor Author

tym2k1 commented Jul 8, 2024

As I stated in the patch I think it's best to leave stripping of binaries to built-in bitbake functionalities. As stated in #64 (comment) I'll try to upstream this recipe when we'll tackle #67 as current version has reached EOL and we need to ensure it builds for currently supported Yocto versions.

@tym2k1
Copy link
Contributor Author

tym2k1 commented Jul 8, 2024

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 ?

@tym2k1 tym2k1 marked this pull request as ready for review July 15, 2024 10:11
@tym2k1 tym2k1 requested a review from macpijan July 15, 2024 10:11
@tym2k1 tym2k1 changed the base branch from develop to release_0.8 July 19, 2024 13:46
@tym2k1 tym2k1 changed the base branch from release_0.8 to release_v0.8 July 19, 2024 13:47
@tym2k1 tym2k1 merged commit 0520bcb into release_v0.8 Jul 19, 2024
@tym2k1 tym2k1 removed the request for review from macpijan July 19, 2024 13:57
@tym2k1 tym2k1 mentioned this pull request Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants