Problems getting started reflashing model 01 on Arch Linux

Hello! My model 01 arrived yesterday, and being a dvorak user and already having some preferences on what goes where on thumb keys I decided to dive right in to reflashing the keyboard with a better layout for me. I’ll go through my steps following the guides on the wiki for posterity & information, and end with where I hit my snag. I didn’t dig too deep yet, but whatever problem I’m having should (is?) probably commented somewhere.

Following https://github.com/keyboardio/Kaleidoscope/wiki/Install-arduino-support-on-linux :

Arduino 1:1.8.5-1 was already installed on my system, which should be up to date enough according to the guide.

As the article hesitantly says, I don’t have the dialout group, but I do have the uucp group (which I’m already a part of).

Arduino was not installed in /usr/local/bin/arduino , but in /usr/bin/arduino. I therefore had to set the $ARDUINO_PATH flag

$ echo 'export ARDUINO_PATH=/usr/bin/' >> ~/.bashrc
$ source ~/.bashrc
$ echo $ARDUINO_PATH
/usr/bin/

Now following https://github.com/keyboardio/Model01-Firmware/blob/master/README.md

mkdir and git cloning worked as expected.

this is where I hit a snag though

$ make flash
ls: cannot access '/home/hatten/.arduino15/packages/keyboardio/hardware/avr/*': No such file or directory
BOARD_HARDWARE_PATH="/home/hatten/Arduino/hardware" /home/hatten/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/bin//kaleidoscope-builder flash
Building output/Model01-Firmware/Model01-Firmware (0.0.0-gv1.13-55-g8ab1) ...
stat /usr/bin/hardware: no such file or directory
make: *** [/home/hatten/Arduino/hardware/keyboardio/avr/build-tools/makefiles//rules.mk:75: flash] Error 1

Some tentative poking around that might help:

$ ls ~/.arduino15
staging  library_index.json  package_index.json  package_index.json.sig  preferences.txt

$ which hardware
which: no hardware in (<long list of custom stuff as well as default system paths>)

$ find / -name hardware 2>/dev/null
/home/hatten/Code/AndroidStudioProjects/MyApplication/app/build/tmp/expandedArchives/classes.jar_a0efcwrns6wtef8zezsroqw5l/android/support/v4/hardware
/home/hatten/Arduino/hardware
/usr/lib/modules/4.13.5-1-ARCH/kernel/drivers/isdn/hardware
/usr/share/arduino/hardware
/opt/android-sdk/sources/android-25/com/android/internal/hardware
/opt/android-sdk/sources/android-25/android/support/v4/hardware
/opt/android-sdk/sources/android-25/android/hardware

My hunch is that the initial ls is for finding previous builds, and not findinig anything isn’t an error? If so, should probably write a more descriptive warning/info message instead of a scary ls error message.
I have no clue what hardware you’re trying to find in /usr/bin. I could go digging in the source to see what it might be, but it’s easier to ask for help (and will make the question show up for others) :smile:

Thanks,
h

1 Like

Hi,

Change the ARDUINO_PATH to point to /usr/share/arduino; that is the correct setting for Manjaro,I expect it to be the same for their base-distro.

kind regards,
Tom

$ echo $ARDUINO_PATH
/usr/share/arduino

$ make flash
ls: cannot access '/home/hatten/.arduino15/packages/keyboardio/hardware/avr/*': No such file or directory
BOARD_HARDWARE_PATH="/home/hatten/Arduino/hardware" /home/hatten/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/bin//kaleidoscope-builder flash
Building output/Model01-Firmware/Model01-Firmware (0.0.0-gv1.13-55-g8ab1) ...
open /usr/share/arduino/hardware/tools: no such file or directory
make: *** [/home/hatten/Arduino/hardware/keyboardio/avr/build-tools/makefiles//rules.mk:75: flash] Error 1

$ l /usr/share/arduino/hardware/
archlinux-arduino  platform.keys.rewrite.txt  platform.txt

I certainly get a different error. Not sure if better.

Thanks,
h

hmm /usr/share/arduino/hardware/tools/ should exist I believe, it does on my system, it belongs to arduino-git installed from AUR.

Nota Bene: I get the ls: cannot access... error as well, but just ignored it – building and flashing works just fine.

Arch is a bit… weird, in that it has /usr/share/arduino/hardware/archlinux-arduino instead of /usr/share/arduino/hardware/arduino. They do this because they use their own avr-gcc, and not the one shipped with Arduino. There are two ways to get around this issue:

  1. Install stock Arduino somewhere, and use that.
  2. Create an /usr/share/arduino/hardware/arduino symlink pointing to archlinux-arduino, and use something like the following command:
make ARDUINO_BUILDER_PATH="/usr/bin/arduino-builder" \
     ARDUINO_PATH="/usr/share/arduino" \
     ARDUINO_LOCAL_LIB_PATH="../arduino-local" \
     AVR_GCC_PREFIX="/usr" \
     ARDUINO_TOOLS_PATH="" \
     AVR_SIZE_PATH="avr-size"

I’m not sure if the ARDUINO_LOCAL_LIB_PATH is required… if I remember correctly, that should point to a path where the hardware/keyboardio/avr stuff is (the parent of that path).

Hope this helps.

2 Likes

Huh, interesting. Although not the first time Arch decides to do something spicy…

$ sudo ln -s /usr/share/arduino/hardware/archlinux-arduino /usr/share/arduino/hardware/arduino

make ARDUINO_BUILDER_PATH="/usr/bin/arduino-builder" \

 ARDUINO_PATH="/usr/share/arduino" \
 ARDUINO_LOCAL_LIB_PATH="../arduino-local" \
 AVR_GCC_PREFIX="/usr" \
 ARDUINO_TOOLS_PATH="" \
 AVR_SIZE_PATH="avr-size"

ls: cannot access ‘/home/hatten/.arduino15/packages/keyboardio/hardware/avr/*’: No such file or directory
BOARD_HARDWARE_PATH="/home/hatten/Arduino/hardware" /home/hatten/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/bin//kaleidoscope-builder build-all
Building output/Model01-Firmware/Model01-Firmware (0.0.0-gv1.13-55-g8ab1) …
open /usr/share/arduino/hardware/tools: no such file or directory
make: *** [/home/hatten/Arduino/hardware/keyboardio/avr/build-tools/makefiles//rules.mk:75: build-all] Error 1

Didn’t help much (did I do it wrong?). I changed ARDUINO_TOOLS_PATH and got further, but it doesn’t seem to respect AVR_SIZE_PATH.

$ find /usr/share/arduino/ -name tools
/usr/share/arduino/tools

$ make ARDUINO_BUILDER_PATH="/usr/bin/arduino-builder" \
ARDUINO_PATH="/usr/share/arduino"\
ARDUINO_LOCAL_LIB_PATH="../arduino-local" \
AVR_GCC_PREFIX="/usr" \
ARDUINO_TOOLS_PATH="/usr/share/arduino/tools" \
AVR_SIZE_PATH="avr-size"
ls: cannot access '/home/hatten/.arduino15/packages/keyboardio/hardware/avr/*': No such file or directory
BOARD_HARDWARE_PATH="/home/hatten/Arduino/hardware" /home/hatten/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/bin//kaleidoscope-builder build-all
Building output/Model01-Firmware/Model01-Firmware (0.0.0-gv1.13-55-g8ab1) ...
/home/hatten/Arduino/hardware/keyboardio/avr/libraries/KeyboardioScanner/twi.c: In function '__vector_36':
/home/hatten/Arduino/hardware/keyboardio/avr/libraries/KeyboardioScanner/twi.c:446:47: warning: this statement may fall through [-Wimplicit-fallthrough=]
     twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
                                               ^
/home/hatten/Arduino/hardware/keyboardio/avr/libraries/KeyboardioScanner/twi.c:447:3: note: here
   case TW_MR_SLA_ACK:  // address sent, ack received
   ^~~~
- Size: firmware/Model01-Firmware/Model01-Firmware-0.0.0-gv1.13-55-g8ab1.elf
/home/hatten/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/bin//kaleidoscope-builder: line 15: /usr/share/arduino/tools/avr/bin/avr-size: No such file or directory
awk: cmd. line:1: (FILENAME=- FNR=1) fatal: division by zero attempted
make: *** [/home/hatten/Arduino/hardware/keyboardio/avr/build-tools/makefiles//rules.mk:75: build-all] Error 2

$ which avr-size
/usr/bin/avr-size

setting AVR_SIZE_PATH to /usr/bin/avr-size gives the same error.

Thanks,
h

Huh, interesting. Can you try adding VERBOSE=1 to the command-line? That should get rid of the post-processing that appears to fail.

If that doesn’t fix it, if you could add a set -x to the top of /home/hatten/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/bin//kaleidoscope-builder, and send me the output, that would be a huge help in tracking down where the issue lies.

argh. Not allowed to upload txt’s. Found some random site

VERBOSE=1
http://m.uploadedit.com/bbtc/1508583723746.txt

VERBOSE=1 and set -x
http://m.uploadedit.com/bbtc/1508583795697.txt

Just been trying to do the same thing. First, I’ve installed everything Arduino I could find (except arduino-docs):

pacman -S arduino arduino-builder arduino-avr-core arduino-ctags

After that I encountered the same problem with the paths, but my solution was slightly different:

ln -s /usr/share/arduino/hardware/archlinux-arduino /usr/share/arduino/hardware/tools

Then I got:

$ export ARDUINO_PATH=/usr/share/arduino
$ make flash
BOARD_HARDWARE_PATH="/home/test/Arduino/hardware" /home/test/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/bin//kaleidoscope-builder flash
Building output/Model01-Firmware/Model01-Firmware (0.0.0-gv1.13-57-ge6f5-dirty) …
Selected board depends on ‘arduino’ core (not installed).
make: *** [/home/test/Arduino/hardware/keyboardio/avr/build-tools/makefiles//rules.mk:75: flash] Error 1

After that I’ve found this thread here and tried the other symlink as well. I’ve kept mine, so my system looks like this now:

ls -FAhl /usr/share/arduino/hardware
total 20K
drwxr-xr-x 1 root root 40 22. Okt 16:59 archlinux-arduino/
lrwxrwxrwx 1 root root 45 22. Okt 17:06 arduino -> /usr/share/arduino/hardware/archlinux-arduino/
-rw-r–r-- 1 root root 7,1K 20. Mär 2017 platform.keys.rewrite.txt
-rw-r–r-- 1 root root 926 20. Mär 2017 platform.txt
lrwxrwxrwx 1 root root 45 22. Okt 16:59 tools -> /usr/share/arduino/hardware/archlinux-arduino/

But still no luck:

$ make flash
ls: cannot access ‘/home/test/.arduino15/packages/keyboardio/hardware/avr/*’: No such file or directory
BOARD_HARDWARE_PATH="/home/test/Arduino/hardware" /home/test/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/bin//kaleidoscope-builder flash
Building output/Model01-Firmware/Model01-Firmware (0.0.0-gv1.13-57-ge6f5-dirty) …
fork/exec {runtime.tools.avr-gcc.path}/bin/avr-g++: no such file or directory
make: *** [/home/test/Arduino/hardware/keyboardio/avr/build-tools/makefiles//rules.mk:75: flash] Error 1

So I tried the extended make invocation suggested above:

$ make ARDUINO_BUILDER_PATH="/usr/bin/arduino-builder"
ARDUINO_PATH="/usr/share/arduino"
ARDUINO_LOCAL_LIB_PATH="…/arduino-local"
AVR_GCC_PREFIX="/usr"
ARDUINO_TOOLS_PATH=""
AVR_SIZE_PATH=“avr-size” flash
ls: cannot access ‘/home/test/.arduino15/packages/keyboardio/hardware/avr/*’: No such file or directory
BOARD_HARDWARE_PATH="/home/test/Arduino/hardware" /home/test/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/bin//kaleidoscope-builder flash
Building output/Model01-Firmware/Model01-Firmware (0.0.0-gv1.13-57-ge6f5-dirty) …
/home/test/Arduino/hardware/keyboardio/avr/libraries/KeyboardioScanner/twi.c: In function ‘__vector_36’:
/home/test/Arduino/hardware/keyboardio/avr/libraries/KeyboardioScanner/twi.c:446:47: warning: this statement may fall through [-Wimplicit-fallthrough=]
twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
^
/home/test/Arduino/hardware/keyboardio/avr/libraries/KeyboardioScanner/twi.c:447:3: note: here
case TW_MR_SLA_ACK: // address sent, ack received
^~~~
Press ENTER when ready…
stty: invalid argument ‘/dev/ttyACM1’
Try ‘stty --help’ for more information.
make: *** [/home/test/Arduino/hardware/keyboardio/avr/build-tools/makefiles//rules.mk:75: flash] Error 1

That’s a success, although it doesn’t look like it. The build environment works in general, the missing device node is a different problem. (Other hardware was assigned ttyACM1, my Model01 got ttyACM3. Gonna figure out how to point the arduino tools to that device node after diner.)

We’ve just been discussing this on #keyboardio on Freenode.

The issue is our hopelessly naive code that goes looking for device ports. (While you may see @algernon’s name in the git blame, it’s because he moved my horrible hack from elsewhere.)

https://github.com/keyboardio/Kaleidoscope/blob/master/etc/kaleidoscope-builder.conf#L42

and

https://github.com/keyboardio/Kaleidoscope/blob/master/etc/kaleidoscope-builder.conf#L66

are where the bad code is.

It looks like right now our load-order for local customizations of the builder config have the system config being loaded last, so you wouldn’t even be able to properly override them, at least not yet. I’m so sorry this isn’t easy yet. But it’s now high on our list to rework.

I’ve just been testing exactly that, overwriting the default:

make ARDUINO_BUILDER_PATH="/usr/bin/arduino-builder" ARDUINO_PATH="/usr/share/arduino" ARDUINO_LOCAL_LIB_PATH="…/arduino-local" AVR_GCC_PREFIX="/usr" ARDUINO_TOOLS_PATH="" AVR_SIZE_PATH=“avr-size” MONITOR_PORT="/dev/ttyACM3" flash

I’ve also (incrementally) tried a few other ways of pointing “make” into the right direction. This is my latest attempt:

make … ARDUINO_PORT="/dev/ttyACM3" MONITOR_PORT="/dev/ttyACM3" FORCE_MONITOR_PORT=true DEVICE_PATH="/dev/ttyACM3" flash

That code snippet explains why it didn’t work. I was searching the source for the line that defines ttyACM1, but hadn’t found it yet. Thanks very much.

Maybe you could do something like they do here:

Autodetection of the right port would of course be great, but in the meantime I’d settle for pointing make the right way via MONITOR_PORT or something similar.

There’s an additional wrinkle when you’re trying to flash a device – you need two different ports. The first is the port of the running device, so you can trigger the reboot into a bootloader. The second is the port that shows up when you’re in the bootloader. These are often, but not always the same.

We’ve got a couple ways we’re looking at fixing this, but it looks like doing the autodetection is unlikely to be dramatically more work than untangling the current code to make it easy to override.

I hadn’t gotten around to that wrinkle yet, thanks for the heads up.

I’ve noticed that the udev rules to avoid ModemManager’s interference (that many Linux users probably will need anyway) already creates a unique symlink for the Model01:

$ ls -l /dev/model01
lrwxrwxrwx 1 root root 12 Okt 22 21:47 /dev/model01 -> input/event6

Maybe this could be used to set DEVICE_PATH? Unless the bootloader shows up with a different idVendor or idProduct, that symlink should be pretty reliable.

FWIW, there’s a very nice solution that avoids all these issues: detecting the device by vendor id & product id. The downside is, that this needs a bit of compiled code.

My current plan is to create a flasher application in node + Electron, package it for all platforms, and cross fingers. I’ve had great success with avrgirl before (it can detect both the running device, and the programmable mode too), so here’s hoping that this would fix our flashing issues once and for all, at the cost of some Electron bloat. (The same feature will be implemented in Chrysalis too - it actually already is implemented there.)

Worst case, I wasted an hour or so. Best? Flashing ~solved cross platform.

2 Likes

That is indeed part of the plan for Linux. (We have two different Device Ids. One for the bootloader and one for the running firmware, but both are known in advance.)

We do need a similar plan for OSX.

Hence the two udev rules, I was wondering…

Jolly good. I’ll just wait for the improvements, since Arch is my secondary system anyway. I can flash my Model01 under Ubuntu, so I’m good for now.

1 Like

As an Arch user who is affected by this but has zero Arduino experience I was wondering if this issue could be circumvented by running from a Virtualbox Ubuntu guest? Is it too fiddly to enable flashing from the guest operating system?

@algernon’s suggestion to just use stock Arduino worked. I followed the instructions on the wiki to install Arduino manually on Linux with the Arch-specific part and it flashes without problems. I added a small fix to that wiki page though, an argument was missing from the Arch command.

1 Like

After following along with the tips shared in this thread, I ran into the following error with Arch packaged version of Arduino IDE (1:1.8.5-1):

Found upload port: /dev/ttyACM0
___REMOVE___/bin/avrdude -C___REMOVE___/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:/tmp/arduino_build_609953/Model01-Firmware.ino.hex:i 
java.io.IOException: Cannot run program "___REMOVE___/bin/avrdude": error=2, No such file or directory
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
	at java.lang.Runtime.exec(Runtime.java:620)
	at java.lang.Runtime.exec(Runtime.java:485)
	at processing.app.helpers.ProcessUtils.exec(ProcessUtils.java:11)
	at cc.arduino.packages.Uploader.executeUploadCommand(Uploader.java:129)
	at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:207)
	at cc.arduino.UploaderUtils.upload(UploaderUtils.java:78)
	at processing.app.SketchController.upload(SketchController.java:713)
	at processing.app.SketchController.exportApplet(SketchController.java:686)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2168)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: error=2, No such file or directory
	at java.lang.UNIXProcess.forkAndExec(Native Method)
	at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
	at java.lang.ProcessImpl.start(ProcessImpl.java:134)
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
	... 10 more
An error occurred while uploading the sketch

I was able to work around this issue by downgraded Arduino AVR board to 1.6.19 (from 1.6.20) within Arduino IDE -> Tools -> Board -> Board Manager… -> search for ‘avr board’ -> click on Arduino AVR board -> use drop down to select 1.6.19 -> Install. I am not sure why the error was occurring or why downgrading fixed this issue. I just wanted to share the work around if others ran into this issue.

2 Likes

OK, so here’s a summary of how I was able to successfully get things working on Arch Linux:

pacaur -S arduino arduino-builder arduino-avr-core arduino-ctags avrdude
sudo usermod -a -G uucp $USER
# re-login
sudo ln -s /usr/share/arduino /usr/local/arduino
cd /usr/share/arduino/hardware
sudo ln -s archlinux-arduino arduino
sudo ln -s archlinux-arduino tools
sudo mkdir -p /usr/share/arduino/tools/avr/bin
sudo ln -s /usr/bin/avrdude /usr/share/arduino/tools/avr/bin/
sudo mkdir -p /usr/share/arduino/tools/avr/etc
sudo ln -s /usr/share/arduino/hardware/archlinux-arduino/avr/bootloaders/gemma/avrdude.conf /usr/share/arduino/tools/avr/etc/

I made a custom make.sh just to make life a bit easier in the Model01-Firmware that just packages the recommendations made together (I use fish so that just makes life easier)

#!/bin/bash

make ARDUINO_BUILDER_PATH="/usr/bin/arduino-builder" \
     ARDUINO_PATH="/usr/share/arduino" \
     ARDUINO_LOCAL_LIB_PATH="../arduino-local" \
     AVR_GCC_PREFIX="/usr" \
     ARDUINO_TOOLS_PATH="/usr/share/arduino/tools" \
     AVR_SIZE_PATH="avr-size" \
flash

Here’s my results (hitting PROG-ENTER)

lhl@ono4 ~/A/Model01-Firmware> ./make.sh
ls: cannot access '/home/lhl/.arduino15/packages/keyboardio/hardware/avr/*': No such file or directory
BOARD_HARDWARE_PATH="/home/lhl/Arduino/hardware" /home/lhl/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/bin//kaleidoscope-builder flash
Building output/Model01-Firmware/Model01-Firmware (0.0.0-gv1.13-57-ge6f5) ...
/home/lhl/Arduino/hardware/keyboardio/avr/libraries/KeyboardioScanner/twi.c: In function '__vector_36':
/home/lhl/Arduino/hardware/keyboardio/avr/libraries/KeyboardioScanner/twi.c:446:47: warning: this statement may fall through [-Wimplicit-fallthrough=]
     twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
                                               ^
/home/lhl/Arduino/hardware/keyboardio/avr/libraries/KeyboardioScanner/twi.c:447:3: note: here
   case TW_MR_SLA_ACK:  // address sent, ack received
   ^~~~
Press ENTER when ready...

Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
    Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x44

I get an error using the Arduino IDE (it complains about finding avr-g++) but I’ve confirmed that I can just edit the Model01-Firmware.ino file directly and the make fwill push the code over. Sweet.

You can check out my fork to see what changes I’ve made: https://github.com/lhl/Model01-Firmware/commits/master

5 Likes