Buy(Cart) Contact NSDSP Home

nshex - extract

The extract command extracts a part of a HEX image. The image part may be selected by memory type (such as code, configuration, EEPROM etc.), or as a range of addresses.



target = extract(source,type,from,to,units)

Argument Description
source The Source image.
type Memory to extract. May be one of the following:
  • code - code memory, including all boot and auxillary segments (if any).
  • config - configuration bits.
  • eeprom - EEPROM
  • uid - User Id
  • otp - OTP memory
  • special - Special purpose memory. Currently only FBOOT memory on dual-partition devices
  • junk - Memory outside of legally writable area. Such memory should not be present in the HEX file
  • range - A range of addresses. The "from" and "to" arguments specify the exact range
from May only be specified if the type is "range". Specifies the beginning of the range to be extracted.
to May only be specified if the type is "range". Specifies the end of the range to be extracted. This address itself is not included in the range.
units Optional. May only be specified if the type is "range". Specifies the addresses to be used. For PIC18 and PIC32, there is no difference between units. For PIC16, PIC24,and dsPIC33, the "hex" units are the device units multiplied by two. If the device is unknown, only "hex" units may be used. May be one of the following:
  • hex - Default. The addresses are specified in HEX file units.
  • dev - The addresses are specified in device units.



eeprom = extract(raw,eeprom)

This command extracts all the EEPROM data from the raw HEX image. The new image containing EEPROM data is named "eeprom".


# bootmix.txt - Merging Bootloader and Application
device dsPIC33FJ128MC804

#read the bootloader file
boot = read(boot.hex)

#read the app file
app = read(app.hex)

#extract pieces
ivt = extrat(boot,range,0,0x200,dev)
config = extrat(app,config)
boot = extract(boot,code)
app = extract(app,code)

#combine pieces as needed
mix = merge(app,boot)
mix = merge(mix,ivt)
mix = merge(mix,config)

This example shows an nshex command file which can be used to combine application and bootloader together so that they could be programmed onto the chip in a single pass. It first reads two hex images from the hex files "boot.hex" and "app.hex".

Then the pieces get extracted from the files. IVT is extracted from the bootloader HEX image with the Extract command by directly specifying the memory range where IVT is located. Confinguration is extracted from the application HEX image. Code is extracted from both images.

Finally, the pieces are mixed together with the merge command and saved as "mix.hex". The file is now ready to be programmed on the chip

This command file could be used like this:

nshex -s bootmix.txt
nsprog p -i mix.hex

Here nshex is used to build the HEX file and then nsprog programs the file onto the target device. Note that you don't need to specify the device name for nsprog because nshex embedded the name of the device into the HEX file.

Northern Software Home NSDSP Contact Us Purchase/Vew Cart

© 2007-2023 Northern Software Inc. All Rights Reserved.