Using default firmware.gen.script exits 255 (even though upload is successful)

nerves
ssh

#1

I was having issues using the mix firmware.push to send new fw to my device, so I followed the guide and ran mix firmware.gen.script and have be using the upload.sh it generated which has worked great. Firmware deploys great and all seemed well.

So, I started scripting this process and ended up getting warnings and failures in scripts. After investigating, it looks like the last line of generated upload.sh script returns 255, but technically it did what it was supposed to.

jonjon@ πŸ“‚ {grub} $ MIX_ENV=dev MIX_TARGET=rpi3 ./upload.sh
Uploading ./_build/rpi3/dev/nerves/images/grub.fw to grub-dev.local...
X11 forwarding request failed on channel 0
Running fwup...
fwup: Upgrading partition A
|====================================| 100% (30.31 / 30.31) MB
Success!
Elapsed time: 5.925 s
Rebooting...
jonjon@ πŸ“‚ {grub} $ echo $?
255

ssh man pages state that it will exit with remote command status or 255 on an error. In this case, I believe the remote exits -1 and shell transposes to 255 which is the code to use with an β€œout of range” status (which are expected to be 0-255)

Anyone know why it might be completing successfully but returning an error? I basically have no idea what to look for with ssh or nerves_firmware_ssh, so any help would be appreciated.

I’ll even supply some ssh -v output :wink:Β¬

jonjon@ πŸ“‚ {grub} $ MIX_ENV=dev MIX_TARGET=rpi3 ./upload.sh grub-dev.local
Uploading ./_build/rpi3/dev/nerves/images/grub.fw to grub-dev.local...
OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /Users/jonjon/.ssh/config
debug1: /Users/jonjon/.ssh/config line 5: Applying options for grub*.local
debug1: /Users/jonjon/.ssh/config line 57: Applying options for *.local
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: /etc/ssh/ssh_config line 52: Applying options for *
debug1: Connecting to grub-dev.local port 8989.
debug1: Connection established.
debug1: identity file /Users/jonjon/.ssh/mx type 0
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jonjon/.ssh/mx-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: Remote protocol version 2.0, remote software version aqxe
debug1: no match: aqxe
debug1: Authenticating to grub-dev.local:8989 as 'jonjon'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: ecdh-sha2-nistp256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:s6rDEVL9YH3LaEDRxRX4qStknwY3560Vs5wkQ4wQMmA
debug1: Host '[grub-dev.local]:8989' is known and matches the RSA host key.
debug1: Found key in /Users/jonjon/.ssh/known_hosts:694
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ecdsa-sha2-nistp256,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive,password
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:jNF/Vgr6H6cxSehszXW5cmb3TM6E3oZCNOxp4NklsoA /Users/jonjon/.ssh/mx
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentication succeeded (publickey).
Authenticated to grub-dev.local ([10.0.1.67]:8989).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: exec
debug1: Requesting X11 forwarding with authentication spoofing.
debug1: Requesting authentication agent forwarding.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending subsystem: nerves_firmware_ssh
X11 forwarding request failed on channel 0
Running fwup...
fwup: Upgrading partition B
|====================================| 100% (30.31 / 30.31) MB
Success!
Elapsed time: 5.869 s
Rebooting...
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
Transferred: sent 28187168, received 13960 bytes, in 6.4 seconds
Bytes per second: sent 4422327.5, received 2190.2
debug1: Exit status -1

#2

Good catch. I reproduced this. It turns out that nerves_firmware_ssh is missing a call to :ssh_connection.exit_status to send the return code. I’ll PR it tomorrow morning.

Thanks,
Frank


#3

Jon - Justin Schneck and I released nerves_firmware_ssh v0.3.3 that fixes the exit code issue and a includes a couple minor changes since the previous release. (Details on the Github project) Thanks again for letting me know about it.