0

I am working on development of device working on embedded linux. When working with new hardware versions of it, when I mess up, I have an image that I can copy using dd to SD card, boot from it, and dd it it to internal eMMC storage.

As the image for old HW is lost, I'm trying to create a new backup image and I would like it to be as small as possible, but as dd is doing it block-by-block and it doesn't matter if there is anything or not on the block it will copy it anyway, so I need full device copied. Internal storage is about 4GB (ext4) and the files are less then 200MB...

I know I can use dd if=/dev/source-device of=image | tar ... but I would prefer to make rather something like dd if=/dev/source-device of=image bs=1M count=300 but to do this I have to make sure my data is in first 300MB.

This brings me two questions:

1) How to check if data is in first 300MB of disk?

2) if data is not there how to make it move to beginning of disk?

mslo
  • 1

1 Answers1

0

There's no "magic" way to do what you are trying to do.

You either need to know the exact size of the meaningful data in your image (if the tools you use to make the image don't create a file the size of the flash partition, then you should know this already) or find the end of it somehow. How to find the end is dependent on the data in your image and the tools you are using to make it.

If the tools you are using to install the image are not writing over all the blocks in the mmc device, you could create a "blank" image that has a discernible pattern such as ASCII/Unicode text XX_BLANK_FIRMWARE_SECTION_XX\n\0 repeated over and over.

You can then use a utility to find where in the current image that string starts, from which you can then figure out the count value to give dd. Not sure exactly which utilities to use for this purpose but I'm sure with good use of hexdump or similar it can be done easily.

You may be a few bytes off but it would be better than copying the entire flash, if you really want to avoid it.

Personally I'd just get a 16GB SD card that can hold multiple images.

LawrenceC
  • 73,957