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

Fix firmware size check with avr-libc 1:2.0.0+Atmel3.6.2-1.1 (Debian bullseye) #12951

Merged
merged 1 commit into from
Jun 7, 2021

Conversation

sigprof
Copy link
Contributor

@sigprof sigprof commented May 19, 2021

Description

Debian bullseye (testing at the moment, but seems close to release) has avr-libc 1:2.0.0+Atmel3.6.2-1.1 with some changes taken from the Atmel-distributed toolchain. In particular, the <avr/io.h> header for ATmega32A (avr/iom32a.h) now defines the FLASHEND constant as 0x7FFFU, and that U suffix breaks the firmware size check code, because the shell arithmetic expansion that is used to calculate MAX_SIZE does not support those C-specific suffixes.

As a workaround, add -D__ASSEMBLER__ to the C preprocessor invocation that is used to expand those macros; in this case avr/iom32a.h defines FLASHEND without the U suffix, and everything works as it did before with older avr-libc versions.

The exact same code is present in two places; they are both changed, even though the code in tmk_core/avr.mk is actually never used for ATmega32A (and the header for ATmega32U4 does not add that U suffix to FLASHEND for some reason).


The problematic code in new avr/iom32a.h:

#if (defined(__ASSEMBLER__) || defined(__IAR_SYSTEMS_ASM__))
#  define SPM_PAGESIZE 128
#  define FLASHSTART   0x0000
#  define FLASHEND     0x7FFF
#else
#  define SPM_PAGESIZE 128U
#  define FLASHSTART   0x0000U
#  define FLASHEND     0x7FFFU
#endif

For some reason the ATmega32U4 header does not have a similar change, therefore only boards using ATmega32A are affected. The build error for jj40:default looks like this:

Linking: .build/jj40_default.elf                                                                    [OK]
Creating load file for flashing: .build/jj40_default.hex                                            [OK]
Copying jj40_default.hex to qmk_firmware folder                                                     [OK]
sh: 1: arithmetic expression: expecting EOF: "
         0x7FFFU
                  + 1 - 4096"
expr: syntax error: unexpected argument ‘20220’
expr: syntax error: missing argument after ‘-’
expr: syntax error: missing argument after ‘/’
sh: 1: [: -gt: unexpected operator

Lots of other MCUs are affected, but the only one that has been used with QMK is apparently ATmega32A:

❯ grep -r 'FLASHEND.*U' .
./avr/io90pwm161.h:#  define FLASHEND     0x3FFFU
./avr/ioa5272.h:#  define FLASHEND     0x1FFFU
./avr/ioa5505.h:#  define FLASHEND     0x3FFFU
./avr/ioa5702m322.h:#  define FLASHEND     0xFFFFU
./avr/ioa5782.h:#  define FLASHEND     0xCFFFU
./avr/ioa5790.h:#  define FLASHEND     0x3FFFU
./avr/ioa5790n.h:#  define FLASHEND     0x3FFFU
./avr/ioa5791.h:#  define FLASHEND     0x3FFFU
./avr/ioa5795.h:#  define FLASHEND     0x1FFFU
./avr/ioa5831.h:#  define FLASHEND     0xCFFFU
./avr/ioa6285.h:#  define FLASHEND     0x1FFFU
./avr/ioa6286.h:#  define FLASHEND     0x1FFFU
./avr/ioa6612c.h:#  define FLASHEND     0x1FFFU
./avr/ioa6613c.h:#  define FLASHEND     0x3FFFU
./avr/ioa6614q.h:#  define FLASHEND     0x7FFFU
./avr/ioa6616c.h:#  define FLASHEND     0x1FFFU
./avr/ioa6617c.h:#  define FLASHEND     0x3FFFU
./avr/ioa664251.h:#  define FLASHEND     0x3FFFU
./avr/ioa8210.h:#  define FLASHEND     0xCFFFU
./avr/ioa8510.h:#  define FLASHEND     0xCFFFU
./avr/iom1284.h:#  define FLASHEND     0x1FFFFU
./avr/iom1284rfr2.h:#  define FLASHEND     0x1FFFFU
./avr/iom128a.h:#  define FLASHEND     0x1FFFFU
./avr/iom128rfr2.h:#  define FLASHEND     0x1FFFFU
./avr/iom164pa.h:#  define FLASHEND     0x3FFFU
./avr/iom165pa.h:#  define FLASHEND     0x3FFFU
./avr/iom168pa.h:#  define FLASHEND     0x3FFFU
./avr/iom168pb.h:#  define FLASHEND     0x3FFFU
./avr/iom2564rfr2.h:#  define FLASHEND     0x3FFFFU
./avr/iom256rfr2.h:#  define FLASHEND     0x3FFFFU
./avr/iom324a.h:#  define FLASHEND     0x7FFFU
./avr/iom324p.h:#  define FLASHEND     0x7FFFU
./avr/iom3250pa.h:#  define FLASHEND     0x7FFFU
./avr/iom325pa.h:#  define FLASHEND     0x7FFFU
./avr/iom3290pa.h:#  define FLASHEND     0x7FFFU
./avr/iom329p.h:#  define FLASHEND     0x7FFFU
./avr/iom32a.h:#  define FLASHEND     0x7FFFU
./avr/iom48pa.h:#  define FLASHEND     0x0FFFU
./avr/iom48pb.h:#  define FLASHEND     0x0FFFU
./avr/iom644rfr2.h:#  define FLASHEND     0xFFFFU
./avr/iom64a.h:#  define FLASHEND     0xFFFFU
./avr/iom64hve2.h:#  define FLASHEND     0xFFFFU
./avr/iom64rfr2.h:#  define FLASHEND     0xFFFFU
./avr/iom88pb.h:#  define FLASHEND     0x1FFFU
./avr/iom8a.h:#  define FLASHEND     0x1FFFU
./avr/iotn1634.h:#  define FLASHEND     0x3FFFU
./avr/iotn441.h:#  define FLASHEND     0x0FFFU
./avr/iotn828.h:#  define FLASHEND     0x1FFFU
./avr/iotn841.h:#  define FLASHEND     0x1FFFU

Maybe bootloader_size.c should be changed to bootloader_size.S instead (and preprocessed using assembler options); I did not try that variant yet.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

…bullseye)

Debian bullseye (testing at the moment, but seems close to release) has
avr-libc 1:2.0.0+Atmel3.6.2-1.1 with some changes taken from the
Atmel-distributed toolchain.  In particular, the <avr/io.h> header for
ATmega32A (avr/iom32a.h) now defines the FLASHEND constant as `0x7FFFU`,
and that `U` suffix breaks the firmware size check code, because the
shell arithmetic expansion that is used to calculate `MAX_SIZE` does not
support those C-specific suffixes.

As a workaround, add `-D__ASSEMBLER__` to the C preprocessor invocation
that is used to expand those macros; in this case avr/iom32a.h defines
`FLASHEND` without the `U` suffix, and everything works as it did before
with older avr-libc versions.

The exact same code is present in two places; they are both changed,
even though the code in `tmk_core/avr.mk` is actually never used for
ATmega32A (and the header for ATmega32U4 does not add that `U` suffix to
`FLASHEND` for some reason).
@github-actions github-actions bot added the core label May 19, 2021
@drashna drashna requested a review from a team May 22, 2021 06:30
@drashna
Copy link
Member

drashna commented Jun 7, 2021

Thanks!

