Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

bmapflash

resin-io-modules1.5kMIT1.2.2

Flash an image using a .bmap file

bmap, tools, bmaptools, flash, flasher

readme

bmapflash

Flash an image using a .bmap file

npm version dependencies Build Status Build status

Installation

Install bmapflash by running:

$ npm install --save bmapflash

Documentation

bmapflash.flashImageToFileDescriptor(imageStream, deviceFileDescriptor, bmapContents, [options]) ⇒ EventEmitter

Kind: static method of bmapflash
Summary: Flash image to file descriptor
Returns: EventEmitter - event emitter
Access: public

Param Type Default Description
imageStream ReadableStream | image stream
deviceFileDescriptor Number | device file descriptor
bmapContents String | bmap contents
[options] Object {} options
[options.bytesToZeroOutFromTheBeginning] Number 0 bytes to zero out from the beginning

Example

fs.open('/dev/rdisk2', 'rs+', (error, fd) => {
  if (error) {
    throw error;
  }

  fs.readFile('my/image.bmap', {
    encoding: 'utf8'
  }, (error, bmapContents) => {
    if (error) {
      throw error;
    }

    const image = fs.createReadStream('path/to/image.img');

    const flasher = bmapflash.flashImageToFileDescriptor(image, fd, bmapContents);

    flasher.on('progress', (state) => {
      console.log(state);
    });

    flasher.on('error', (error) {
      throw error;
    });

    flasher.on('done', () => {
      console.log('Done!');
    });
  });
});

bmapflash.validateFlashedImage(deviceFileDescriptor, bmapContents) ⇒ EventEmitter

This function reads all the mapped blocks as specified by the .bmap file, generates checksums, and compares them to the checksums specified in the .bmap file.

The returned event emitter might emit the following events:

  • done (Object[]): Emitted when all the blocks have been scanned. This event passes as an argument an array of objects containing the ranges that did not pass validation.

  • error (Error): Emitted when an error happened.

  • progress (Object): Emitted regularly, passing an object containing progress state information.

Kind: static method of bmapflash
Summary: Validate flashed image
Returns: EventEmitter - event emitter
Access: public

Param Type Description
deviceFileDescriptor Number device file descriptor
bmapContents String bmap contents

Example

fs.open('/dev/rdisk2', 'rs+', (error, fd) => {
  if (error) {
    throw error;
  }

  fs.readFile('my/image.bmap', {
    encoding: 'utf8'
  }, (error, bmapContents) => {
    if (error) {
      throw error;
    }

    const validator = bmapflash.validateFlashedImage(fd, bmapContents);

    validator.on('progress', (state) => {
      console.log(state);
    });

    validator.on('error', (error) {
      throw error;
    });

    validator.on('done', (invalidRanges) => {
      if (invalidRanges.length !== 0) {
        console.log('Validation was not successful');
      }
    });
  });
});

Support

If you're having any problem, please raise an issue on GitHub and the Resin.io team will be happy to help.

Tests

Run the test suite by doing:

$ npm test

Contribute

Before submitting a PR, please make sure that you include tests, and that jshint runs without any warning:

$ npm run lint

License

bmapflash is free software, and may be redistributed under the terms specified in the license.

changelog

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

v1.2.1

1.2.2 - 2020-03-03

  • Update dependencies [Pagan Gazzard]

  • Make this module compatible with Node.js v4.

v1.2.0

  • Add bytesToZeroOutFromTheBeginning option.

v1.1.2

  • Fix ranges always being reported as invalid for certain images.
  • Ensure all progress events are emitted before emitting "done".

v1.1.1

  • Improve smoothness of progress state information.

v1.1.0

  • Add support for bmap v1.3.