Grove Pi+のファームウェアをアップデート（Raspbian Buster Lite 2019-7-10使用）

フレッシュなRaspbianでGrove Pi+のファームウェアをアップデートする手順です。

# 使用したもの

* Raspberry Pi 3 Model B+
* Grove Pi+
* RASPBIAN BUSTER LITE 2019-7-10 (2019-07-10-raspbian-buster-lite.img)

# マイクロSD作成

`2019-07-10-raspbian-buster-lite.img`イメージファイルから、マイクロSDを作成します。

わたしはWin32 Disk Imagerを使いました。
起動時にSSHでリモート接続したいので、bootパーティションのルートに`ssh`というファイルを作っておきました。

# Raspbian起動

ラズパイにGrove Pi+を載せて、作成したマイクロSDで起動します。
このときに、Grove Pi+のGroveコネクタは何も接続しておかないほうが良いでしょう。（接続していたらどうなるのか？は知りません。）

# 必要なファイルをインストール

アップデートに必要なツール、ファイルをどしどしインストールします。

```bash
sudo apt update
sudo apt install git
mkdir ~/Dexter
cd ~/Dexter
git clone https://github.com/DexterInd/GrovePi.git
mkdir ~/Dexter/lib
cd ~/Dexter/lib
git clone https://github.com/DexterInd/AVRDUDE.git
```

# avrdudeをインストール

avrdudeをインストールする前に、依存しているパッケージをインストールします。

```
sudo apt install libncurses5 libusb-0.1-4
```

dpkgでavrdudeをインストールします。

```bash
cd ~/Dexter/lib/AVRDUDE/avrdude
sudo dpkg -i avrdude_5.10-4_armhf.deb
```

# Grove Pi+のファームウェアをアップデート

ファームウェアをアップデートします。

```bash
cd ~/Dexter/GrovePi/Firmware
sudo ~/Dexter/GrovePi/Firmware/firmware_update.sh
```

参考に実行結果を掲載しておきます。

```bash
pi@raspberrypi:~/Dexter/GrovePi/Firmware $ sudo ~/Dexter/GrovePi/Firmware/firmware_update.sh
Updating the GrovePi firmware
=============================
 http://www.dexterindustries.com/grovepi
 Run this program:
 sudo ./firmware_update.sh

=============================
Do you want to update the firmware? [y,n]y
Make sure that GrovePi is connected to Raspberry Pi
Firmware found
Press any key to start firmware update
. . .

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xFF:
avrdude: load data lfuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: reading input file "0xDA"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xDA:
avrdude: load data hfuse data from input file 0xDA:
avrdude: input file 0xDA contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: reading input file "0x05"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0x05:
avrdude: load data efuse data from input file 0x05:
avrdude: input file 0x05 contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "grove_pi_firmware.hex"
avrdude: input file grove_pi_firmware.hex auto detected as Intel Hex
avrdude: writing flash (13816 bytes):

Writing | ################################################## | 100% 3.49s

avrdude: 13816 bytes of flash written
avrdude: verifying flash memory against grove_pi_firmware.hex:
avrdude: load data flash data from input file grove_pi_firmware.hex:
avrdude: input file grove_pi_firmware.hex auto detected as Intel Hex
avrdude: input file grove_pi_firmware.hex contains 13816 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.98s

avrdude: verifying ...
avrdude: 13816 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

pi@raspberrypi:~/Dexter/GrovePi/Firmware $
```

# 参考

Grove Pi+に入れるファームウェア ... [これ](https://github.com/DexterInd/GrovePi/blob/master/Firmware/grove_pi_firmware.hex)
使っているavrdude ... [これ](https://github.com/DexterInd/AVRDUDE/blob/master/avrdude/avrdude_5.10-4_armhf.deb)