Skip to content

Prepare the Edison for OpenAPS

Oskar Pearson edited this page Jun 10, 2016 · 61 revisions

Introduction

The Intel Edison system comes with a very limited Operating System. It's best to replace this with a custom version of Debian, so that the config is as-close to the Raspberry Pi as possible. This fits best with OpenAPS, and it also means you have the latest security and stability patches.

Prerequisites

These instructions require a Linux-based computer or a Raspberry Pi. Note that you cannot use a Mac for this as far as we are aware - it must be a Linux or Windows machine.

To use a Raspberry Pi, you’ll need a large (preferably 16GB+) SD card. The Edison image is almost 2GB, so you’ll not only need space for the compressed and uncompressed image, but you’ll also need to enable a large swapfile on your Pi to fit the image into virtual memory while it is being flashed. Using an SD card as memory is very slow, so allow extra time to flash the Edison image using a Pi.

If you’re using a Raspberry Pi:

  1. Run sudo bash -c 'echo CONF_SWAPSIZE=2000 > /etc/dphys-swapfile' to configure a 2GB swap file. Note: if you don't have enough space on the SD card for a 2G swap a 1G swap will probably work
  2. Run sudo /etc/init.d/dphys-swapfile stop and then sudo /etc/init.d/dphys-swapfile start to enable the new swap file.
  3. If you installed watchdog on the pi, it's a good idea to stop it since loading the image into memory to flash is intensive

If you're using a Windows PC:

  1. Go to System Properties, under Performance click on Settings.
  2. Select Advanced and click on Change... to change the page size.
  3. On Virtual Memory window uncheck Automatically manage paging file size ... and set the Initial size and Maximum size to 1024 and 2048 and reboot.

Flashing UbiLinux onto the Edison

  1. From a linux-based computer or Raspberry Pi, download http://www.emutexlabs.com/files/ubilinux/ubilinux-edison-150309.tar.gz or if that is outdated, http://www.emutexlabs.com/ubilinux
  2. In download folder, right-click on file and extract (or use tar xvzf ubilinux-edison-150309.tar.gz from the command line)
  3. Connect a USB cable (one that carries data, not just power) to the USB console port and sudo screen /dev/ttyUSB0 115200 or similar (on a Mac it’s /dev/tty.usbserial-<TAB>). If you do no have screen installed you can install with sudo apt-get install screen (Linux). Once the screen comes up, press enter a few times to wake things up. This will give you a running view of what is happening on your Edison. [Note, this step is optional but helpful to see what is going on]
  4. Now you will see a login prompt for the edison on the console screen. Login with username root and no password. This will have us ready to reboot from the command line when we are ready.
  5. Plug USB cable (one that carries data, not just power) into the USB port that is almost in the on the bottom right (if reading the Intel logo) if setting up with the Intel board. If you are using the Sparkfun board, it is the USB port labeled OTG. Plug the other end into your Linux box / Pi.
  6. In a separate terminal window, log in and cd toFlash, then sudo ./flashall.sh If you receive an dfu-util: command not found error, you can install dfu-util by running sudo apt-get install dfu-util (Linux). It will ask you to reboot the Edison. If nothing else works, and you're feeling brave, you can try pulling the Edison out and reconnect it to the board to start the flash process.
  7. It will ask you to reboot the Edison. Go back to your console window and type in restart (or, perhaps reboot). Switch back to the other window and you will see the flash process begin. You can monitor both windows throughout the rest of the flash process.
  8. It will take 10-45 minutes to flash. The first 10-15 minutes it may appear like nothing is happening. Eventually you will start to see a progress bar in the console. At the end when it says to give it 2 minutes, give it 5 or so. If you open a 2nd ssh to the pi and run top you'll see dfu-util using all a bunch of memory.
  9. Congratulations! You’re Edison is flashed with Ubilinux. The default user name and password are both edison
  10. More instructions located: https://learn.sparkfun.com/tutorials/loading-debian-ubilinux-on-the-edison

Troubleshooting the flash process

a) If you get:

dfu-util: Device has DFU interface, but has no DFU functional descriptor
dfu-util: Cannot open DFU device 8087:0a99

that likely means you ran ./flashall.sh without sudo.

b) If you get:

Flashing rootfs, (it can take up to 10 minutes... Please be patient)
dfu-util -v -d 8087:0a99 --alt rootfs -D /home/pi/toFlash/edison-image-edison.ext4 -R 2>&1 | tee -a flash.log | ( sed -n '19 q'; head -n 1; cat >/dev/null )
Rebooting
U-boot & Kernel System Flash Success...

in something closer to 10 seconds than 10 minutes, then you likely didn't set up swap properly. To verify, cat flash.log and look for dfu-util: Cannot allocate memory of size 1610612736 bytes near the end.

