RPi-Distro / rpi-source

Raspberry Pi kernel source installer
MIT License
140 stars 39 forks source link

Error while running the command "rpi-source" in terminal #14

Open chinmaydashp opened 1 year ago

chinmaydashp commented 1 year ago
In file included from ./arch/arm64/include/asm/lse.h:5,
                 from ./arch/arm64/include/asm/cmpxchg.h:14,
                 from ./arch/arm64/include/asm/atomic.h:16,
                 from ./include/linux/atomic.h:7,
                 from ./include/asm-generic/bitops/atomic.h:5,
                 from ./arch/arm64/include/asm/bitops.h:25,
                 from ./include/linux/bitops.h:68,
                 from ./include/linux/log2.h:12,
                 from kernel/bounds.c:13:
./arch/arm64/include/asm/atomic_ll_sc.h: In function '__ll_sc__cmpxchg_double':
./arch/arm64/include/asm/atomic_ll_sc.h:318:38: error: '__uint128_t' undeclared (first use in this function); did you mean '__int128__'?
  318 |  : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr)  \
      |                                      ^~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:325:1: note: in expansion of macro '__CMPXCHG_DBL'
  325 | __CMPXCHG_DBL(   ,        ,  ,         )
      | ^~~~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:318:38: note: each undeclared identifier is reported only once for each function it appears in
  318 |  : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr)  \
      |                                      ^~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:325:1: note: in expansion of macro '__CMPXCHG_DBL'
  325 | __CMPXCHG_DBL(   ,        ,  ,         )
      | ^~~~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:318:51: error: expected expression before ')' token
  318 |  : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr)  \
      |                                                   ^
./arch/arm64/include/asm/atomic_ll_sc.h:325:1: note: in expansion of macro '__CMPXCHG_DBL'
  325 | __CMPXCHG_DBL(   ,        ,  ,         )
      | ^~~~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h: In function '__ll_sc__cmpxchg_double_mb':
./arch/arm64/include/asm/atomic_ll_sc.h:318:38: error: '__uint128_t' undeclared (first use in this function); did you mean '__int128__'?
  318 |  : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr)  \
      |                                      ^~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:326:1: note: in expansion of macro '__CMPXCHG_DBL'
  326 | __CMPXCHG_DBL(_mb, dmb ish, l, "memory")
      | ^~~~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:318:51: error: expected expression before ')' token
  318 |  : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr)  \
      |                                                   ^
./arch/arm64/include/asm/atomic_ll_sc.h:326:1: note: in expansion of macro '__CMPXCHG_DBL'
  326 | __CMPXCHG_DBL(_mb, dmb ish, l, "memory")
      | ^~~~~~~~~~~~~
make[1]: *** [scripts/Makefile.build:118: kernel/bounds.s] Error 1
make: *** [Makefile:1289: prepare0] Error 2
Traceback (most recent call last):
  File "/usr/local/bin/rpi-source", line 421, in <module>
    sh("cd %s && make modules_prepare %s" % (linux_symlink, (" > /dev/null" if args.quiet else "")))
  File "/usr/local/bin/rpi-source", line 93, in sh
    subprocess.check_call(cmd, shell=True)
  File "/usr/lib/python2.7/subprocess.py", line 190, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'cd /home/pi/linux && make modules_prepare ' returned non-zero exit status 2
pelwell commented 1 year ago
  1. Say what you did.
  2. Say what system you did it on.
chinmaydashp commented 1 year ago

I am following the setup for a flow sensor on Raspberry Pi 4B linked here. I followed the steps given in this link, but as they are using the archived repo, I am following the steps given in this repo. I am getting the above error when I run the rpi-source command in the terminal. It installs the kernel but while adding the files it is giving me this error.

pelwell commented 1 year ago

That's not enough information for 2 - what does uname -a report?

pelwell commented 1 year ago

After some experimentation I'm going to guess that you're on 32-bit Raspberry Pi OS with the current apt kernel and firmware. This equates to:

Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux

i.e. a 64-bit kernel on a 32-bit userspace. It should be possible to compile kernel modules with this configuration, but it requires a cross compiler to be installed and used by rpi-source.

Try this:

$ sudo apt install gcc-aarch64-linux-gnu
$ export CROSS_COMPILE=
$ rpi-source

Note that you may need to delete the linux-<hash> directory in order to get rpi-source to do anything,

