Skip to content

Instantly share code, notes, and snippets.

@ravikp7
Forked from jadonk/README.md
Last active March 8, 2017 18:43
Show Gist options
  • Save ravikp7/fbaa73ebd00297dfb3fe9d951268d199 to your computer and use it in GitHub Desktop.
Save ravikp7/fbaa73ebd00297dfb3fe9d951268d199 to your computer and use it in GitHub Desktop.
Hacks and node-beaglebone-boot

Current status:

playdoh:BBBlfs jason$ node --version
v7.5.0
playdoh:BBBlfs jason$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
playdoh:BBBlfs jason$ node main.js 
Device {
  busNumber: 20,
  deviceAddress: 22,
  deviceDescriptor: 
   { bLength: 18,
     bDescriptorType: 1,
     bcdUSB: 512,
     bDeviceClass: 2,
     bDeviceSubClass: 0,
     bDeviceProtocol: 0,
     bMaxPacketSize0: 64,
     idVendor: 1105,
     idProduct: 24897,
     bcdDevice: 0,
     iManufacturer: 33,
     iProduct: 37,
     iSerialNumber: 0,
     bNumConfigurations: 1 },
  portNumbers: [ 1, 1 ] }
Interface {
  device: 
   Device {
     busNumber: 20,
     deviceAddress: 22,
     deviceDescriptor: 
      { bLength: 18,
        bDescriptorType: 1,
        bcdUSB: 512,
        bDeviceClass: 2,
        bDeviceSubClass: 0,
        bDeviceProtocol: 0,
        bMaxPacketSize0: 64,
        idVendor: 1105,
        idProduct: 24897,
        bcdDevice: 0,
        iManufacturer: 33,
        iProduct: 37,
        iSerialNumber: 0,
        bNumConfigurations: 1 },
     portNumbers: [ 1, 1 ],
     interfaces: [ [Object], [Circular] ],
     _configDescriptor: 
      { bLength: 9,
        bDescriptorType: 2,
        wTotalLength: 70,
        bNumInterfaces: 2,
        bConfigurationValue: 1,
        iConfiguration: 1,
        bmAttributes: 192,
        bMaxPower: 50,
        extra: <Buffer 03 09 03>,
        interfaces: [Object] } },
  id: 1,
  altSetting: 0,
  descriptor: 
   { bLength: 9,
     bDescriptorType: 4,
     bInterfaceNumber: 1,
     bAlternateSetting: 0,
     bNumEndpoints: 2,
     bInterfaceClass: 10,
     bInterfaceSubClass: 0,
     bInterfaceProtocol: 0,
     iInterface: 2,
     extra: <Buffer >,
     endpoints: [ [Object], [Object] ] },
  interfaceNumber: 1,
  endpoints: 
   [ InEndpoint {
       device: [Object],
       descriptor: [Object],
       address: 129,
       transferType: 2 },
     OutEndpoint {
       device: [Object],
       descriptor: [Object],
       address: 2,
       transferType: 2 } ] }
isKernelDriverActive = false
/Users/jason/workspace/BBBlfs/node_modules/usb/usb.js:168
	this.device.__claimInterface(this.id)
	            ^

Error: LIBUSB_ERROR_ACCESS
    at Interface.claim (/Users/jason/workspace/BBBlfs/node_modules/usb/usb.js:168:14)
    at Object.<anonymous> (/Users/jason/workspace/BBBlfs/main.js:13:36)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:418:7)
    at startup (bootstrap_node.js:139:9)
