../../../staging_dir/host/bin/lzma d tplink_tl-wdr4310-v1-kernel.bin 4310.unlzma
2.
using hexedit software okteta edit 4310.unlzma three offsets need modified (after A4):
0072:5258 replace hex 00020000 007d0000 with 00200000 00fd0000
0073:5272 replace string 7f with ff
0073:5298 replace hex 007f0000 00010000 with 00ff0000 00010000
3.../../../staging_dir/host/bin/lzma e -lc1 -lp2 4310.unlzma tplink_tl-wdr4310-v1-kernel.bin
4.
modify openwrt-imagebuilder-22.03.2-ath79-generic.Linux-x86_64/target/linux/ath79/image/generic-tp-link.mk
define Device/tplink_tl-wdr4310-v1
$(Device/tplink-8mlzma) ---> changing to 16mlzma
SOC := ar9344
DEVICE_MODEL := TL-WDR4310
DEVICE_VARIANT := v1
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ledtrig-usbport
TPLINK_HWID := 0x43100001
SUPPORTED_DEVICES += tl-wdr4300
endef
TARGET_DEVICES += tplink_tl-wdr4310-v1
make image PROFILE=tplink_tl-wdr4310-v1 PACKAGES="uhttpd luci luci-ssl"
youxiaojie
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "Taras Gavrylenko"
__copyright__ = "Copyright 2020, The OpenWrt Project"
__version__ = "0.9"
__email__ = "gavrylenko.taras@gmail.com"
__status__ = "Beta"
"""
OpenWrt TP-Link kernel DTS patcher allows to use release 19.07 kernel
and packages on hardware modded devices with increased flash chip size.
Set environment variable $LZMA_UTIL_PATH with path to LZMA utility
Recommended LZMA 4.65 : Igor Pavlov : Public domain : 2009-02-03
from Openwrt originals
Be sure you have Python interpreter 3.8 or higher
Run: python3.8 kernel_patcher.py <path_to_kernel_file>
Script stages:
1. Rename original kernel to *.bak
2. Unpack original kernel
3. Patch DTS partition table
4. Pack new kernel
"""
import argparse
import logging
import os
import subprocess
from pathlib import Path
logging.basicConfig(
format='%(asctime)s %(levelname)s %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
def run_command(cmd: str):
return subprocess.call(cmd, shell=True)
def compress_lzma(lzma_util: str, raw_path: Path, lzma_path: Path) -> int:
cmd = f'{lzma_util} e {raw_path} {lzma_path} -lc1 -lp2'
status = run_command(cmd)
if status != 0:
raise RuntimeError(f'Failed to compress {raw_path}')
return lzma_path.stat().st_size
def decompress_lzma(lzma_util: str, lzma_path: Path, raw_path: Path) -> int:
cmd = f'{lzma_util} d {lzma_path} {raw_path}'
status = run_command(cmd)
if status != 0:
raise RuntimeError(f'Failed to decompress {lzma_path}')
return raw_path.stat().st_size
def resize_kernel_dts(krnl_path: Path):
chunk_num = 0
chunk_size = 64 * 1024
with krnl_path.open(mode='rb+') as f_out:
while data := f_out.read(chunk_size):
if (offset := data.find(b'partition@20000')) > 0:
ofs_part = chunk_num * chunk_size + offset
logger.info('Found DTS partition table at: '
f'0x{ofs_part:08x}')
break
chunk_num += 1
else:
raise RuntimeError('Could not find DTS partition table')
f_out.seek(ofs_part)
data = bytearray(f_out.read(0x100))
if (offset := data.find(b'\xaa\0\x02\0\0\0\x7d\0\0')) > 0:
data[offset+6] |= 0xff
else:
raise RuntimeError('Partition pattern not found')
if (offset := data.find(b'partition@7f0000')) > 0:
data[offset+10] = ord('f')
else:
raise RuntimeError('Partition pattern not found')
if (offset := data.find(b'\xaa\0\x7f\0\0\0\x01\0\0')) > 0:
data[offset+2] |= 0xff
else:
raise RuntimeError('Partition pattern not found')
f_out.seek(ofs_part)
f_out.write(data)
def main():
logger.info('OpenWrt Imagebuilder DTS patcher v0.9')
lzma_util_path = os.getenv('LZMA_UTIL_PATH')
if lzma_util_path is None:
logger.error('Compressor utility path is not set: LZMA_UTIL_PATH')
exit(1)
parser = argparse.ArgumentParser()
parser.add_argument('image', help='OpenWrt kernel image file')
args = parser.parse_args()
krnl_path = Path(args.image)
if krnl_path.is_file() is False:
logger.error(f'Kernel image file does not exist: {krnl_path}')
exit(1)
krnl_size = krnl_path.stat().st_size
logger.info(f'Processing kernel image file: {krnl_path}')
logger.info(f'Origin kernel size: 0x{krnl_size:08x}')
kernel_raw_path = Path(krnl_path.with_suffix('.raw'))
logger.info('Decompressing kernel...')
krnl_raw_size = decompress_lzma(
lzma_util_path, krnl_path, kernel_raw_path)
logger.info(f'Decompressed kernel size: 0x{krnl_raw_size:08x}')
logger.info('Resizing kernel DTS...')
resize_kernel_dts(kernel_raw_path)
krnl_path.rename(krnl_path.with_suffix('.bak'))
logger.info('Compressing kernel...')
krnl_lzma_size = compress_lzma(
lzma_util_path, kernel_raw_path, krnl_path)
logger.info(f'Compressed kernel size: 0x{krnl_lzma_size:08x}')
if krnl_lzma_size > krnl_size:
logger.warning('Re-compressed kernel is bigger than original.')
logger.info('Done')
if __name__ == '__main__':
main()