You should find that rpi-source now runs to completion, just leaving you with the problem that the out-of-tree drivers are a bit old/broken. Apply the following patches to get them building:

index 87b59ca..c64048d 100644
--- a/crc8.c
+++ b/crc8.c
@@ -71,7 +71,7 @@ EXPORT_SYMBOL(crc8_populate_lsb);
  * nbytes: number of bytes in data buffer.
  * crc:        previous returned crc8 value.
  */
-u8 crc8(const u8 table[CRC8_TABLE_SIZE], u8 *pdata, size_t nbytes, u8 crc)
+u8 crc8(const u8 table[CRC8_TABLE_SIZE], const u8 *pdata, size_t nbytes, u8 crc)
 {
        /* loop over the buffer data */
        while (nbytes-- > 0)
diff --git a/sfxx.c b/sfxx.c
index 48e770e..38bfd65 100644
--- a/sfxx.c
+++ b/sfxx.c
@@ -433,14 +433,13 @@ fail_remove_sysfs:
        return ret;
 }

-static int __exit sfxx_remove(struct i2c_client *client)
+static void __exit sfxx_remove(struct i2c_client *client)
 {
        struct sfxx_data *data = i2c_get_clientdata(client);
        if (data != NULL) {
                input_unregister_device(data->dev);
                sysfs_remove_group(&client->dev.kobj, &sfxx_attr_group);
        }
-       return 0;
 }

 /* device ID table */
chinmaydashp commented 1 year ago

Thanks a lot for your help. Yes, I am using the 32-bit Raspberry Pi OS with the current apt kernel and firmware and got

Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux

After following the steps, I am still getting the same error. I am adding the entire terminal log for your reference.


$ sudo apt install gcc-aarch64-linux-gnu
$ export CROSS_COMPILE=

