From 4a043dc9d46e36882afbecb20f479e335549bd4b Mon Sep 17 00:00:00 2001
From: Mikhail Zhilkin <csharper2005@gmail.com>
Date: Sat, 22 Apr 2023 09:35:44 +0000
Subject: [PATCH] ramips: add factory image for TP-Link EC330-G5u v1

This commit adds factory.bin image for TP-Link EC330-G5u v1. This allows
to install OpenWrt without connecting a serial cable (UART).

Installation using factory image
--------------------------------

Tested with "3.16.0 0.9.1 v6037.0 Build 191016 Rel.30619nb" TP-Link
firmware.

1.  Login to the router web interface (http://192.168.0.1/ by default) and
    save running config to "conf.bin" file
2.  Open configuration file in any TP-Link config editor (e.g.
    https://jahed.github.io/tp-link-config-editor/)
3.  Find "DeviceInfo" section and insert a new string "<Description
    val="Modem Router`telnetd -p 1023 -l login`" />" according to the
    following example:
       <DeviceInfo>
          ...
          <Description val="Modem Router`telnetd -p 1023 -l login`" />
          ...
       </DeviceInfo>
4.  Save configuration file and upload changed configuration using stock
    firmware interface
5.  Login using telnet to IP:192.168.0.1 (Username:admin, password:1234)
6.  Run "cat /proc/mtd | grep mtd7"
       a. If the result is 'mtd7: 03000000 00020000 "rootfs" 03400000',
          then install stock firmware using web interface to toggle booted
          firmware image from "os1" to "os0"
       b. If the result is 'mtd7: 03000000 00020000 "rootfs" 00400000',
          then all is ok, go to the next step
7.  Set up a tftp server with OpenWrt factory.bin image (IP:192.168.0.100
    in this example)
8.  Login using telnet to 192.168.0.1
9.  Download OpenWrt factory.bin image from the tftp server:
       cd /tmp
       tftp -g -r factory.bin 192.168.0.100
10. Write OpenWrt factory.bin image:
       dd if=/tmp/factory.bin of=/dev/mtdblock1
11. Power cycle the router

Signed-off-by: Mikhail Zhilkin <csharper2005@gmail.com>
---
 target/linux/ramips/image/mt7621.mk | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
index c362046b8e..24daba43aa 100644
--- a/target/linux/ramips/image/mt7621.mk
+++ b/target/linux/ramips/image/mt7621.mk
@@ -2214,6 +2214,9 @@ define Device/tplink_ec330-g5u-v1
 	uImage-tplink-c9 firmware 'OS IMAGE ($(VERSION_DIST))'
   KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | loader-kernel | \
 	uImage none
+  IMAGES += factory.bin
+  IMAGE/factory.bin := append-kernel | pad-to $$(KERNEL_SIZE) | \
+	append-ubi | check-size
   IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata | check-size
 endef
 TARGET_DEVICES += tplink_ec330-g5u-v1
-- 
2.30.2