Skip to content

Commit

Permalink
Merge pull request #170 from NordicSemiconductor/feature/retries
Browse files Browse the repository at this point in the history
New feature: retrying DFU in case of undesired disconnection
  • Loading branch information
philips77 authored Feb 21, 2019
2 parents dd95111 + 1a40f78 commit bbecebe
Show file tree
Hide file tree
Showing 33 changed files with 1,503 additions and 871 deletions.
61 changes: 45 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

### Usage

The compat library may be found on jcenter and Maven Central repository. Add it to your project by adding the following dependency:
The DFU library may be found on jcenter and Maven Central repository. Add it to your project by
adding the following dependency:

```Groovy
implementation 'no.nordicsemi.android:dfu:1.9.0'
```

For projects not migrated to Android Jetpack, use:

```Groovy
implementation 'no.nordicsemi.android:dfu:1.8.1'
Expand All @@ -13,18 +20,28 @@ implementation 'no.nordicsemi.android:dfu:1.8.1'
If you use proguard, add the following line to your proguard rules:
```-keep class no.nordicsemi.android.dfu.** { *; }```

Starting from version 1.9.0 the library is able to retry a DFU update in case of an unwanted
disconnection. However, to maintain backward compatibility, this feature is by default disabled.
Call `initiator.setNumberOfRetries(int)` to set how many attempts the service should perform.
Secure DFU will be resumed after it has been interrupted from the point it stopped, while the
Legacy DFU will start again.

### Device Firmware Update (DFU)

The nRF5x Series chips are flash-based SoCs, and as such they represent the most flexible solution available. A key feature of the nRF5x Series and their associated software architecture
and S-Series SoftDevices is the possibility for Over-The-Air Device Firmware Upgrade (OTA-DFU). See Figure 1. OTA-DFU allows firmware upgrades to be issued and downloaded to products
in the field via the cloud and so enables OEMs to fix bugs and introduce new features to products that are already out on the market.
The nRF5x Series chips are flash-based SoCs, and as such they represent the most flexible solution available.
A key feature of the nRF5x Series and their associated software architecture and S-Series SoftDevices
is the possibility for Over-The-Air Device Firmware Upgrade (OTA-DFU). See Figure 1.
OTA-DFU allows firmware upgrades to be issued and downloaded to products in the field via the cloud
and so enables OEMs to fix bugs and introduce new features to products that are already out on the market.
This brings added security and flexibility to product development when using the nRF5x Series SoCs.

![Device Firmware Update](resources/dfu.png)

This repository contains a tested library for Android 4.3+ platform which may be used to perform Device Firmware Update on the nRF5x device using a phone or a tablet.
This repository contains a tested library for Android 4.3+ platform which may be used to perform
Device Firmware Update on the nRF5x device using a phone or a tablet.

DFU library has been designed to make it very easy to include these devices into your application. It is compatible with all Bootloader/DFU versions.
DFU library has been designed to make it very easy to include these devices into your application.
It is compatible with all Bootloader/DFU versions.

[![Alt text for your video](http://img.youtube.com/vi/LdY2m_bZTgE/0.jpg)](http://youtu.be/LdY2m_bZTgE)

Expand All @@ -34,38 +51,50 @@ See the [documentation](documentation) for more information.

### Requirements

The library is compatible with nRF51 and nRF52 devices with S-Series Soft Device and the DFU Bootloader flashed on.
The library is compatible with nRF51 and nRF52 devices with S-Series Soft Device and the
DFU Bootloader flashed on.

### DFU History

#### Legacy DFU

* **SDK 4.3.0** - First version of DFU over Bluetooth Smart. DFU supports Application update.
* **SDK 6.1.0** - DFU Bootloader supports Soft Device and Bootloader update. As the updated Bootloader may be dependent on the new Soft Device, those two may be sent and installed together.
* **SDK 6.1.0** - DFU Bootloader supports Soft Device and Bootloader update. As the updated
Bootloader may be dependent on the new Soft Device, those two may be sent and
installed together.
- Buttonless update support for non-bonded devices.
* **SDK 7.0.0** - The extended init packet is required. The init packet contains additional validation information: device type and revision, application version, compatible Soft Devices and the firmware CRC.
* **SDK 8.0.0** - The bond information may be preserved after an application update. The new application, when first started, will send the Service Change indication to the phone to refresh the services.
* **SDK 7.0.0** - The extended init packet is required. The init packet contains additional
validation information: device type and revision, application version, compatible
Soft Devices and the firmware CRC.
* **SDK 8.0.0** - The bond information may be preserved after an application update.
The new application, when first started, will send the Service Change indication
to the phone to refresh the services.
- Buttonless update support for bonded devices
- sharing the LTK between an app and the bootloader.

#### Secure DFU

* **SDK 12.0.0** - New Secure DFU has been released. Buttonless service is experimental.
* **SDK 13.0.0** - Buttonless DFU (still experimental) uses different UUIDs. No bond sharing supported. Bootloader will use address +1.
* **SDK 14.0.0** - Buttonless DFU is no longer experimental. A new UUID (0004) added for bonded only devices (previous one (0003) is for non-bonded only).
* **SDK 13.0.0** - Buttonless DFU (still experimental) uses different UUIDs. No bond sharing
supported. Bootloader will use address +1.
* **SDK 14.0.0** - Buttonless DFU is no longer experimental. A new UUID (0004) added for bonded
only devices (previous one (0003) is for non-bonded only).
* **SDK 15.0.0** - Support for higher MTUs added.

This library is fully backwards compatible and supports both the new and legacy DFU.
The experimental buttonless DFU service from SDK 12 is supported since version 1.1.0. Due to the fact, that this experimental service from SDK 12 is not safe,
you have to call [starter.setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true)](https://github.com/NordicSemiconductor/Android-DFU-Library/blob/release/dfu/src/main/java/no/nordicsemi/android/dfu/DfuServiceInitiator.java#L376)
to enable it. Read the method documentation for details. It is recommended to use the Buttonless service from SDK 13 (for non-bonded devices, or 14 for bonded).
The experimental buttonless DFU service from SDK 12 is supported since version 1.1.0.
Due to the fact, that this experimental service from SDK 12 is not safe, you have to call
[starter.setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true)](https://github.com/NordicSemiconductor/Android-DFU-Library/blob/release/dfu/src/main/java/no/nordicsemi/android/dfu/DfuServiceInitiator.java#L376)
to enable it. Read the method documentation for details. It is recommended to use the Buttonless
service from SDK 13 (for non-bonded devices, or 14 for bonded).
Both are supported since DFU Library 1.3.0.

Check platform folders for mode details about compatibility for each library.

### React Native

A library for both iOS and Android that is based on this library is available for React Native: [react-native-nordic-dfu](https://github.com/Pilloxa/react-native-nordic-dfu)
A library for both iOS and Android that is based on this library is available for React Native:
[react-native-nordic-dfu](https://github.com/Pilloxa/react-native-nordic-dfu)

### Resources

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.1'

classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
Expand Down
8 changes: 4 additions & 4 deletions dfu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: 'com.jfrog.bintray'
ext {
PUBLISH_GROUP_ID = 'no.nordicsemi.android'
PUBLISH_ARTIFACT_ID = 'dfu'
PUBLISH_VERSION = '1.8.1'
PUBLISH_VERSION = '1.9.0'
bintrayRepo = 'android'
bintrayName = 'dfu-library'
Expand Down Expand Up @@ -45,8 +45,8 @@ android {
defaultConfig {
minSdkVersion 18
targetSdkVersion 28
versionCode 22
versionName "1.8.1"
versionCode 23
versionName "1.9.0"
}

buildTypes {
Expand All @@ -58,7 +58,7 @@ android {
}

dependencies {
implementation 'androidx.core:core:1.1.0-alpha02'
implementation 'androidx.core:core:1.1.0-alpha04'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation 'androidx.annotation:annotation:1.0.1'
implementation 'com.google.code.gson:gson:2.8.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Intent;

import androidx.annotation.NonNull;

/**
* A base implementation of a buttonless service. The purpose of a buttonless service is to
* switch a device into the DFU bootloader mode.
Expand All @@ -51,7 +53,7 @@ public void onCharacteristicWrite(final BluetoothGatt gatt, final BluetoothGattC
}
}

BaseButtonlessDfuImpl(final Intent intent, final DfuBaseService service) {
BaseButtonlessDfuImpl(@NonNull final Intent intent, @NonNull final DfuBaseService service) {
super(intent, service);
}

Expand All @@ -68,7 +70,8 @@ public BaseBluetoothGattCallback getGattCallback() {
* @param forceRefresh true, if cache should be cleared even for a bonded device. Usually the Service Changed indication should be used for this purpose.
* @param scanForBootloader true to scan for advertising bootloader, false to keep the same address
*/
protected void finalize(final Intent intent, final boolean forceRefresh, final boolean scanForBootloader) {
@SuppressWarnings("SameParameterValue")
void finalize(@NonNull final Intent intent, final boolean forceRefresh, final boolean scanForBootloader) {
/*
* We are done with DFU. Now the service may refresh device cache and clear stored services.
* For bonded device this is required only if if doesn't support Service Changed indication.
Expand Down
Loading

0 comments on commit bbecebe

Please sign in to comment.