$ rm -r linux-0afb5e98488aed7017b9bf321b575d0177feb7ed
$ rpi-source

 *** SoC: BCM2711

 *** Using: /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz

 *** Latest firmware revision: 055e044d5359ded1aacc5a17a8e35365373d0b8b

 *** Linux source commit: 0afb5e98488aed7017b9bf321b575d0177feb7ed

 *** Download kernel source: Already downloaded /home/pi/linux-0afb5e98488aed7017b9bf321b575d0177feb7ed.tar.gz

 *** Unpack kernel source
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
 *** Add '+' to kernel release string

 *** Create symlink: /home/pi/linux

 *** Create /lib/modules/<ver>/{build,source} symlinks

 *** .config

 *** Module.symvers

 *** make modules_prepare
  SYNC    include/config/auto.conf.cmd
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/confdata.o
  HOSTCC  scripts/kconfig/expr.o
  LEX     scripts/kconfig/lexer.lex.c
  YACC    scripts/kconfig/parser.tab.[ch]
  HOSTCC  scripts/kconfig/lexer.lex.o
  HOSTCC  scripts/kconfig/menu.o
  HOSTCC  scripts/kconfig/parser.tab.o
  HOSTCC  scripts/kconfig/preprocess.o
  HOSTCC  scripts/kconfig/symbol.o
  HOSTCC  scripts/kconfig/util.o
  HOSTLD  scripts/kconfig/conf
  HOSTCC  scripts/dtc/dtc.o
  HOSTCC  scripts/dtc/flattree.o
  HOSTCC  scripts/dtc/fstree.o
  HOSTCC  scripts/dtc/data.o
  HOSTCC  scripts/dtc/livetree.o
  HOSTCC  scripts/dtc/treesource.o
  HOSTCC  scripts/dtc/srcpos.o
  HOSTCC  scripts/dtc/checks.o
  HOSTCC  scripts/dtc/util.o
  LEX     scripts/dtc/dtc-lexer.lex.c
  YACC    scripts/dtc/dtc-parser.tab.[ch]
  HOSTCC  scripts/dtc/dtc-lexer.lex.o
  HOSTCC  scripts/dtc/dtc-parser.tab.o
  HOSTLD  scripts/dtc/dtc
  HOSTCC  scripts/dtc/libfdt/fdt.o
  HOSTCC  scripts/dtc/libfdt/fdt_ro.o
  HOSTCC  scripts/dtc/libfdt/fdt_wip.o
  HOSTCC  scripts/dtc/libfdt/fdt_sw.o
  HOSTCC  scripts/dtc/libfdt/fdt_rw.o
  HOSTCC  scripts/dtc/libfdt/fdt_strerror.o
  HOSTCC  scripts/dtc/libfdt/fdt_empty_tree.o
  HOSTCC  scripts/dtc/libfdt/fdt_addresses.o
  HOSTCC  scripts/dtc/libfdt/fdt_overlay.o
  HOSTCC  scripts/dtc/fdtoverlay.o
  HOSTLD  scripts/dtc/fdtoverlay
  HOSTCC  scripts/genksyms/genksyms.o
  YACC    scripts/genksyms/parse.tab.[ch]
  HOSTCC  scripts/genksyms/parse.tab.o
  LEX     scripts/genksyms/lex.lex.c
  HOSTCC  scripts/genksyms/lex.lex.o
  HOSTLD  scripts/genksyms/genksyms
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/sorttable
  HOSTCC  scripts/asn1_compiler
  WRAP    arch/arm64/include/generated/uapi/asm/kvm_para.h
  WRAP    arch/arm64/include/generated/uapi/asm/errno.h
  WRAP    arch/arm64/include/generated/uapi/asm/ioctl.h
  WRAP    arch/arm64/include/generated/uapi/asm/ioctls.h
  WRAP    arch/arm64/include/generated/uapi/asm/ipcbuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/msgbuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/poll.h
  WRAP    arch/arm64/include/generated/uapi/asm/resource.h
  WRAP    arch/arm64/include/generated/uapi/asm/sembuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/shmbuf.h
  WRAP    arch/arm64/include/generated/uapi/asm/siginfo.h
  WRAP    arch/arm64/include/generated/uapi/asm/socket.h
  WRAP    arch/arm64/include/generated/uapi/asm/sockios.h
  WRAP    arch/arm64/include/generated/uapi/asm/stat.h
  WRAP    arch/arm64/include/generated/uapi/asm/swab.h
  WRAP    arch/arm64/include/generated/uapi/asm/termbits.h
  WRAP    arch/arm64/include/generated/uapi/asm/termios.h
  WRAP    arch/arm64/include/generated/uapi/asm/types.h
  WRAP    arch/arm64/include/generated/asm/early_ioremap.h
  WRAP    arch/arm64/include/generated/asm/mcs_spinlock.h
  WRAP    arch/arm64/include/generated/asm/qrwlock.h
  WRAP    arch/arm64/include/generated/asm/qspinlock.h
  WRAP    arch/arm64/include/generated/asm/parport.h
  WRAP    arch/arm64/include/generated/asm/user.h
  WRAP    arch/arm64/include/generated/asm/bugs.h
  WRAP    arch/arm64/include/generated/asm/delay.h
  WRAP    arch/arm64/include/generated/asm/div64.h
  WRAP    arch/arm64/include/generated/asm/dma-mapping.h
  WRAP    arch/arm64/include/generated/asm/dma.h
  WRAP    arch/arm64/include/generated/asm/emergency-restart.h
  WRAP    arch/arm64/include/generated/asm/hw_irq.h
  WRAP    arch/arm64/include/generated/asm/irq_regs.h
  WRAP    arch/arm64/include/generated/asm/kdebug.h
  WRAP    arch/arm64/include/generated/asm/kmap_size.h
  WRAP    arch/arm64/include/generated/asm/local.h
  WRAP    arch/arm64/include/generated/asm/local64.h
  WRAP    arch/arm64/include/generated/asm/mmiowb.h
  WRAP    arch/arm64/include/generated/asm/msi.h
  WRAP    arch/arm64/include/generated/asm/serial.h
  WRAP    arch/arm64/include/generated/asm/softirq_stack.h
  WRAP    arch/arm64/include/generated/asm/switch_to.h
  WRAP    arch/arm64/include/generated/asm/trace_clock.h
  WRAP    arch/arm64/include/generated/asm/unaligned.h
  WRAP    arch/arm64/include/generated/asm/vga.h
  UPD     include/config/kernel.release
  UPD     include/generated/uapi/linux/version.h
  UPD     include/generated/utsrelease.h
  UPD     include/generated/compile.h
  GEN     arch/arm64/include/generated/asm/cpucaps.h
  GEN     arch/arm64/include/generated/asm/sysreg-defs.h
warning: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum
warning: LSE atomics not supported by binutils
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/modpost.o
  CC      scripts/mod/devicetable-offsets.s
  UPD     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTLD  scripts/mod/modpost
  UPD     include/generated/timeconst.h
  CC      kernel/bounds.s