#!/usr/bin/env node
var usb = require('usb');
var packet = require('packet');
// Connect to BeagleBone
var device = usb.findByIds(0x0451, 0x6141);
console.log(device);
device.open();
var interface = device.interface(1);
console.log(interface);
if(device.interface(0).isKernelDriverActive()){ device.interface(0).detachKernelDriver(); } // Got this logic from BBBlfs
//sudo kextunload /System/Library/Extensions/HoRNDIS.kext
console.log('claim = ' + interface.claim());
//interface.attachKernelDriver();
var inEndpoint = interface.endpoint(0x81);
console.log(inEndpoint);
var outEndpoint = interface.endpoint(0x02);
console.log(outEndpoint);
// Set Transfer type
inEndpoint.transferType(usb.LIBUSB_TRANSFER_TYPE_BULK);
// Send BOOTP
inEndpoint.timeout = 0;
inEndpoint.transfer(450, onFirstIn);
function onFirstIn(error, data) {
console.log(error);
console.log(data);
}
var parser = packet.createParser();
parser.packet("rndis", "\
msg_type: b32, \
msg_len: b32, \
data_offset: b32, \
band_offset: b32, \
band_len: b32, \
out_band_elements: b32, \
packet_offset: b32, \
packet_info_len: b32, \
reserved_first: b32, \
reserved_second: b32");
var serializer = parser.createSerializer();
// Get ARP request, send response
// Get TFTP request, send data
{
"name": "beaglebone-boot",
"version": "0.0.1",
"description": "Boot BeagleBone over USB using on-chip ROM",
"main": "main.js",
"dependencies": {
"usb": "1.2.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/jadonk/beaglebone-boot.git"
},
"keywords": [
"beaglebone",
"boot",
"bootp",
"tftp",
"rndis",
"libusb"
],
"author": "Jason Kridner",
"license": "MIT",
"bugs": {
"url": "https://github.com/jadonk/beaglebone-boot/issues"
},
"homepage": "https://github.com/jadonk/beaglebone-boot#readme"
}
@jadonk
Copy link

jadonk commented Mar 8, 2017

playdoh:fbaa73ebd00297dfb3fe9d951268d199 jason$ node main.js 
Device {
  busNumber: 20,
  deviceAddress: 11,
  deviceDescriptor: 
   { bLength: 18,
     bDescriptorType: 1,
     bcdUSB: 512,
     bDeviceClass: 2,
     bDeviceSubClass: 0,
     bDeviceProtocol: 0,
     bMaxPacketSize0: 64,
     idVendor: 1105,
     idProduct: 24897,
     bcdDevice: 0,
     iManufacturer: 33,
     iProduct: 37,
     iSerialNumber: 0,
     bNumConfigurations: 1 },
  portNumbers: [ 1, 1 ] }
Interface {
  device: 
   Device {
     busNumber: 20,
     deviceAddress: 11,
     deviceDescriptor: 
      { bLength: 18,
        bDescriptorType: 1,
        bcdUSB: 512,
        bDeviceClass: 2,
        bDeviceSubClass: 0,
        bDeviceProtocol: 0,
        bMaxPacketSize0: 64,
        idVendor: 1105,
        idProduct: 24897,
        bcdDevice: 0,
        iManufacturer: 33,
        iProduct: 37,
        iSerialNumber: 0,
        bNumConfigurations: 1 },
     portNumbers: [ 1, 1 ],
     interfaces: [ [Object], [Circular] ],
     _configDescriptor: 
      { bLength: 9,
        bDescriptorType: 2,
        wTotalLength: 70,
        bNumInterfaces: 2,
        bConfigurationValue: 1,
        iConfiguration: 1,
        bmAttributes: 192,
        bMaxPower: 50,
        extra: <Buffer 03 09 03>,
        interfaces: [Object] } },
  id: 1,
  altSetting: 0,
  descriptor: 
   { bLength: 9,
     bDescriptorType: 4,
     bInterfaceNumber: 1,
     bAlternateSetting: 0,
     bNumEndpoints: 2,
     bInterfaceClass: 10,
     bInterfaceSubClass: 0,
     bInterfaceProtocol: 0,
     iInterface: 2,
     extra: <Buffer >,
     endpoints: [ [Object], [Object] ] },
  interfaceNumber: 1,
  endpoints: 
   [ InEndpoint {
       device: [Object],
       descriptor: [Object],
       address: 129,
       transferType: 2 },
     OutEndpoint {
       device: [Object],
       descriptor: [Object],
       address: 2,
       transferType: 2 } ] }
/Users/jason/workspace/fbaa73ebd00297dfb3fe9d951268d199/node_modules/usb/usb.js:168
	this.device.__claimInterface(this.id)
	            ^

Error: LIBUSB_ERROR_ACCESS
    at Interface.claim (/Users/jason/workspace/fbaa73ebd00297dfb3fe9d951268d199/node_modules/usb/usb.js:168:14)
    at Object.<anonymous> (/Users/jason/workspace/fbaa73ebd00297dfb3fe9d951268d199/main.js:13:36)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:418:7)
    at startup (bootstrap_node.js:139:9)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment