© 2018 by Zack Smith. All rights reserved.
Why build the AVR toolchain at all?
You've just bought a mechanical keyboard that has an
Atmel AVR microcontroller in it but you hate the layout and/or you want to reflash it with
new and better
QMK firmware. But how?
- You could download a precompiled AVR toolchain.
- You could build it yourself.
The problem with downloading binaries is that there's always the risk they might contain malware.
You typically won't know who compiled it and what their motives were.
You may think you downloaded a compiler but actually it's a compiler+spyware.
Why update your keyboard firmware?
There are four possible gains:
- Programming a better layout e.g. swapping Alt and Windows keys to be like a Mac keyboard.
- Achieving funkier LED light effects.
- Alleviating firmware bugs.
- Avoiding malware risks.
A malicious USB device can do more mischief than you'd expect.
- It can change its USB device type to network, which your computer will automatically connect to. It can then receive and send a copy of all your network traffic to a faraway server.
- It can serve as a key logger, storing your usernames and passwords and eventually uploading those to someone's server.
- It can potentially attack other USB devices, overwriting their firmware with malicious code.
After much honing and fixing, I got the AVR toolchain to compile on MacOS 10.14 Mojave.
The following script should just work:
curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.31.1.tar.bz2
curl -O https://bigsearcher.com/mirrors/gcc/releases/gcc-8.2.0/gcc-8.2.0.tar.xz
curl -O http://nongnu.askapache.com/avr-libc/avr-libc-2.0.0.tar.bz2
echo === MAKE BINUTILS
tar xfv binutils-2.31.1.tar.*
../configure --prefix=$PREFIX --target=avr --disable-nls --program-prefix="avr-"
sudo make install
echo === MAKE GCC
tar xfv gcc-8.2.0.tar.*
chmod +x $REQ
../configure --prefix=$PREFIX --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --disable-libada --with-dwarf2 --disable-shared --enable-static --enable-mingw-wildcard --program-prefix="avr-"
sudo make install
echo === MAKE AVRLIB
tar xfv avr-libc-2.0.0.tar.*
../configure --prefix=$PREFIX --host=avr --build=`../config.guess`
sudo make install-strip
echo === DONE