Skip to content

Instantly share code, notes, and snippets.

@nikdoof
Last active November 13, 2023 08:30
Show Gist options
  • Save nikdoof/f75f5ac40d79dcd5ed7c27d6c170c387 to your computer and use it in GitHub Desktop.
Save nikdoof/f75f5ac40d79dcd5ed7c27d6c170c387 to your computer and use it in GitHub Desktop.
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
84792 0x14B38 CRC32 polynomial table, little endian
86716 0x152BC xz compressed data
131072 0x20000 uImage header, header size: 64 bytes, header CRC: 0xB07BDC72, created: 2023-11-05 19:22:42, image size: 104304 bytes, Data Address: 0x0, Entry Point: 0x0, data CRC: 0xA4DFAB1B, OS: Firmware, CPU: ARM, image type: OS Kernel Image, compression type: lzma, image name: "MVX4##I6B0gf3a2dcfCM_UBT1501#XVM"
131136 0x20040 xz compressed data
327680 0x50000 uImage header, header size: 64 bytes, header CRC: 0x53A646C, created: 2023-11-12 23:19:25, image size: 1855208 bytes, Data Address: 0x20008000, Entry Point: 0x20008000, data CRC: 0x25417C70, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: none, image name: "Linux-4.9.84-ssc333"
342619 0x53A5B xz compressed data
342953 0x53BA9 xz compressed data
2424832 0x250000 Squashfs filesystem, little endian, version 4.0, compression:xz, size: 5054462 bytes, 751 inodes, blocksize: 131072 bytes, created: 2023-11-12 23:24:34
#!/usr/bin/env python3
# Based on https://github.com/OpenIPC/website/blob/master/app/models/firmware.rb
import argparse
import tarfile
import tempfile
import requests
def main():
parser = argparse.ArgumentParser('firmware_builder')
parser.add_argument('TAR', help='Firmware tar file')
parser.add_argument('SIZE', type=int, help='Size of the flash image in MB')
args = parser.parse_args()
# Source tar file
source = tarfile.open(args.TAR)
# Identify the files needed
for fl in source.getmembers():
if 'md5sum' in fl.name:
continue
if fl.name.startswith('uImage'):
kernel = fl
soc = kernel.name.split('.')[1]
print('SOC: {0}'.format(soc))
print('Kernel: {0}'.format(kernel.name))
elif fl.name.startswith('rootfs.squashfs'):
rootfs = fl
print('Rootfs: {0}'.format(rootfs.name))
# Get u-boot from OpenIPC
url = "https://github.com/OpenIPC/firmware/releases/download/latest/u-boot-{0}-nor.bin".format(soc)
print('U-boot: {0}'.format(url))
resp = requests.get(url)
if not resp.ok:
print('Error grabbing {0}'.format(url))
return
uboot = tempfile.TemporaryFile()
uboot.write(resp.content)
uboot.seek(0)
# Prep file
output_filename = '{0}-{1}mb.bin'.format(soc, args.SIZE)
dest = open(output_filename, 'wb')
dest.write(b"\xff" * (args.SIZE * (1024 ** 2)))
dest.seek(0)
# Write u-boot
dest.write(uboot.read())
# Write kernel
dest.seek(0x50000)
dest.write(source.extractfile(kernel).read())
# Write rootfs
if args.SIZE == 8 or soc.startswith('ssc'):
rootfs_offset = 0x250000
elif args.SIZE == 16:
rootfs_offset = 0x350000
elif args.SIZE == 32:
rootfs_offset = 0x350000
print('Rootfs Offset: {0}'.format(rootfs_offset))
dest.seek(rootfs_offset)
dest.write(source.extractfile(rootfs).read())
dest.close()
print('Bin Wrote: {0}'.format(output_filename))
if __name__ == '__main__':
main()
[nikdoof@Opux] (scripts) % ./firmware_builder.py openipc.ssc333-nor-lite.tgz 8
Kernel: uImage.ssc333
Rootfs: rootfs.squashfs.ssc333
U-boot: https://github.com/OpenIPC/firmware/releases/download/latest/u-boot-ssc333-nor.bin
Rootfs Offset: 2424832
Bin Wrote: ssc333-8mb.bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment