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

Dfu Support #1

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open

Dfu Support #1

wants to merge 70 commits into from

Conversation

superna9999
Copy link
Owner

Add possibility to boot a second stage with DFU

superna9999 and others added 30 commits January 30, 2023 16:00
This permits driving a board controlled by GPIOs on an FTDI
interface.

Also add a sample 99-libftdi.rules to permit using the FTDI device.

Signed-off-by: Neil Armstrong <[email protected]>
Document newer boards over Alpaca.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Add Continuous Integration using Github actions, re-using similar setup
from linux-nfc/neard [1] (dropped Alpine, Ubuntu i386, sanitizers and
few others action steps).  Since I copied most files, I retained all
original copyrights.

The CI will build cdba for several different distros and architectures.

[1] https://github.com/linux-nfc/neard

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Correct parsing of 'B' interface name from config and also fix:

  ftdi-gpio.c: In function ‘ftdi_gpio_parse_config’:
  ftdi-gpio.c:104:31: warning: logical ‘and’ of equal expressions [-Wlogical-op]
    104 |         if (*interface != 'A' &&
        |                               ^~

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Fixes:

  ftdi-gpio.c: In function ‘ftdi_gpio_open’:
  ftdi-gpio.c:190:9: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Fixes:

  ftdi-gpio.c: In function ‘ftdi_gpio_parse_config’:
  ftdi-gpio.c:146:58: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
    146 |                         errx(1, "GPIOs offset invalid: '%d'", gpio_offset);
        |                                                         ~^    ~~~~~~~~~~~
        |                                                          |    |
        |                                                          int  unsigned int
        |                                                         %d

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Pointer arithmetic should not be done on void pointers.

  fastboot.c:223:37: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
    223 |                                 ptr += USB_DT_SS_EP_COMP_SIZE;
        |                                     ^~

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Fixes:

  device.c: In function ‘device_info’:
  list.h:39:26: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
     39 |                 (type *)((char *)__mptr - offsetof(type, member)); \
        |                          ^
  list.h:85:9: note: in expansion of macro ‘container_of’
     85 |         container_of((list)->next, type, member)
        |         ^~~~~~~~~~~~
  list.h:91:21: note: in expansion of macro ‘list_entry_first’
     91 |         for (item = list_entry_first(list, typeof(*(item)), member); \
        |                     ^~~~~~~~~~~~~~~~
  device.c:303:9: note: in expansion of macro ‘list_for_each_entry’
    303 |         list_for_each_entry(device, &devices, node) {
        |         ^~~~~~~~~~~~~~~~~~~

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Pointer arithmetic should not be done on void pointers.

  cdba.c: In function ‘fastboot_work_fn’:
  cdba.c:377:38: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
    377 |         memcpy(msg->data, work->data + work->offset, left);

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Code should avoid comparing signed and unsigned integers, because of
implicit case.

  circ_buf.c: In function ‘circ_fill’:
  circ_buf.c:69:20: warning: comparison of integer expressions of different signedness: ‘ssize_t’ {aka ‘long int’} and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
     69 |         } while (n != space);

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Pointer arithmetic should not be done on void pointers.

  circ_buf.c: In function ‘circ_read’:
  circ_buf.c:104:25: warning: pointer of type ‘void *’ used in subtraction [-Wpointer-arith]
    104 |         return (void*)p - buf;
        |                         ^

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Fixes:

  cdb_assist.c: In function ‘cdb_assist_print_status’:
  cdb_assist.c:351:28: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
    351 |         n = sprintf(buf, "%dmV %dmA%s%s%s%s%s ref: %dmV",
        |                           ~^
        |                            |
        |                            int
        |                           %d
    352 |                          cdb->voltage_set,
        |                          ~~~~~~~~~~~~~~~~
        |                             |
        |                             unsigned int

  cdb_assist.c:372:29: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
    372 |         n = sprintf(buf, "u%d\r\n", mV);
        |                            ~^       ~~
        |                             |       |
        |                             int     unsigned int
        |                            %d

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Code should avoid comparing signed and unsigned integers, because of
implicit case.  Explicit casts are safe because 'buf' size is 256.

  conmux.c: In function ‘registry_lookup’:
  conmux.c:169:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
    169 |         if (ret >= sizeof(buf))
        |                 ^~

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Fixes:

  device_parser.c: In function ‘nextsym’:
  device_parser.c:53:56: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     53 |                 fprintf(stderr, "device parser: error %d\n", dp->parser.error);
        |                                                       ~^     ~~~~~~~~~~~~~~~~
        |                                                        |               |
        |                                                        int             unsigned int
        |                                                       %d
  device_parser.c: In function ‘expect’:
  device_parser.c:80:58: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘unsigned int’ [-Wformat=]
     80 |         fprintf(stderr, "device parser: expected %d got %d\n", type, dp->event.type);
        |                                                         ~^           ~~~~~~~~~~~~~~
        |                                                          |                    |
        |                                                          int                  unsigned int

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Code should avoid comparing signed and unsigned integers, because of
implicit case.  Explicit casts are safe because 'lock' size is PATH_MAX.

  device.c: In function ‘device_lock’:
  device.c:64:15: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
     64 |         if (n >= sizeof(lock))
        |               ^~

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Fixes:

  cdba-server.c: In function ‘fastboot_info’:
  cdba-server.c:98:33: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
     98 |         fprintf(stderr, "%s\n", (char *)buf);
        |                                 ^

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Pointer arithmetic should not be done on void pointers.

  cdba-server.c:146:21: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
    146 |         memcpy(newp + fastboot_size, data, len);
        |                     ^

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Fixes clang warning:

  circ_buf.c:49:9: warning: variable 'count' set but not used [-Wunused-but-set-variable]
          size_t count = 0;
                 ^

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cast via (void *) to fix -Wcast-align clang and GCC on armv7
(arm-linux-gnueabi-gcc) warning for container_of:

  device.c:91:2: warning: cast from 'char *' to 'typeof (*(device)) *' (aka 'struct device *') increases required alignment from 1 to 8 [-Wcast-align]
          list_for_each_entry(device, &devices, node) {
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ./list.h:91:14: note: expanded from macro 'list_for_each_entry'
          for (item = list_entry_first(list, typeof(*(item)), member); \
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ./list.h:85:2: note: expanded from macro 'list_entry_first'
          container_of((list)->next, type, member)
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ./list.h:39:3: note: expanded from macro 'container_of'
                  (type *)((char *)__mptr - offsetof(type, member)); \
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Krzysztof Kozlowski <[email protected]>
After fixing all the warnings (at least on gcc v11.3.0), enable them as
errors, so any silent builds will explicitly fail (also in Continuous
Integration builds).

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Konrad Dybcio <[email protected]>
and leave a comment about lunar EOL

Signed-off-by: Konrad Dybcio <[email protected]>
Don't count the timers, as it's not used anywhere. Clang is unhappy with that:

cdba-server.c:307:6: warning: variable 'count' set but not used [-Wunused-but-set-variable]
        int count = 0;

Signed-off-by: Konrad Dybcio <[email protected]>
There is no need to manually install libc6-dev-ARCH-cross packages.
Corresponding target arch packages will be pulled out via the dependency
of library dev packages.

Reviewed-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Dmitry Baryshkov <[email protected]>
Rather than specifying GCC packages manually, generate package name
using dpkg-architecture.

Reviewed-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Dmitry Baryshkov <[email protected]>
For different reasons it might be desirable to keep slot 'b' as an
active slot. Add support for specifying the active slot in the config
file. The default is still slot 'a'.

Signed-off-by: Dmitry Baryshkov <[email protected]>
Current default is to interpret 20 tilde characters as a signal to power
cycle the board and if there are no power cycles left to exit cdba.
Unfortunately gcc started spurting tilde chars in compile log, so
compiling software on the cdba target can cause cdba exit.

Change the defaults so that by default cdba doesn't interpret received
lines. One can specify '-c 0' on the cdba command line to restore
previous behaviour.

Signed-off-by: Dmitry Baryshkov <[email protected]>
krzk and others added 30 commits September 22, 2023 21:06
Arch Linux builds can fail if system is not upgraded while installing
new packages, probably due to mismatched libraries:

  clang: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /usr/lib/libstdc++.so.6)

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Put 'pkg_config_path' before 'variant' so the environment variables are
ordered alphabetically.  No functional changes.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Remove stale CI script links (unused).

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Limit access control to the boards according to the passed username. If
the user has no access, the board becoms completely invisible: it is not
listed, it is not possible to fetch board description, etc.

Signed-off-by: Dmitry Baryshkov <[email protected]>
Describe optional user/group/device mapping in the config file example.

Signed-off-by: Dmitry Baryshkov <[email protected]>
Set and export the CDBA_USER variable to enable ACL in cdba-server.

Signed-off-by: Dmitry Baryshkov <[email protected]>
Since Linux kernel 6.0, PPPS capable USB hubs expose a simple sysfs
attribute for power control. Allow overwriting the usb control callback
to use PPPS hub control instead.

Signed-off-by: Caleb Connolly <[email protected]>
Musl requires that this header be explicitly included for O_CREAT,
O_CLOEXEC, etc.

Signed-off-by: Caleb Connolly <[email protected]>
Instad of hand-coding message sending, create a single wrapper that
sends messages to the server.

Signed-off-by: Dmitry Baryshkov <[email protected]>
Instad of hand-coding message sending, create a single wrapper that
sends messages to the client.

Signed-off-by: Dmitry Baryshkov <[email protected]>
Extract message sending helpers
On ARM the conmux.c around gethostbyname() results in a compiler
warning/error:

conmux.c:269:27: error: cast increases required alignment of target type [-Werror=cast-align]
  269 |         saddr.sin_addr = *(struct in_addr *)hent->h_addr_list[0];

Instead of trying to fix the (deprecated) gethostbyname() call, switch
conmux to use getaddrinfo(), which is the proper way to resolve
addresses.

Signed-off-by: Dmitry Baryshkov <[email protected]>
Introduce meson.build to be used with the Meson build system,
which handles the dependency and advanced compiler options
for when used on various linux distributions.

The libftdi .so for example has different names on different
distribution, using meson makes sure we can handle those easily,
and easily integrate with other package build systems like
Yocto or Buildroot.

Signed-off-by: Neil Armstrong <[email protected]>
Add x86_64 only meson build for now, meson requires some
cross-compile files to be passed.

Signed-off-by: Neil Armstrong <[email protected]>
Meson requires a cross_compile file for foreign architectures,
and also needs the CPU family.

Add FAMILY to all matrix entries
Remove unused MODE
Print PKG_CONFIG_PATH
Add i386 special Meson setup case
Add cross-compile Meson setup case

Signed-off-by: Neil Armstrong <[email protected]>
This detects Meson automatically and drops custom build step

Signed-off-by: Neil Armstrong <[email protected]>
Remove the Makefile and all the references in the README
and CI scripts.

Signed-off-by: Neil Armstrong <[email protected]>
Signed-off-by: Neil Armstrong <[email protected]>
Signed-off-by: Neil Armstrong <[email protected]>
Signed-off-by: Neil Armstrong <[email protected]>
Signed-off-by: Neil Armstrong <[email protected]>
Signed-off-by: Neil Armstrong <[email protected]>
Signed-off-by: Neil Armstrong <[email protected]>
Signed-off-by: Neil Armstrong <[email protected]>
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.

5 participants