Skip to contentSkip to conversation

arduino-101: Support for flashing via USB

PATCH New Juro Bystricky 1 participant 1 message Feb 12, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arduino-101: Support for flashing via USB

Implement a class allowing flashing Arduino-101 using dfu-util. User needs to have dfu-utils installed on the host machine. All tree cores supported (x86, ARM, ARC)

Sample usage:

    $ MACHINE=arduino-101 bitbake xxx
    $ MACHINE=arduino-101 bitbake xxx -c flash_usb
---
 classes/zephyr-flash-dfu.bbclass  | 34 ++++++++++++++++++++++++++++++++++
 conf/machine/arduino-101-sss.conf |  1 +
 conf/machine/arduino-101.conf     |  1 +
 3 files changed, 36 insertions(+)
 create mode 100644 classes/zephyr-flash-dfu.bbclass
classes/zephyr-flash-dfu.bbclass new file +34 -0
new file mode 100644
index 0000000..2d82281
@@ -0,0 +1,34 @@
+
+python do_flash_usb() {
+    import subprocess
+    return_code = subprocess.call("which dfu-util", shell=True)
+    if return_code != 0:
+        bb.error("ERROR: dfu_util binary not in PATH")
+        sys.exit(1)
+
+    board = d.getVar('BOARD',True)
+    bb.warn("Attempting to flash board: %s" % board)
+
+    if board == 'arduino_101_sss':
+        iface = 'sensor_core'
+    elif board == 'arduino_101':
+        iface = 'x86_app'
+    elif board == 'arduino_101_ble':
+        iface = 'ble_core'
+    else:
+        bb.error(" Unsupported board %s" % board)
+        sys.exit(2)
+
+    image = "%s/%s.elf" % (d.getVar('DEPLOY_DIR_IMAGE', True), d.getVar('PN', True))
+    statement = 'dfu-util -v -a ' + iface + ' -d 8087:0aba -D ' + image.replace('elf','bin')
+    bb.note("command: %s" % statement)
+    return_code = subprocess.call(statement, shell=True)
+    if return_code != 0:
+        bb.error("Error flashig the device [%d], reset needed?" % return_code)
+    else:
+        bb.warn("Success (return code %d)" % return_code)
+}
+
+addtask do_flash_usb
+
+do_flash_usb[nostamp] = "1"
conf/machine/arduino-101-sss.conf +1 -0
index cab5a3f..14b9861 100644
@@ -16,3 +16,4 @@ PREFERRED_VERSION_binutils-cross-${TARGET_ARCH} = "2.26+gitarc"
 PREFERRED_VERSION_binutils-cross-canadian-${TRANSLATED_TARGET_ARCH} = "2.26+gitarc"
 
 TARGET_LINK_HASH_STYLE = ""
+ZEPHYR_INHERIT_CLASSES += "zephyr-flash-dfu"
conf/machine/arduino-101.conf +1 -0
index 543a41e..b38c320 100644
@@ -8,3 +8,4 @@ require conf/machine/include/tune-iamcu.inc
 TUNE_PKGARCH_arduino-101 = "iamcu"
 
 TARGET_LINK_HASH_STYLE = ""
+ZEPHYR_INHERIT_CLASSES += "zephyr-flash-dfu"
Signature · 1 line
2.7.4