c) If you have a failed flash or have problems with the reboot, try starting the console and hitting enter a bunch of times while connecting to stop autoboot. You'll then be at a boot> prompt. Run sudo ./flashall.sh and when it asks you to reboot type and enter run do_flash at the boot> prompt.

d) If you get an error that says "Ready to receive application" on the Edison the problem is you don't have enough power to properly boot up the Edison. This can happen if you are powering from your Pi. You should either connect a battery to the Edison board to give it a little boost, or use a powered USB hub between the Pi and the Edison.

e) If Edison reboots correctly but never gets picked up by the flashall.sh script and the flashing process does not start, check the Edison device ID. It will probably come out automatically after the flashall.sh script fails with a list of available devices connected to the machine. On Linux, you can run lsusb to get a list of usb devices with their device ID. If the device ID is different from the one expected on flashall.sh, you can edit the script and change lines containing: USB_VID=8087 & USB_PID=0a99 to whatever the Edison has for an ID. Some users have encountered their devices ID to be 8087:0a9e

Initial Setup

Log in as edison/edison via serial console.

su -
echo FIXME-thehostname-you-want > /etc/hostname

nano /etc/hosts
    - add the host name you chose to the end of the first line 
    - old: 127.0.0.1	localhost
    - new: 127.0.0.1	localhost FIXME-thehostname-you-want

nano /etc/network/interfaces
    - Uncomment 'auto wlan0'
    - Comment out 'auto usb0'
    - Don't uncomment or add in eth0
    - Set wpa-ssid to your wifi network name
    - Set wpa-psk to the password for your wifi network

passwd root       # set a secure password
passwd edison     # set a secure password

reboot      # to set hostname and configure wifi

Use http://weworkweplay.com/play/automatically-connect-a-raspberry-pi-to-a-wifi-network/ if you want to connect to multiple networks, rather than just one.

Update package Repositories

su -
sed -i '/^deb http...ubilinux.*$/d' /etc/apt/sources.list

dpkg -P nodejs nodejs-dev
apt-get update && apt-get -y dist-upgrade && apt-get -y autoremove
apt-get install -y sudo strace tcpdump screen acpid
adduser edison sudo
adduser edison dialout

Next, copy your ssh key to the edison if appropriate (directions you can adapt are here: http://openaps.readthedocs.io/en/latest/docs/walkthrough/phase-0/rpi.html#mac-and-linux), and run 'reboot' to upgrade your kernels and clear out logged in sessions and IDs

Upgrade

Log in as edison / your password. You can do this via Wifi or over serial console if you wish.

sudo -i
sed -i 's/wheezy/jessie/g' /etc/apt/sources.list
rm -f /etc/apt/sources.list.d/nodesource.list

sudo apt-get update
sudo apt-get -y install apt dpkg aptitude
  - Yes to restart services if it asks you
sudo apt-get -y upgrade             # NOT dist-upgrade
  - Yes to restarting services (including ssh - should not log you off)
  - Yes to disabling root ssh login
  - /etc/securetty - Enter 'Y' to keep the maintainer's version
  - /etc/init.d/hostapd - Enter 'Y' to keep the maintainer's version
sudo apt-get -y autoremove

sudo apt-get clean   # equivalent to 'rm -f /var/cache/apt/archives/*.deb'
sudo dpkg-reconfigure tzdata
  - to set the timezone since the normal docs point to using the PI specific tools

sudo reboot

Then install openaps as per the usual instructions.

Important settings for the Edison, post install

  • Remember to set your timezone sudo dpkg-reconfigure tzdata to ensure the APS processes your profile time correctly
  • Edit /etc/logrotate.conf and set the log rotation to daily from weekly and enable log compression by removing the hash on the #compress line, to reduce the probability of running out of disk space
  • See these instructions on how to set the WPA Supplicant process to connect to multiple access points
  • If your edison boots to a console and says it is in rescue mode (you can hit ctrl-d to continue or enter the root password), you may need to change a u-boot environment variable to make it boot normally. During the boot process you will see:
*** Ready to receive application *** 


U-Boot 2014.04 (Feb 09 2015 - 15:40:31)

       Watchdog enabled
DRAM:  980.6 MiB
MMC:   tangier_sdhci: 0
In:    serial
Out:   serial
Err:   serial
Hit any key to stop autoboot:  0 
  1. Hit any key to drop to a prompt and type:
    printenv bootargs_target
  2. If the answer is
    bootargs_target=first-install
    then type:
    setenv bootargs_target multi-user
    saveenv
  3. And to exit that firmware u-boot prompt:
    run do_boot