fairecasoimeme / ZiGate

Zigate is an Universal Zigbee Gateway
http://zigate.fr
171 stars 59 forks source link

Compiling on Linux #343

Closed devbis closed 3 years ago

devbis commented 3 years ago

I provided several changes to allow compiling the firmware for jn51xx chips on Linux systems using the BA2 toolchain. I added an instruction for building on Linux as well as on Windows.

The major change is the renaming of top-level directories 'Module Radio' -> 'ModuleRadio' (and 'Module Wifi' -> 'ModuleWifi' for consistency) It fixes the issue when make on Linux treat names with spaces as two files.

Another fixed problem was removing py2exe compiled binaries and replacing them with pure python scripts. So building on Linux requires python2.7 or python3.4+ and installed xmltodict library that can be installed from PyPI in a generic way

Windows part is not affected by the changes and compiles successfully too.

Compiling on Linux can be used for non-windows users as well for creating automated builds.

Thanks!

schrodingersket commented 3 years ago

I provided several changes to allow compiling the firmware for jn51xx chips on Linux systems using the BA2 toolchain. I added an instruction for building on Linux as well as on Windows.

The major change is the renaming of top-level directories 'Module Radio' -> 'ModuleRadio' (and 'Module Wifi' -> 'ModuleWifi' for consistency) It fixes the issue when make on Linux treat names with spaces as two files.

Another fixed problem was removing py2exe compiled binaries and replacing them with pure python scripts. So building on Linux requires python2.7 and installed amara library that can be installed from PyPI in a generic way

Windows part is not affected by the changes and compiles successfully too.

Compiling on Linux can be used for non-windows users as well for creating automated builds.

Thanks!

Just want to say this is AWESOME! This would let me delete my Windows VM that I'm currently using just for this 😅

devbis commented 3 years ago

I fixed several issues in ZPSConfig.py and it returns missing ZDOServers entries in zps_gen.c Also I modifies deps in Makefile to eliminate error with missing pdum_apdu.S that allows building the firmware in one run.

devbis commented 3 years ago

I fixed parallel build to increase building speed in -jXXX mode

devbis commented 3 years ago

I introduced an example YAML file for GitHub actions that allows compiling 16 firmware binaries with different build options at once.

https://github.com/devbis/ZiGate/blob/auto_build/.github/workflows/c-cpp.yml

It may help introducing CI/CD integration for ZiGate

G1K commented 3 years ago

It works! Are there any problems preventing the merge @fairecasoimeme ?

devbis commented 3 years ago

I rebased the PR on the top of the master branch

fairecasoimeme commented 3 years ago

ok thanks for fix

pipiche38 commented 3 years ago

Looks like some Python modules have to be installed , as well as some cross compiler

devbis commented 3 years ago

It is described in the readme section https://github.com/fairecasoimeme/ZiGate/tree/master/ModuleRadio/Firmware/src#linux You can compile GCC binaries or download pre-compiled ones.

pipiche38 commented 3 years ago

Thanks got it.

pipiche38 commented 3 years ago

Unfortunatly the cross compiler do not compile on Fedora distribution!

Building JTAG Release r36379
  AUTOHEAD stamp-h1
  CONFIG.S stamp-h
  CONFIG.S Makefile
  CC       jp3.o
  CC       jp-io.o
  CC       ftdi_driver.o
jp-io.c:28:11: fatal error: 'sys/io.h' file not found
        #include <sys/io.h>
                 ^~~~~~~~~~
In file included from ftdi_driver.c:35:
./ftdi_driver.h:78:28: warning: declaration of 'struct ftdi_context' will not be visible outside of this function [-Wvisibility]
void ftdi_set_state(struct ftdi_context *ftdi, int state);
                           ^
./ftdi_driver.h:79:32: warning: declaration of 'struct ftdi_context' will not be visible outside of this function [-Wvisibility]
void ftdi_set_state_buf(struct ftdi_context *ftdi, uint8_t *buf, int sz);
                               ^
./ftdi_driver.h:80:27: warning: declaration of 'struct ftdi_context' will not be visible outside of this function [-Wvisibility]
int ftdi_get_state(struct ftdi_context *ftdi);
                          ^
ftdi_driver.c:1492:4: error: use of undeclared identifier 'ftdi_chunk'
                        ftdi_chunk = 0;
                        ^
ftdi_driver.c:1497:4: error: use of undeclared identifier 'ftdi_chunk'
                        ftdi_chunk = -1;
                        ^
ftdi_driver.c:1500:3: error: use of undeclared identifier 'ftdi_chunk'
                ftdi_chunk = strtol(str, NULL, 0);
                ^
ftdi_driver.c:1502:4: error: use of undeclared identifier 'ftdi_chunk'
                        ftdi_chunk *= 1000000;
                        ^
ftdi_driver.c:1506:4: error: use of undeclared identifier 'ftdi_chunk'
                        ftdi_chunk *= 1000;
                        ^
ftdi_driver.c:1532:3: warning: implicit declaration of function 'select_clk_edge_mode' is invalid in C99 [-Wimplicit-function-declaration]
                select_clk_edge_mode(clk_edge_mode);
                ^
4 warnings and 5 errors generated.
make: *** [Makefile:79: ftdi_driver.o] Error 1
make: *** Waiting for unfinished jobs....
1 error generated.
make: *** [Makefile:79: jp-io.o] Error 1
Build failed!
tjikkun commented 3 years ago
jp-io.c:28:11: fatal error: 'sys/io.h' file not found
        #include <sys/io.h>

so sys/io.h is missing. Then: sudo dnf provides */sys/io.h tells you that you need glibc-headers

Hope this helps

pipiche38 commented 3 years ago

rpm -qa | grep glibc-headers glibc-headers-2.31-6.fc32.armv7hl

schrodingersket commented 3 years ago

I run Arch Linux and this works great for me. Granted, I have quite a few cross-compiler toolchains installed for various projects, but I'm spinning up a Fedora VM now to test this compilation out.

schrodingersket commented 3 years ago

I run Arch Linux and this works great for me. Granted, I have quite a few cross-compiler toolchains installed for various projects, but I'm spinning up a Fedora VM now to test this compilation out.

Just confirmed that this works out of the box in the latest Fedora Workstation after following instructions specified in the README. @pipiche38 any chance you're using a 64-bit ARM processor? Wondering if you might need to use <asm/io.h> instead of <sys/io.h>: https://bugzilla.redhat.com/show_bug.cgi?id=1116162#c1