I want to port NuttX to BK-AVR128 powered by Atmega128AU chip, so I used the amber board as starting point just modifying the amber/include/board.h clock frequency to 8MHz.

First I installed the GCC toolchain:

$ sudo apt install gcc-avr

Then I configure to use the amber board with hello example:

$ ./tools/configure.sh amber:hello

But when I tried to compile it reported an error:

$ make
Create version.h
LN: platform/board to /home/alan/nuttxspace/apps/platform/dummy
Register: hello
./chip/atmega_lowconsole.c:33:20: fatal error: avr/io.h: No such file or directory
compilation terminated.
ERROR: avr-gcc failed: 1
command: avr-gcc -MT ./atmega_lowconsole.o -M '-fno-common' '-Wall' '-Wstrict-prototypes' '-Wshadow' '-Wundef' '-Wno-attributes' '-Wno-unknown-pragmas' '-O2' '-fno-strict-aliasing' '-fomit-frame-pointer' '-mmcu=atmega128' '-isystem' '/home/alan/nuttxspace/nuttx/include' '-D__NuttX__' '-DNDEBUG' '-D__KERNEL__' '-pipe' '-I' '/home/alan/nuttxspace/nuttx/arch/avr/src/chip' '-I' '/home/alan/nuttxspace/nuttx/arch/avr/src/common' '-I' '/home/alan/nuttxspace/nuttx/arch/avr/src/avr' '-I' '/home/alan/nuttxspace/nuttx/sched' ./chip/atmega_lowconsole.c
make[2]: *** [/home/alan/nuttxspace/nuttx/tools/Config.mk:230: atmega_lowconsole.ddc] Error 1
make[1]: *** [Makefile:122: .depend] Error 2
make: *** [tools/Unix.mk:619: pass2dep] Error 2

So I searched for this missing file:

$ apt-file search "avr/io.h"
avr-libc: /usr/lib/avr/include/avr/io.h

And realized that I didn’t install the avr-libc, it was easy to fix:

$ sudo apt install gcc-avr

Finally make worked fine:

CC:  avr/avr_usestack.c In file included from avr/avr_usestack.c:36:0:
/home/alan/nuttxspace/nuttx/include/nuttx/tls.h:51:4: warning: #warning CONFIG_TLS_NELEM is not defined [-Wcpp]
# warning CONFIG_TLS_NELEM is not defined
^
LD: nuttx
CP: nuttx.hex

Now I just need to flash the firmware:

$ avrdude -c usbasp -p atmega128 -U flash:w:nuttx.hex

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9702 (probably m128)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "nuttx.hex"
avrdude: input file nuttx.hex auto detected as Intel Hex
avrdude: writing flash (44734 bytes):

Writing | ################################################## | 100% 31.07s

avrdude: 44734 bytes of flash written
avrdude: verifying flash memory against nuttx.hex:
avrdude: load data flash data from input file nuttx.hex:
avrdude: input file nuttx.hex auto detected as Intel Hex
avrdude: input file nuttx.hex contains 44734 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 21.69s

avrdude: verifying ...
avrdude: 44734 bytes of flash verified

avrdude: safemode: Fuses OK (E:FF, H:19, L:FF)

avrdude done. Thank you.