@drashna drashna merged commit 680cc1f into qmk:develop Jun 7, 2021
mechlovin pushed a commit to mechlovin/qmk_firmware that referenced this pull request Jul 30, 2021
…bullseye) (qmk#12951)

Debian bullseye (testing at the moment, but seems close to release) has
avr-libc 1:2.0.0+Atmel3.6.2-1.1 with some changes taken from the
Atmel-distributed toolchain.  In particular, the <avr/io.h> header for
ATmega32A (avr/iom32a.h) now defines the FLASHEND constant as `0x7FFFU`,
and that `U` suffix breaks the firmware size check code, because the
shell arithmetic expansion that is used to calculate `MAX_SIZE` does not
support those C-specific suffixes.

As a workaround, add `-D__ASSEMBLER__` to the C preprocessor invocation
that is used to expand those macros; in this case avr/iom32a.h defines
`FLASHEND` without the `U` suffix, and everything works as it did before
with older avr-libc versions.

The exact same code is present in two places; they are both changed,
even though the code in `tmk_core/avr.mk` is actually never used for
ATmega32A (and the header for ATmega32U4 does not add that `U` suffix to
`FLASHEND` for some reason).
mechlovin pushed a commit to mechlovin/qmk_firmware that referenced this pull request Jul 30, 2021
…bullseye) (qmk#12951)

Debian bullseye (testing at the moment, but seems close to release) has
avr-libc 1:2.0.0+Atmel3.6.2-1.1 with some changes taken from the
Atmel-distributed toolchain.  In particular, the <avr/io.h> header for
ATmega32A (avr/iom32a.h) now defines the FLASHEND constant as `0x7FFFU`,
and that `U` suffix breaks the firmware size check code, because the
shell arithmetic expansion that is used to calculate `MAX_SIZE` does not
support those C-specific suffixes.

As a workaround, add `-D__ASSEMBLER__` to the C preprocessor invocation
that is used to expand those macros; in this case avr/iom32a.h defines
`FLASHEND` without the `U` suffix, and everything works as it did before
with older avr-libc versions.

The exact same code is present in two places; they are both changed,
even though the code in `tmk_core/avr.mk` is actually never used for
ATmega32A (and the header for ATmega32U4 does not add that `U` suffix to
`FLASHEND` for some reason).
nhongooi pushed a commit to nhongooi/qmk_firmware that referenced this pull request Dec 5, 2021
…bullseye) (qmk#12951)

Debian bullseye (testing at the moment, but seems close to release) has
avr-libc 1:2.0.0+Atmel3.6.2-1.1 with some changes taken from the
Atmel-distributed toolchain.  In particular, the <avr/io.h> header for
ATmega32A (avr/iom32a.h) now defines the FLASHEND constant as `0x7FFFU`,
and that `U` suffix breaks the firmware size check code, because the
shell arithmetic expansion that is used to calculate `MAX_SIZE` does not
support those C-specific suffixes.

As a workaround, add `-D__ASSEMBLER__` to the C preprocessor invocation
that is used to expand those macros; in this case avr/iom32a.h defines
`FLASHEND` without the `U` suffix, and everything works as it did before
with older avr-libc versions.

The exact same code is present in two places; they are both changed,
even though the code in `tmk_core/avr.mk` is actually never used for
ATmega32A (and the header for ATmega32U4 does not add that `U` suffix to
`FLASHEND` for some reason).
@sigprof sigprof deleted the avr-check-size-fix branch July 21, 2022 19:26
BorisTestov pushed a commit to BorisTestov/qmk_firmware that referenced this pull request May 23, 2024
…bullseye) (qmk#12951)

Debian bullseye (testing at the moment, but seems close to release) has
avr-libc 1:2.0.0+Atmel3.6.2-1.1 with some changes taken from the
Atmel-distributed toolchain.  In particular, the <avr/io.h> header for
ATmega32A (avr/iom32a.h) now defines the FLASHEND constant as `0x7FFFU`,
and that `U` suffix breaks the firmware size check code, because the
shell arithmetic expansion that is used to calculate `MAX_SIZE` does not
support those C-specific suffixes.

As a workaround, add `-D__ASSEMBLER__` to the C preprocessor invocation
that is used to expand those macros; in this case avr/iom32a.h defines
`FLASHEND` without the `U` suffix, and everything works as it did before
with older avr-libc versions.

The exact same code is present in two places; they are both changed,
even though the code in `tmk_core/avr.mk` is actually never used for
ATmega32A (and the header for ATmega32U4 does not add that `U` suffix to
`FLASHEND` for some reason).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants