So there's the Arduino Yun. That's quite a nice concept - an embedded Linux computer (MIPS based, YAY!) and microcontroller combined on one board. Just such a shame it's an Atmel microcontroller and not a PIC32.
But then there is the Dragino Yun shield. Just the Linux portion on a shield that you can plug in to your favourite board and make a Frankensteinian monster. Perfect. Coupled with a nice meaty PIC32 it's the ideal combination. However, programming the PIC32 is then nigh on impossible, since the serial port gets blocked up. So you want to program it from the Yun shield if you can. But that means porting pic32prog to Linino, and that has proved to be a bit of a trial. More on that some other time though.
This is all about what happened whilst I have been attempting to do that porting.
I bricked the Dragino somehow.
Yep - won't boot. Kernel panic. I can only think that something I installed while trying to do the porting caused it to go haywire. My guess is "udev". Still, a replacement of the firmware should fix things. But then that's where things have kind of fallen apart.
The instructions on the Dragino website are out of date, and the Linux portion of those instructions are restricted to a single paragraph and a picture. Less than useful. So it was down to me to then work out how to do it for myself using the Windows instructions and my own superior brain power. (-- modest as usual :) )
So here we go. First you will need the right firmware files. I have the newest (at the time of writing this) 2.3 Dragino shield. There is no 2.3 version of the firmware. The newest I could find was 2.0.6, which seems to work fine. They are here. You will need the dragino2-yun-common-v2.0.6-kernel.bin and dragino2-yun-common-v2.0.6-rootfs-squashfs.bin files. Of course, if you have an older version of the Dragino you may have to hunt around for the right files for your board - the layout of their downloads section isn't that intuitive.
That's the easy part. Now for the "fixing" of the system.
First you need to get access to the "u-boot" console (or "dr boot" as it's called on the Dragino). For that you need an Ethernet (wired) network. Fortunately I already have one set up on my desk for just this kind of thing, but you may need to create one just for the occasion. That means running a cable from the Ethernet port on your computer to the RJ45 socket of the Dragino. You might even need to invest in a special "crossover" cable if a normal one doesn't work. The network has to be on a specific IP range for this to all work.
I created an alias to my ethernet port to allow me to use the special range at the same time as my default range. You can do the same even if it's an ad-hoc network:
$ sudo ifconfig eth0:1 inet 192.168.255.2/24
That should give you a new network device, which if you run "ifconfig" by itself you should see in the list:
eth0:1 Link encap:Ethernet HWaddr 00:25:64:b6:71:89 inet addr:192.168.255.2 Bcast:192.168.255.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:17
Now you need to set up the right tools for the job. I use Debian Jessie, but the same tools should be available on Ubuntu and other similar Linux environments.
The three programs you need are "nc" (NetCat"), "tftpd" (Trivial File Transfer Protocol Daemon) and "xinetd" (eXtended InterNET Daemon). You can install those on Debian with:
$ sudo apt-get install nc tftpd xinetd
Now to get them running. First the tftpd, which relies on xinetd. You need to create a file (as root) called "/etc/xinetd.d/tftp" and in it put:
# default: off # description: The tftp server serves files using the Trivial File \ # Transfer Protocol. The tftp protocol is often used to boot diskless \ # workstations, download configuration files to network-aware printers, \ # and to start the installation process for some operating systems. service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /tftpboot disable = no }
Then you can restart the xinetd service to pick up the changes:
$ sudo systemctl restart xinetd
Now tftp, according to that configuration, should serve its files from /tftpboot, but that's not what I found was happening. Instead it was wanting to serve the files from /srv/tftp. You will need to make that folder for yourself since it isn't there by default:
$ sudo mkdir -p /srv/tftp
And then place the files you downloaded into it. You will need to do that as root, so do it from the command line:
$ sudo cp ~/Downloads/dragino2-yun-common-v2.0.6-*.bin /srv/tftp/
And that should be that. You are now ready to try and recover the Dragino. This is where NetCat (nc) comes in. You need to start a NetCat server listening on port 6666 of your aliased interface waiting for a connection from your Dragino:
$ nc -kul -p 6666 192.168.255.1 6666
Note that the IP address there is the IP of the Dragino, not the IP of the interface. It will only accept a connection from that one specific place.
Now boot the Dragino into "Ethernet Recovery" mode. That means holding the little button on the side for 10 seconds while you turn the power on. The white and blue LEDs should flash 11 times. Release the button when they stop flashing. You should then see things appear on the screen, including a prompt:
dr_boot>
Now you should be good to go. First download and flash the kernel image:
dr_boot> tftpboot 0x81000000 dragino2-yun-common-v2.0.6-kernel.bin tftpboot 0x81000000 dragino2-yun-common-v2.0.6-kernel.bin TFTP from IP: 192.168.255.2 Our IP: 192.168.255.1 Filename: 'dragino2-yun-common-v2.0.6-kernel.bin' Load address: 0x81000000 Using: eth1 Loading: ######################################## ########## Lots of hashes here ######### ######################################## TFTP transfer complete! Bytes transferred: 1245184 (0x130000) dr_boot> erase 0x9fea0000 +0x140000 erase 0x9fea0000 +0x140000 Erase FLASH from 0x9FEA0000 to 0x9FFDFFFF in bank #1 Erasing: #################### Erased sectors: 20 dr_boot> cp.b 0x81000000 0x9fea0000 $filesize cp.b 0x81000000 0x9fea0000 $filesize Copying to FLASH... Writting at address: 0x9FEA0000 Done!
Be sure to put all those numbers in exactly, or you could permanently kill the Dragino!
And yes, they really can't spell "Writing"...
Now do the same with the root filesystem:
dr_boot> tftpboot 0x81000000 dragino2-yun-common-v2.0.6-rootfs-squashfs.bin tftpboot 0x81000000 dragino2-yun-common-v2.0.6-rootfs-squashfs.bin TFTP from IP: 192.168.255.2 Our IP: 192.168.255.1 Filename: 'dragino2-yun-common-v2.0.6-rootfs-squashfs.bin' Load address: 0x81000000 Using: eth1 Loading: ######################################## ########## Lots of hashes here ######### ######################################## TFTP transfer complete! Bytes transferred: 9175040 (0x8c0000) dr_boot> erase 0x9f050000 +0xe50000 erase 0x9f050000 +0xe50000 Erase FLASH from 0x9F050000 to 0x9FE9FFFF in bank #1 Erasing: ####################################### ####################################### ####################################### ####################################### ####################################### ################################## Erased sectors: 229 dr_boot> cp.b 0x81000000 0x9f050000 $filesize cp.b 0x81000000 0x9f050000 $filesize Copying to FLASH... Writting at address: 0x9F050000 Done!
Again be sure to get those numbers right! Copy and paste is your friend!
And that should be it. Time to make it boot into the new image:
dr_boot> setenv bootcmd bootm 0x9fea0000 setenv bootcmd bootm 0x9fea0000 dr_boot> saveenv saveenv Saving environment to FLASH... Erase FLASH from 0x9F030000 to 0x9F03FFFF in bank #1 Erasing: # Erased sectors: 1 Writting at address: 0x9F030000 dr_boot> reset reset Resetting the board...
Pressing CTRL-C at this point will exit you from NetCat.
And that should be that. The Dragino will, of course, have been reset completely to factory settings, so you can now go ahead and configure it as if it were a brand new Dragino.
Enjoy.