Thursday, November 13, 2014

I critically wounded Edison and used my cleric powers to restore it to super shape! (Or the story of what to do to restore an Intel Edison by U-Boot)

Prelude to disaster



Over the last couple weeks I continued trying to tame my Intel Edison but I must admit that I did go a little too hard on it for is own safety. At first I was going to solder wire directly on the breakout board but when I began thinking about it, I decided to solder a female header instead. I made a little order at the RobotShop online store for the hardware I needed and after a couple of days I received them. This is when the fun began. I did not have the chance to solder anything for the last 10 years and I was never really good, but I ordered a third hand to help me and this changed my life. For good measure I looked at some video tutorial on Youtube and made extra caution not to touch any IC on the Edison. At first I was not very good but I soon learned to keep the iron a little longer after I removed the solder wire to let it enter the hole.  I did the same for the OLED display I will try to use for my Meteo Notifier V2 project. So with my Edison breakout board ready for some prototyping, I tried my hand on some NodeJS program to control a LED using the blink sample. I played a little bit with it to make some fun and began looking at how to make the display working.



I enter the dark alley


I selected the NHD-1.5-128128UGC3 OLED display from Newhaven Display that can be controlled using the SPI protocol. The SPI protocole is somewhat simple, having myself wrote a small driver using GPIO in the past, but with the Edison I intended to use the hardware SPI master. It use 4 wire, SS, SCK, MISO, MOSI but can be used with only 3 wire, removing the MISO, as it is the case for my device. As you can see with the following image the SCK is a clock, the SS is a ship select that can be used to select multiple device using multiple SS pin and the MOSI is the master output slave input or simply the data written to the device. That's the logical protocol but my problem began when I tried to connect it electrically.  I soon discovered that there was a problem with the voltage, because the IO on the Edison is 1.8V and my display use a 3.3V input. With more expectation then real hope I looked in the specification and found that this was not compatible. This is when I realized that the first major flaw of the Edison. I had read about it rapidly on some site but at this moment it hit me like a ton of brick and realized that as it was a big problem. The problem is that the 1.8V IO's is good for the TDP but not super to connect to hobby board that mainly use 3.3V. I am sure that with time more and more hobby board will use 1.8V IC, but for now you need to use logic level shifter. That's what I did and placed another order on RobotShop for some 4 signal logic level shifter PCB.

The electrical murder


With all the electronic in hand I began connecting wire between the Edison breakout board and my OLED display PCB, using the logic level shifter in between. I must admit that I learned the hard way how to use IC and how not to blow them up. At work I only have the software to do and I let the electric engineer do this job. But at home I prefer doing all the work myself, with all the small manipulation error that I can sometime do ;) In this case I tried to use an old electrolytic capacitor for decoupling but for some reason, a short maybe ;), the Edison did not like that and one of the LED on the breakout board shutdown and I also eared some clicking noise on it. At this point I began to expect the worse but after some time the Edison restarted. But I soon realized that something was going wrong when XDK began giving errors when trying to copy the files on the Edison and I also noticed some problem with the serial port. My first instinct was that the eMMC was corrupted and I began to reflash the OS using the USB drive and reboot ota method. I soon discovered that there was a problem with that because I had some problem copying the rescue files to the USB drive and when the Edison rebooted it tried flashing a file but there was an error and rebooted. At this point my Edison was stuck in an infinite loop at an early stage in the boot so that this flashing method was not available anymore.

How I used my cleric healing power


The electronic may not be my best skill but restoring an embedded device is one of the thing I do everyday at work. As a software engineer for embedded devices, I developed codes to restore devices at very low level and I had to do it in with device in very bad shape. As I had noticed at the start of the boot process the prompt to enter U-Boot, I had great hope of fixing it without hardware solution like JTAG. But as I never used U-Boot and that there is no documentation for the Edison version, I was in for an exploration trip (I thought after that I could look in the source code!). I began by trying the help command, but I stumble into a little problem, screen do not have scroll bars so I lost the majorities of the commands so I maximized my terminal and retry the help. This time I found some interesting things. After some try and some research on Google I found the mmc command, but that did not help me on this even if it was interesting. So there is what I did to fix my broken OS using my Linux PC.

1. On your PC open a terminal on the Edison serial port. In my case I used the screen command

sudo screen /dev/ttyUSB0 115200


2. Reboot the Edison and when you see this on your serial console press Enter before the countdown     reach 0

******************************
PSH KERNEL VERSION: b0182727
  WR: 20104000
******************************

SCU IPC: 0x800000d0  0xfffce92c

PSH miaHOB version: TNG.B0.VVBD.0000000c

microkernel built 23:15:13 Apr 24 2014

******* PSH loader *******
PCM page cache size = 192 KB 
Cache Constraint = 0 Pages
Arming IPC driver ..
Adding page store pool ..
PagestoreAddr(IMR Start Address) = 0x04899000
pageStoreSize(IMR Size)          = 0x00080000

*** Ready to receive application *** 


U-Boot 2014.04 (Oct 14 2014 - 15:19:04)

       Watchdog enabled
DRAM:  980.6 MiB
MMC:   tangier_sdhci: 0
In:    serial
Out:   serial
Err:   serial
Hit any key to stop autoboot:  0 

3. In the serial console enter this command

run do_force_flash_os

4. Download the rescue from the Intel site and select the Edison Yocto complete image
5. Unzip it to a folder
6. Open a terminal on this folder
7. Enter this command in your PC terminal

sudo ./flashall.sh

On the PC terminal you will see that

Using U-Boot target: edison-blank


Now waiting for dfu device 8087:0a99

Please plug and reboot the board

Flashing IFWI

##################################################] finished!

##################################################] finished!

Flashing U-Boot

##################################################] finished!

Flashing U-Boot Environment

##################################################] finished!

Flashing U-Boot Environment Backup

##################################################] finished!

Flashing boot partition (kernel)

##################################################] finished!

Flashing rootfs, (it can take up to 5 minutes... Please be patient)

##################################################] finished!

Rebooting

U-boot & Kernel System Flash Success...

Your board needs to reboot twice to complete the flashing procedure, please do not unplug it for 2 minutes.

And in your Edison serial port terminal you will see something that look like this

Saving Environment to MMC...
Writing to redundant MMC(0)... done
GADGET DRIVER: usb_dnl_dfu
#
DFU complete CRC32: 0x677be95a
DOWNLOAD ... OK
Ctrl+C to exit ...
#
DFU complete CRC32: 0x677be95a
DOWNLOAD ... OK
Ctrl+C to exit ...
#
DFU complete CRC32: 0x7d41232d
DOWNLOAD ... OK
Ctrl+C to exit ...
#
DFU complete CRC32: 0x6d41a02b
DOWNLOAD ... OK
Ctrl+C to exit ...
#
DFU complete CRC32: 0x6d41a02b
DOWNLOAD ... OK
Ctrl+C to exit ...
#
DFU complete CRC32: 0xdaddfa4a
DOWNLOAD ... OK
Ctrl+C to exit ...
################################################################
DFU complete CRC32: 0xdb8b7821
DOWNLOAD ... OK
Ctrl+C to exit ...
resetting ...

Congratulation you would now have restored your Edison to full health :)
Needless to say that this will only work if you did not break it to the point that the U-Boot prompt is not available or if the eMMC have been physically broken. I hope this could help someone.

No comments:

Post a Comment