• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    C
  • License
    Other
  • Created about 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JojoDiff Alternative Patch library - portable C library for memory-efficient binary patching

Jojo AlterNative Patch (JANPatch)

Memory-efficient library which can apply JojoDiff patch files. Very useful for embedded development, for example for delta firmware updates. Written in C, and can be backed by anything that offers basic I/O primitives.

This is an implementation from scratch, done by reverse engineering the diff file format, and inspecting the diff generation code. It's not a derived work from jptch (the patch application in JojoDiff). The reason for this is that JojoDiff is licensed under GPLv3, which does not allow linking in the library in non-GPL applications. JANPatch is licensed under Apache 2.0.

For an example of using this library on an embedded system, see binary-diff-mbedos5.

Usage (CLI)

On POSIX systems (macOS, Linux, Cygwin under Windows):

  1. Build the CLI, via:

    $ make
    
  2. Run ./janpatch-cli with the old file, a JojoDiff patch file, and the destination:

    $ ./janpatch-cli demo/blinky-k64f-old.bin demo/blinky-k64f.patch ./blinky-k64f-patched.bin
    
  3. Verify that the patch was applied successfully:

    $ diff demo/blinky-k64f-new.bin blinky-k64f-patched.bin
    
    # should return nothing
    

Usage (library)

JANPatch is implemented in a single header file, which you can copy into your project. For portability to non-POSIX platforms you need to provide the library with function pointers to basic IO operations. These are fread, fwrite, fseek and (optionally) ftell. The file pointer for these functions is of type JANPATCH_STREAM, which you can set when building.

The functions are defined in a context, for example on POSIX systems, you define JANPatch like this:

#define JANPATCH_STREAM     FILE        // use POSIX FILE

#include "janpatch.h"

janpatch_ctx ctx = {
    // fread/fwrite buffers for every file, minimum size is 1 byte
    // when you run on an embedded system with block size flash, set it to the size of a block for best performance
    { (unsigned char*)malloc(1024), 1024 },
    { (unsigned char*)malloc(1024), 1024 },
    { (unsigned char*)malloc(1024), 1024 },

    // define functions which can perform basic IO
    // on POSIX, use:
    &fread,
    &fwrite,
    &fseek,
    &ftell          // NOTE: passing ftell is optional, and only required when you need progress reports
};

Then create three objects of type JANPATCH_STREAM and call janpatch with the context:

JANPATCH_STREAM *source = fopen("source.bin", "rb");
JANPATCH_STREAM *patch  = fopen("patch", "rb");
JANPATCH_STREAM *target = fopen("target.bin", "wb");

janpatch(ctx, source, patch, target);

For a demonstration of using this library on a non-POSIX system, see binary-diff-mbedos5#xdot.

Reporting progress

Exact progress indication is hard, as the size of the file after patching is not known, but you can get rudimentary progress (based on the pages written to the target stream) by setting the progress property on the context:

void progress(uint8_t percentage) {
    printf("Patch progress: %d%%\n", percentage);
}

ctx.progress = &progress;

Note that you need to have declared ctx.ftell for this to work.

Generating patch files

To generate patch files you'll need to build JojoDiff or JDiff.js.

  1. Install a recent version of Node.js.

  2. Install JDiff.js:

    $ npm install jdiff-js -g
    
  3. Generate a patch file via:

    $ jdiff old-file.bin new-file.bin old-to-new-file.patch
    

Running tests

To test janpatch against a wide variety of outputs you can run the integration tests. The script will generate all possible diffs between files in the integration-tests/source directory, then use janpatch to patch them.

To run:

  1. Install a recent version of Node.js.

  2. Build JojoDiff (see above).

  3. Build janpatch-cli.

  4. Run:

    $ node integration-tests/run-tests.js --jdiff-path "/path/to/jdiff"
    

Mbed OS 5 - Building without loading UART driver

Error messages are printed over printf, which will automatically load the UART drivers on Mbed OS 5. You can mitigate this by using debug(), which is stripped out when building for a release profile.

You can do this by declaring the JANPATCH_ERROR macro as such:

#define JANPATCH_ERROR(...)  debug(__VA_ARGS__)

License

Apache License version 2. See LICENSE.

More Repositories

1

mbed-simulator

Experimental simulator for Mbed OS 5 applications
C
174
star
2

node-native-zip

Zipping in node.js with no external dependencies
JavaScript
106
star
3

Moth

Moth has all the awesomness Steve Souders thaught you about fast websites, but fully integrated in your ASP.NET MVC project!
JavaScript
27
star
4

ttn-sensor-maps

Create pretty looking maps of TTN sensor nodes
JavaScript
18
star
5

mbed-vscode-generator

Generate VSCode intellisense and build configuration for Mbed OS
JavaScript
17
star
6

alpine-opencv-docker

Pre-built OpenCV for armhf Alpine Linux 3.6
C++
15
star
7

arduino-mbed-mashup

Running Arduino sketches on Mbed OS
C
14
star
8

css-reflow-tracer

Helps track down CSS reflows
JavaScript
14
star
9

binary-diff-mbedos5

Using JANPatch to apply a binary diff in Mbed OS 5
C++
12
star
10

rollingspider.xyz

Fly a drone in your browser
JavaScript
10
star
11

mbed-os-example-fota-http

Firmware update over HTTP example for mbed OS 5
C++
7
star
12

neosensory-arduinoble

Talk to NeoSensory from ArduinoBLE
C++
7
star
13

fxos-physical-web

Physical Web app for Firefox OS
JavaScript
7
star
14

b-l475e-iot01a-audio-mbed

Mbed OS example on driving the MEMS microphones on ST IoT Discovery Board
C
6
star
15

sam-lorawan-mbedos5