In file included from ./arch/arm64/include/asm/lse.h:5,
                 from ./arch/arm64/include/asm/cmpxchg.h:14,
                 from ./arch/arm64/include/asm/atomic.h:16,
                 from ./include/linux/atomic.h:7,
                 from ./include/asm-generic/bitops/atomic.h:5,
                 from ./arch/arm64/include/asm/bitops.h:25,
                 from ./include/linux/bitops.h:68,
                 from ./include/linux/log2.h:12,
                 from kernel/bounds.c:13:
./arch/arm64/include/asm/atomic_ll_sc.h: In function '__ll_sc__cmpxchg_double':
./arch/arm64/include/asm/atomic_ll_sc.h:318:38: error: '__uint128_t' undeclared (first use in this function); did you mean '__int128__'?
  318 |  : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr)  \
      |                                      ^~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:325:1: note: in expansion of macro '__CMPXCHG_DBL'
  325 | __CMPXCHG_DBL(   ,        ,  ,         )
      | ^~~~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:318:38: note: each undeclared identifier is reported only once for each function it appears in
  318 |  : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr)  \
      |                                      ^~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:325:1: note: in expansion of macro '__CMPXCHG_DBL'
  325 | __CMPXCHG_DBL(   ,        ,  ,         )
      | ^~~~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:318:51: error: expected expression before ')' token
  318 |  : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr)  \
      |                                                   ^
./arch/arm64/include/asm/atomic_ll_sc.h:325:1: note: in expansion of macro '__CMPXCHG_DBL'
  325 | __CMPXCHG_DBL(   ,        ,  ,         )
      | ^~~~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h: In function '__ll_sc__cmpxchg_double_mb':
./arch/arm64/include/asm/atomic_ll_sc.h:318:38: error: '__uint128_t' undeclared (first use in this function); did you mean '__int128__'?
  318 |  : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr)  \
      |                                      ^~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:326:1: note: in expansion of macro '__CMPXCHG_DBL'
  326 | __CMPXCHG_DBL(_mb, dmb ish, l, "memory")
      | ^~~~~~~~~~~~~
./arch/arm64/include/asm/atomic_ll_sc.h:318:51: error: expected expression before ')' token
  318 |  : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr)  \
      |                                                   ^
./arch/arm64/include/asm/atomic_ll_sc.h:326:1: note: in expansion of macro '__CMPXCHG_DBL'
  326 | __CMPXCHG_DBL(_mb, dmb ish, l, "memory")
      | ^~~~~~~~~~~~~
make[1]: *** [scripts/Makefile.build:118: kernel/bounds.s] Error 1
make: *** [Makefile:1289: prepare0] Error 2
Traceback (most recent call last):
  File "/usr/local/bin/rpi-source", line 421, in <module>
    sh("cd %s && make modules_prepare %s" % (linux_symlink, (" > /dev/null" if args.quiet else "")))
  File "/usr/local/bin/rpi-source", line 93, in sh
    subprocess.check_call(cmd, shell=True)
  File "/usr/lib/python2.7/subprocess.py", line 190, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'cd /home/pi/linux && make modules_prepare ' returned non-zero exit status 2
pelwell commented 1 year ago

Sorry - I paused writing my instructions to check the compiler string then didn't complete it. I should have said:

export CROSS_COMPILE=aarch64-linux-gnu-
chinmaydashp commented 1 year ago

Thanks a lot for your support, rpi-source compiled after adding the patch. However, the modules are not compatible with the kernel version I am currently running. I am adding the command and error message load the modules and instantiate the driver for your reference:

pi@raspberrypi:~/drivers $ sudo insmod crc8/crc8.ko
insmod: ERROR: could not insert module crc8/crc8.ko: Invalid module format

pi@raspberrypi:~/drivers $ sudo insmod sfxx/sfxx.ko
insmod: ERROR: could not insert module sfxx/sfxx.ko: Invalid module format
anakin4747 commented 1 year ago

I ran into the same errors, to finally solve it i ended up changing the OS to a headless 64bit instead of a headless 32bit RPi OS. When I did that I didn't need to run rpi-source as the build folder came included when I ran "sudo apt install raspberrypi-kernel-headers".

@chinmaydashp, I hope this helps your "Invalid module format" problem!