|
48 | 48 | * parameters to the service. The DfuServiceInitiator class may be used to make this process easier.
|
49 | 49 | * It provides simple API that covers all low lever operations.
|
50 | 50 | */
|
51 |
| -@SuppressWarnings({"WeakerAccess", "unused"}) |
52 |
| -public class DfuServiceInitiator { |
| 51 | +@SuppressWarnings({"WeakerAccess", "unused", "deprecation"}) |
| 52 | +public final class DfuServiceInitiator { |
53 | 53 | public static final int DEFAULT_PRN_VALUE = 12;
|
| 54 | + public static final int DEFAULT_MBR_SIZE = 0x1000; |
54 | 55 |
|
55 | 56 | /** Constant used to narrow the scope of the update to system components (SD+BL) only. */
|
56 | 57 | public static final int SCOPE_SYSTEM_COMPONENTS = 1;
|
@@ -80,6 +81,7 @@ public class DfuServiceInitiator {
|
80 | 81 | private boolean enableUnsafeExperimentalButtonlessDfu = false;
|
81 | 82 | private boolean disableResume = false;
|
82 | 83 | private int numberOfRetries = 0; // 0 to be backwards compatible
|
| 84 | + private int mbrSize = DEFAULT_MBR_SIZE; |
83 | 85 |
|
84 | 86 | private Boolean packetReceiptNotificationsEnabled;
|
85 | 87 | private int numberOfPackets = 12;
|
@@ -374,6 +376,32 @@ else if (scope == (SCOPE_APPLICATION | SCOPE_SYSTEM_COMPONENTS))
|
374 | 376 | return this;
|
375 | 377 | }
|
376 | 378 |
|
| 379 | + /** |
| 380 | + * This method sets the size of an MBR (Master Boot Record). It should be used only |
| 381 | + * when updating a file from a HEX file. If you use BIN or ZIP, value set here will |
| 382 | + * be ignored. |
| 383 | + * <p> |
| 384 | + * The MBR size is important for the HEX parser, which has to cut it from the Soft Device's |
| 385 | + * HEX before sending it to the DFU target. The MBR can't be updated using DFU, and the |
| 386 | + * bootloader expects only the Soft Device bytes. Usually, the Soft Device HEX provided |
| 387 | + * by Nordic contains an MBR at addresses 0x0000 to 0x1000. |
| 388 | + * 0x1000 is the default size of MBR which will be used. |
| 389 | + * <p> |
| 390 | + * If you have a HEX file which address start from 0 and want to send the whole BIN content |
| 391 | + * from it, you have to set the MBR size to 0, otherwise first 4096 bytes will be cut off. |
| 392 | + * <p> |
| 393 | + * The value set here will not be used if the {@link DfuSettingsConstants#SETTINGS_MBR_SIZE} |
| 394 | + * is set in Shared Preferences. |
| 395 | + * |
| 396 | + * @param mbrSize the MBR size in bytes. Defaults to 4096 (0x1000) bytes. |
| 397 | + * @return the builder |
| 398 | + * @see DfuSettingsConstants#SETTINGS_MBR_SIZE |
| 399 | + */ |
| 400 | + public DfuServiceInitiator setMbrSize(@IntRange(from = 0) final int mbrSize) { |
| 401 | + this.mbrSize = mbrSize; |
| 402 | + return this; |
| 403 | + } |
| 404 | + |
377 | 405 | /**
|
378 | 406 | * Set this flag to true to enable experimental buttonless feature in Secure DFU. When the
|
379 | 407 | * experimental Buttonless DFU Service is found on a device, the service will use it to
|
@@ -730,6 +758,7 @@ public DfuServiceController start(@NonNull final Context context, @NonNull final
|
730 | 758 | intent.putExtra(DfuBaseService.EXTRA_FORCE_DFU, forceDfu);
|
731 | 759 | intent.putExtra(DfuBaseService.EXTRA_DISABLE_RESUME, disableResume);
|
732 | 760 | intent.putExtra(DfuBaseService.EXTRA_MAX_DFU_ATTEMPTS, numberOfRetries);
|
| 761 | + intent.putExtra(DfuBaseService.EXTRA_MBR_SIZE, mbrSize); |
733 | 762 | if (mtu > 0)
|
734 | 763 | intent.putExtra(DfuBaseService.EXTRA_MTU, mtu);
|
735 | 764 | intent.putExtra(DfuBaseService.EXTRA_CURRENT_MTU, currentMtu);
|
|
0 commit comments