Mbed OS 5 LoRaWAN stack running on SAML21 and SAMR34 Xplained Pro
C++
6
star
16

jdiff-js

JojoDiff in JavaScript
JavaScript
6
star
17

meetingroom-web

Meetingroom management with Physical Web, web part
JavaScript
5
star
18

stm32-standby-rtc-wakeup

Bring STM32 device into Standby mode and wake it from RTC (Mbed OS 5 library)
C
5
star
19

mbed-delta-update

Delta update library for Mbed OS 5
C
4
star
20

mbed-os-example-cryptoauthlib

Mbed OS 5 example program for interacting with Crypto Authentication secure elements
C
4
star
21

lorawan-fota-signing-tool

LoRaWAN Firmware Update signing tools for Mbed OS 5
JavaScript
4
star
22

mbed-coremark-lm32-printf

Small printf library for Mbed OS 5 - based on https://github.com/jpbonn/coremark_lm32
C
4
star
23

mbed-ws

WIP! Websocket client for Mbed OS
C++
4
star
24

dsa2018-greenhouse-monitor

Greenhouse monitoring system for DSA 2018
C++
4
star
25

mbed-cryptoauthlib

Mbed OS library for interacting with the Crypto Authentication secure elements
C++
4
star
26

janos-tracker-server

Simple server for the tracker
JavaScript
3
star
27

iot-devfest

IoT DevFest workshop 2019
C++
3
star
28

mbed-websocket

WIP!!! Sane, non-blocking websocket client for Mbed OS
C++
3
star
29

apializer

Api'alizer turns a website into an API
JavaScript
3
star
30

sxsw

Demo's for SXSW
C++
3
star
31

jsconf-us

JavaScript
3
star
32

jsconf-asia

Experiments for JSConf.asia
JavaScript
3
star
33

mbed-js-wrapper-generator

WIP C++ <> JerryScript wrapper generator
JavaScript
3
star
34

app-training-dhaka

Some small projects
JavaScript
3
star
35

mbed-lorawan-frag-lib

LoRaWAN fragmentation library
C++
2
star
36

hexiwear-cloud

Hexiwear to mbed Device Connector
C++
2
star
37

push-server

Simple push server and client for FFOS
JavaScript
2
star
38

koehandel

Just a game
JavaScript
2
star
39

mbed-os-example-http-server

HTTP Server for mbed OS 5 - work in progress
C++
2
star
40

c9integration

JavaScript
2
star
41

omg-awesome-homescreen

Simple third-party homescreen template for Firefox OS
JavaScript
2
star
42

apf-demo

JavaScript
2
star
43

mbed-js-simulator

Run mbed.js programs in your browser
JavaScript
2
star
44

mbed-find-dangling-pointers

Find dangling pointers in Mbed OS projects
JavaScript
2
star
45

threejs-dice-physics

A bunch of falling dice
JavaScript
2
star
46

socketioupload

Demonstration on how to use socket.io and nodejs to create a file sharing application
JavaScript
2
star
47

electricity-bus-tracker

Track buses in Gothenburg
JavaScript
1
star
48

mobileeast

Mobile East 2012 demo repository
JavaScript
1
star
49

internal-training-lora-2019

Internal training for LoRaWAN
C++
1
star
50

azure-private-key-extractor

C#
1
star
51

at45-blockdevice

mbed OS 5 block device driver for AT45 flash
C++
1
star
52

mak-maze

Maze game for FFOS
CSS
1
star
53

jsdom-demo

JavaScript
1
star
54

test123

1
star
55

dsa-firmware-2019

Firmware for DSA 2019
C++
1
star
56

lorawan-fragmentation-in-flash

Memory efficient implementation of LoRaWAN Datablock Fragmentation for mbed OS 5
C
1
star
57

arm-objdump-parser

Generate trees of C++ code by parsing objdump files
JavaScript
1
star
58

mbed-js-repl

JS REPL for mbed
C++
1
star
59

doodle-jump-fxos

JavaScript
1
star
60

tech-live-analytics

Tracking physical product engagement with Google Analytics
C++
1
star
61

mbed-os-example-lorawan-skt

SK Telecom LoRaWAN example for Mbed OS 5
C++
1
star
62

ttn-conf-workshop

The Things Network Conference - FOTA workshop material
JavaScript
1
star
63

connector-mqtt

mbed Device Connector over MQTT
JavaScript
1
star
64

md2mbed

Convert Markdown into formatted text for os.mbed.com
JavaScript
1
star
65

emscripten-node-mmap

mmap for emscripten's NODEFS lib
C++
1
star
66

mbed-os-example-lorawan-minimal

Minimal version of mbed-os-example-lorawan for Murata module
C++
1
star
67

mbed-os-example-blinky-no-rtos

Blinky for mbed OS 5 without using mbed RTOS
C++
1
star
68

6lowpan-notes

Notes for 6LoWPAN article
1
star
69

schizophrenia

JavaScript
1
star
70

mbed-tsl2572

Mbed OS driver for the TSL2572 ambient light sensor
C++
1
star
71

pelion-ready-plus-azure

Run Pelion Device Management and Azure IoT Hub Client on the same device
C++
1
star
72

mbed-os-dev-lorawan

SXSW 2018 Temp LoRaWAN fork of Mbed OS
C
1
star
73

mbed-config

Visual configuration system for Mbed OS
HTML
1
star
74

mbed-davis-anemometer

Mbed driver for Davis Anemometer
C++
1
star
75

google-maps-socketio-demo

Google Maps demo that let's you put pins on a map, by clicking or via geocode. Plus it distributes them to all others with the window open as well. Collaboration ftw!
JavaScript
1
star
76

dsa2017-fieldwork-fw

Firmware for fieldwork during DSA2017
C++
1
star