-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repacking the modified squashfs into a deployable firmware file #4
Comments
By coincidence, I reverse engineered the CRC check (a slightly modified CRC32 with poly 0x77073096) three days ago, see 9b966e2 :-) Please contribute back things you create, a repack script might be helpful for others. |
To further add to your question: having a correct image file might not be sufficient. You have to understand the update procedure. The web gui internally calls the updater like this:
Where Inside the
Firmware v3.0.0.20_20052300 adds an |
we could be lucky due to the simple image layout. i recorded a log of doing an update/upgrade (they use both terms). The image layout is the following as printed out by the update task:
the squashfs image is at section:fs start:620000 with length:900000 so it might be as simple as adding the new squafsh image at the place 0x620000 / the place where the previous is, even if its bigger / smaller as always the full range will be written to NOR. see ref (Note with my camera, i found the squafsh image offset at 0x620000 which was different to what you had hardcoded in as 0x6e0000. seems these offsets are either different by camera, or it has chnaged in the recent fw version that I applied a few days ago before starting reverse engineering i found the right offset from the uboot commandline:
see |
some more research on the theory above (the squashfas is simply the last binary blob at the end of the image file and can be replaced) doing a binwalk on an orignal firmware file
reveals:
see the last row where the plain squashfs image was found at offset
hexdumping this with offset
now extracting the images using the
The squashfs image file is extracted correctly at offset
now hexdumping this extracted file,too:
file size is the same, and looks like the same output:
the addresses are different, so can't do a diff.
first 5 and last 5 lines of
this also looks similar. so now doing a binary compare.
performing a diff:
this proves that the squashfs image is indeed the last chunk in the firmware update file. It should be possible to overwrite the last chunks starting from the offset where the squashfs header is found (in this case The tricky part that is still outstanding, is to calculate the checksum of a new squashfs image and modify the header of the file accordingly. |
No, the
You refer 6422528, which is the offset on flash:
The pak file consists of both the image file section and (flash) partition layouts. |
you are correct, the partition offset is correctly displayed. Comment editd |
Thanks for the hint regarding the Firmware |
Wanted to give an update on this. I made significant progress in re-packing the modified squashfs into a pak file. I'm planning to upload a pull request for unpack-novatek-firmware.pl in the next days. This includes a flag that will take the original pak file and a mtdblock6-NEW.bin file and will write a new pak fiele with proper headers and CRC that can be deployed.
I now have a bit of trouble as I haven't found a way to upgrade the firmware with the same version again, the UI keeps complaining. Also i can't do a downgrade, Maybe I should have made a dump on sdcard before flashing... |
Try to start dropbear in foreground mode ( As I said in #4 (comment) we have to learn more about the update process (version numbers, ...). |
I used the wrong dropbox binary, had to use the one from the original contrib directory with a different path for the hostkey location. |
Any update on this? |
I'm not merging zengelan's repack-script into the main tree because the update mechanism in all its entirety hasn't been understood well (at least by me). For those who are brave of heart there is no known reason for not using the script. |
@zengelan I've tried your script because i can always dump and reflash the soc with my tools if it goes sideway. I cannot get it to update through the web UI though. it kicks back an "unknown error during update, please try again after device restarts" |
That's what the repack tells me when I try to unpack it again which I'm sure is why the flash fails. Edit: I had to fix the CRC bytes in the header of the repacked file with a hex editor and after naming it appropriately to pass their lame version checking it has flashed and is working. Latest Firmware for the RLC-410-5MP v3.0.0.136_20121100 |
Hi,
I tried to understand the unpack script to create a "repack" script. But i am struggling with the crc calculations. Would it be generally feasible to write a scipt / tool which would re-pack a modified squashfas image to a deploymabel firmware file?
The goal is to modify the image file and upload it to the camrea without the need to have a serial connection.
regards
.andreas
The text was updated successfully, but these errors were encountered: