From 87092b3c065978fc0e673856c34b3db0829280db Mon Sep 17 00:00:00 2001 From: Mikhail Zhilkin Date: Fri, 18 Mar 2022 17:02:30 +0000 Subject: scripts: add support for Sercomm kernel header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This scripts creates custom kernel header that necessary for Sercomm mt7621 devices: - Sercomm S3 - Beeline SmartBox Giga - Beeline SmartBox Pro - Beeline Smartbox Turbo - Beeline Smartbox Turbo+ - WiFire S1500.NBN Header format ------------- +--------+---------------+------------------------+ | Offset | Value | Description | +========+===============+========================+ | 0x0 | 53 65 72 00 | Magic "Ser." | +--------+---------------+------------------------+ | 0x4 | 04 00 00 01 | End offset of RootFS | +--------+---------------+------------------------+ | | | This header checksum | | 0x8 | d6 14 9a c1 | htonl(~crc) | +--------+---------------+------------------------+ | 0xc | 02 ff ff ff | Constant | +--------+---------------+------------------------+ | 0x10 | 00 01 40 00 | Kernel start offset | +--------+---------------+------------------------+ | 0x14 | c6 94 24 00 | Kernel length | +--------+---------------+------------------------+ | | | Kernel checksum | | 0x18 | e7 78 89 f1 | htonl(~crc) | +--------+---------------+------------------------+ | 0x1c | 00 00 00 00 | Constant | +--------+---------------+------------------------+ | 0x20 | ff ff ff ff | Constant | +--------+---------------+------------------------+ | 0x24 | ff ff ff ff | Constant | +--------+---------------+------------------------+ | 0x28 | 00 00 00 01 | RootFS offset | +--------+---------------+------------------------+ | | | RootFS length | | 0x2c | 04 00 00 00 | Always 0x4, we check | | | | UBI magic only | +--------+---------------+------------------------+ | | | RootFS checksum | | 0x30 | 1c fc 55 2d | htonl(~crc) | | | | Const for UBI magic | +--------+---------------+------------------------+ | 0x34 | 00 00 00 00 | Constant | +--------+---------------+------------------------+ | 0x38 | ff ff ff ff … | Pad to 0x100 | +--------+---------------+------------------------+ Signed-off-by: Mikhail Zhilkin --- scripts/sercomm-kernel-header.py | 121 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100755 scripts/sercomm-kernel-header.py (limited to 'scripts/sercomm-kernel-header.py') diff --git a/scripts/sercomm-kernel-header.py b/scripts/sercomm-kernel-header.py new file mode 100755 index 0000000000..bfb29c6fe0 --- /dev/null +++ b/scripts/sercomm-kernel-header.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 +""" +# SPDX-License-Identifier: GPL-2.0-or-later +# +# sercomm-kernel-header.py: Creates Sercomm kernel header +# +# Copyright © 2022 Mikhail Zhilkin +""" + +import argparse +import binascii +import os +import struct + +KERNEL_HEADER_SIZE = 0x100 +PADDING = 0xff +ROOTFS_FAKE_HEADER = "UBI#" + +def auto_int(x): + return int(x, 0) + +def create_kernel_header(args): + out_file = open(args.header_file, "wb") + header = get_kernel_header(args) + out_file.write(header) + out_file.close() + +def get_kernel_header(args): + header = bytearray([PADDING] * KERNEL_HEADER_SIZE) + + struct.pack_into('