[PATCH] ramips: add support for Tozed S12 Plus (UNISOC)

2022-07-27 Thread Ian Pangilinan
 From: Ian Pangilinan 
Date: Sun, 28 July 2022 11:27:00 +0800
Subject: [PATCH] ramips: add support for Tozed S12 Plus (UNISOC)

Tozed S12 Plus (UNISOC) is a Cat.6 LTE CPE. It is known as ZLT S12 Pro 
in some markets.

Product link: https://www.sztozed.com/en/contents/58/84.html

Hardware Highlights:

  * SOC: MT7621A 2C4T @ 880MHz
  * RAM: DDR3 256MB @ 800MHz
  * FLASH: MX25L12805D 16MB SPI NOR
  * WLAN0: MT7612E 5GHz 802.11nac 2x2:2 @ 867Mbps
  * WLAN1: MT7603E 2.4GHz 802.11bgn 2x2:2 @ 300Mbps
  * SWITCH: MT7530 4-port GbE
  * WWAN: UNISOC SL8563 Cat.6 LTE
  * SIM: 1x Mini-SIM 2FF
  * BUTTONS: Reset, WPS, Wi-Fi
  * LEDS: Power (Yellow/Blue), Wi-Fi, Data (Red/Blue), Signal1-5, 
Telephone
  * POWER: 12VDc 2A


There is an existing PR for this device here: 
https://github.com/openwrt/openwrt/pull/10321, but the author seems to 
have abandoned it after a week of no update in reply to reviewer 
suggestions and inquiries. This submission aims to remedy the 
shortcomings of that PR and will be made up-to-date by this author.

The device can be sysupgrade-d directly from the stock firmware. The 
flash layout remains the same between stock and OpenWrt.

This is the flash layout from stock firmware:

0x-0x0003 : "u-boot"
0x0003-0x00038000 : "u-boot-env"
0x0004-0x0005 : "factory"
0x0005-0x0100 : "firmware"
0x-0x00217058 : "kernel"
0x00217058-0x00fb : "rootfs"
0x00c3-0x00fb : "rootfs_data"
0x00038000-0x0004 : "tozed-conf"


Installation Instructions:

Stock firmware runs an old OpenWrt SNAPSHOT release. Installation can be 
either via

a) webui (gain superadmin access, use the sysupgrade image),
b) sysupgrade (gain root shell access, use the sysupgrade image), or
c) tftpboot in the bootloader.

Instructions below are for c). Connect the USB-TTL serial converter as 
follows when facing the board upright on the side of the buttons and 
RJ45 ports, located under the WPS/Wi-Fi buttons from left to right:

(TX) (GND) (RX)

Baud rate is 115200.

1. Connect the computer to the device via ethernet cable. Set a static 
adddress of 10.10.10.3/24 to the wired interface.
2. Start the TFTP server, point it to where the initramfs image is 
located. Rename the image to 'test.bin'.
3. Turn on the device. There will be a three-second delay before the 
default 'Boot system code via flash' is selected.
4. Interrupt the boot process by pressing 1 to 'System Load Linux to 
SDRAM via TFTP'.
5. Press enter to accept the default 'Input device IP (10.10.10.123)'.
6. Press enter to accept the default 'Input server IP (10.10.10.3)'.
7. Press enter to accept the default 'Input Linux Kernel filename ()', 
or enter 'test.bin'.
8. Wait for the initramfs image to finish loading.
9. Reconnect the wired interface to any LAN ports of the device via 
DHCP.
9. Flash the sysupgrade image at 
http://192.168.1.1/cgi-bin/luci/admin/system/flash


What Works?

+ LEDs
+ Buttons
+ Wired LAN and WAN
+ Wireless LAN

What Doesn't?

- Wireless WAN
- Telephone

The only non-configurable LEDs are those from each of the switch ports. 
They function as intended. I set the yellow and blue power LEDs as 
status indicators for OpenWrt. There is also an exported GPIO to reset 
the WWAN.

Support fgor WWAN could come at a later date. I have setup LAN4 of the 
device as WAN.

Signed-off-by: Ian Pangilinan 
---
  .../dts/mt7621_tozed_s12-unisoc-plus.dts (new) | 278 
+
  target/linux/ramips/image/mt7621.mk|  10 +
  .../mt7621/base-files/etc/board.d/02_network   |   1 +
  3 files changed, 289 insertions(+), 0 deletion(-)
  create mode 100644 target/linux/ramips/dts/mt7621_notion_r281.dts
  create mode 100644 
target/linux/ramips/dts/mt7621_tozed_s12-unisoc-plus.dts
diff --git a/target/linux/ramips/dts/mt7621_tozed_s12-unisoc-plus.dts 
b/target/linux/ramips/dts/mt7621_tozed_s12-unisoc-plus.dts
new file mode 100644
index 00..b4697ee63d
--- /dev/null
+++ b/target/linux/ramips/dts/mt7621_tozed_s12-unisoc-plus.dts
@@ -0,0 +1,278 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+// Copyright (C) 2022, Ian Pangilinan 
+
+#include "mt7621.dtsi"
+
+#include 
+#include 
+
+/ {
+   compatible = "tozed,s12-unisoc-plus", "mediatek,mt7621-soc";
+   model = "Tozed S12 Plus (UNISOC)";
+
+   chosen {
+   bootargs = "console=ttyS0,115200";
+   };
+
+   aliases {
+   led-boot = _power0;
+   led-failsafe = _power0;
+   led-running = _power1;
+   led-upgrade = _power0;
+   label-mac-device = 
+   };
+
+   gpio-export {
+   compatible = "gpio-export";
+   #size-cells = <0>;
+
+   /* external LTE antenna 1 */
+   ext_ant0 {
+   gpio-export,name = "ext_ant0";
+   gpio-export,input = <0>;
+   gpios = < 6 GPIO_ACTIVE_HIGH>;
+  

[PATCH firmware-utils v2 1/2] mkh3cimg: add image tool for H3C devices

2022-07-27 Thread Jan Hoffmann
Firmware images for these devices can contain multiple files, such as
application files or bootloader images. This tool only creates images
with a single application file. In the case of OpenWrt, this is going
to contain the kernel image.

Compressed files are supported by the image format, in this case the
supplied input file needs to be a 7z archive with LZMA compression.

Signed-off-by: Jan Hoffmann 
---
 CMakeLists.txt |   1 +
 src/mkh3cimg.c | 366 +
 2 files changed, 367 insertions(+)
 create mode 100644 src/mkh3cimg.c

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e6592bccb157..daf442681d66 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,6 +65,7 @@ FW_UTIL(mkdniimg "" "" "")
 FW_UTIL(mkedimaximg "" "" "")
 FW_UTIL(mkfwimage "" "-Wextra -D_FILE_OFFSET_BITS=64" "${ZLIB_LIBRARIES}")
 FW_UTIL(mkfwimage2 "" "" "${ZLIB_LIBRARIES}")
+FW_UTIL(mkh3cimg "" "" "")
 FW_UTIL(mkheader_gemtek "" "" "${ZLIB_LIBRARIES}")
 FW_UTIL(mkhilinkfw "" "" "${OPENSSL_CRYPTO_LIBRARIES}")
 FW_UTIL(mkmerakifw src/sha1.c "" "")
diff --git a/src/mkh3cimg.c b/src/mkh3cimg.c
new file mode 100644
index ..d5660537f196
--- /dev/null
+++ b/src/mkh3cimg.c
@@ -0,0 +1,366 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#if !defined(__BYTE_ORDER)
+#error "Unknown byte order"
+#endif
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define cpu_to_be16(x)  (x)
+#define cpu_to_be32(x)  (x)
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+#define cpu_to_be16(x)  bswap_16(x)
+#define cpu_to_be32(x)  bswap_32(x)
+#else
+#error "Unsupported endianness"
+#endif
+
+
+#define IMAGE_VERSION1
+#define FILE_VERSION 1
+#define FILE_DESCRIPTION "OpenWrt"
+#define FILE_TYPE_MASK   0x1
+
+
+#define PACKAGE_FLAG 2
+
+#define FILE_TYPE_APPLICATION0x0400
+
+#define VERSION_OFFSET_INVALID   0x
+
+#define COMPRESSION_TYPE_NONE0x
+#define COMPRESSION_TYPE_7Z  0x0002
+
+
+struct file_header {
+   uint8_t res1[4];
+
+   uint32_t header_crc;
+
+   uint32_t file_type;
+   uint32_t version;
+   uint32_t product_id;
+   uint32_t device_id;
+
+   uint32_t length_unpadded;
+
+   uint32_t version_offset;
+
+   uint16_t year;
+   uint8_t month;
+   uint8_t day;
+   uint8_t res2[1];
+   uint8_t hour;
+   uint8_t minute;
+   uint8_t second;
+
+   uint8_t res3[64];
+
+   char description[224];
+
+   uint32_t length;
+
+   uint32_t file_crc;
+
+   uint32_t compression_type;
+} __attribute__ ((packed));
+
+struct file_desc {
+   uint32_t file_type;
+   uint32_t offset;
+   uint32_t length;
+   uint32_t file_crc;
+   uint32_t version;
+   uint32_t type_mask;
+} __attribute__ ((packed));
+
+struct image_header {
+   uint32_t version;
+
+   uint32_t file_count;
+
+   uint32_t product_id;
+   uint32_t device_id;
+
+   uint16_t year;
+   uint8_t month;
+   uint8_t day;
+   uint8_t res1[1];
+   uint8_t hour;
+   uint8_t minute;
+   uint8_t second;
+
+   uint16_t package_crc;
+   uint16_t package_flag;
+
+   uint32_t length;
+
+   struct file_desc files[128];
+
+   /* RSA signature, not required */
+   uint8_t res2[3072];
+
+   uint32_t header_crc;
+} __attribute__ ((packed));
+
+
+static void *buf;
+static size_t buflen;
+
+static size_t length_unpadded;
+static size_t length;
+
+
+static uint32_t crc16_xmodem(char *buf, size_t len) {
+   uint32_t poly = 0x1021;
+   uint32_t crc = 0;
+   char b;
+   int i, j;
+
+   for (i = 0; i < len; i++) {
+   b = buf[i];
+   crc = crc ^ (b << 8);
+
+   for (j = 0; j < 8; j++) {
+   crc = crc << 1;
+   if (crc & 0x1) {
+   crc = (crc ^ poly) & 0x;
+   }
+   }
+   }
+
+   return crc;
+}
+
+static int create_buffer_and_read_file(char *filename) {
+   FILE *f;
+
+   f = fopen(filename, "r");
+   if (f == NULL) {
+   fprintf(stderr, "failed to open input file\n");
+   goto err;
+   }
+
+   fseek(f, 0L, SEEK_END);
+   length_unpadded = ftell(f);
+   rewind(f);
+
+   length = length_unpadded;
+   if (length_unpadded % 8 != 0) {
+   length += 8 - length_unpadded % 8;
+   }
+
+   buflen = sizeof(struct file_header) + sizeof(struct image_header) + 
length;
+   buf = malloc(buflen);
+   if (!buf) {
+   fprintf(stderr, "failed to allocate buffer\n");
+   goto err_close;
+   }
+
+   memset(buf, 0, buflen);
+
+   if (fread(buf + sizeof(struct file_header) + sizeof(struct 
image_header), length_unpadded, 1, f) != 1) {
+   fprintf(stderr, "failed to 

[PATCH firmware-utils v2 2/2] mkh3cvfs: add filesystem tool for H3C devices

2022-07-27 Thread Jan Hoffmann
The bootloader can only boot images from a custom filesystem which
normally spans most of the flash on the device. This tool creates a
filesystem image containing a single file (which should be a firmware
image created using mkh3cimg).

The size of the filesystem is hardcoded in the bootloader. However, an
image that is only slightly larger than its content is sufficient, as
long as no write operations are performed in the bootloader menu. This
allows to append further data (i.e. rootfs) after the end of the
filesystem image.

Signed-off-by: Jan Hoffmann 
---
 CMakeLists.txt |   1 +
 src/mkh3cvfs.c | 426 +
 2 files changed, 427 insertions(+)
 create mode 100644 src/mkh3cvfs.c

diff --git a/CMakeLists.txt b/CMakeLists.txt
index daf442681d66..9b70226b8dc1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,6 +66,7 @@ FW_UTIL(mkedimaximg "" "" "")
 FW_UTIL(mkfwimage "" "-Wextra -D_FILE_OFFSET_BITS=64" "${ZLIB_LIBRARIES}")
 FW_UTIL(mkfwimage2 "" "" "${ZLIB_LIBRARIES}")
 FW_UTIL(mkh3cimg "" "" "")
+FW_UTIL(mkh3cvfs "" "" "")
 FW_UTIL(mkheader_gemtek "" "" "${ZLIB_LIBRARIES}")
 FW_UTIL(mkhilinkfw "" "" "${OPENSSL_CRYPTO_LIBRARIES}")
 FW_UTIL(mkmerakifw src/sha1.c "" "")
diff --git a/src/mkh3cvfs.c b/src/mkh3cvfs.c
new file mode 100644
index ..e5b3f353c920
--- /dev/null
+++ b/src/mkh3cvfs.c
@@ -0,0 +1,426 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#if !defined(__BYTE_ORDER)
+#error "Unknown byte order"
+#endif
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define cpu_to_be16(x)  (x)
+#define cpu_to_be32(x)  (x)
+#define be16_to_cpu(x)  (x)
+#define be32_to_cpu(x)  (x)
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+#define cpu_to_be16(x)  bswap_16(x)
+#define cpu_to_be32(x)  bswap_32(x)
+#define be16_to_cpu(x)  bswap_16(x)
+#define be32_to_cpu(x)  bswap_32(x)
+#else
+#error "Unsupported endianness"
+#endif
+
+
+#define FAT_PTR_FLAGS_GET(x) ((be32_to_cpu(x) & 0xff00) >> 24)
+#define FAT_PTR_FLAGS_SET(x, y)  (x = cpu_to_be32((be32_to_cpu(x) & 
0x00ff) | ((y & 0x00ff) << 24)))
+
+#define FAT_PTR_VAL_GET(x) (be32_to_cpu(x) & 0x00ff)
+#define FAT_PTR_VAL_SET(x, y)  (x = cpu_to_be32((be32_to_cpu(x) & 0xff00) 
| (y & 0x00ff)))
+
+
+struct fat_entry {
+   /* first byte contains flags */
+   uint32_t previous;
+
+   /* first byte is reserved */
+   uint32_t next;
+} __attribute__ ((packed));
+
+struct file_entry {
+   uint8_t flags;
+
+   uint8_t res0[5];
+
+   uint16_t year;
+   uint8_t month;
+   uint8_t day;
+   uint8_t hour;
+   uint8_t minute;
+   uint8_t second;
+
+   uint8_t res1[3];
+
+   uint32_t length;
+
+   uint32_t parent_block;
+   uint16_t parent_index;
+
+   uint8_t res2[2];
+
+   uint32_t data_block;
+
+   char name[96];
+} __attribute__ ((packed));
+
+
+#define ERASEBLOCK_SIZE   0x1
+#define BLOCK_SIZE0x400
+
+#define BLOCKS_PER_ERASEBLOCK   (ERASEBLOCK_SIZE / BLOCK_SIZE)
+#define FILE_ENTRIES_PER_BLOCK  (BLOCK_SIZE / sizeof(struct file_entry))
+
+
+#define FLAG_FREE   0x80
+#define FLAG_VALID  0x40
+#define FLAG_INVALID0x20
+#define FLAG_HIDE   0x10
+#define FLAG_DIRECTORY  0x02
+#define FLAG_READONLY   0x01
+
+
+static FILE *f;
+static size_t file_size = 0;
+
+static int dir_block = 1;
+static int dir_count = 0;
+
+static int next_data_block = 2;
+
+
+static inline size_t fat_entry_offset(int block) {
+   return ERASEBLOCK_SIZE * (block / (BLOCKS_PER_ERASEBLOCK-1))
+   + sizeof(struct fat_entry) * (block % 
(BLOCKS_PER_ERASEBLOCK-1));
+}
+
+static inline size_t block_offset(int block) {
+   return ERASEBLOCK_SIZE * (block / (BLOCKS_PER_ERASEBLOCK-1))
+   + BLOCK_SIZE * (1 + (block % (BLOCKS_PER_ERASEBLOCK-1)));
+}
+
+static int init_eraseblock(size_t offset) {
+   size_t end = offset - (offset % ERASEBLOCK_SIZE) + ERASEBLOCK_SIZE;
+   char *fill = "\xff";
+   int i;
+
+   while (file_size < end) {
+   if (fseek(f, file_size, SEEK_SET)) {
+   fprintf(stderr, "failed to seek to end\n");
+   return -1;
+   }
+
+   for (i = 0; i < ERASEBLOCK_SIZE; i++) {
+   if (fwrite(fill, 1, 1, f) != 1) {
+   fprintf(stderr, "failed to write eraseblock\n");
+   return -1;
+   }
+   }
+
+   file_size += ERASEBLOCK_SIZE;
+   }
+
+   return 0;
+}
+
+static inline void init_fat_entry(struct fat_entry *out) {
+   memset(out, '\xff', sizeof(struct fat_entry));
+}
+
+static int read_fat_entry(struct fat_entry *out, int block) {
+   size_t offset = fat_entry_offset(block);
+
+   if (init_eraseblock(offset)) {
+   return -1;
+   }
+
+   if (fseek(f, offset, 

[PATCH firmware-utils v2 0/2] add tools for H3C devices

2022-07-27 Thread Jan Hoffmann
This adds tools for creating firmware and filesystem images for H3C
devices, such as HPE 1920 series switches.

This is a prerequisite for the series "realtek: add HPE 1920 support".

Changes in v2:
 - split into separate commits for each tool and add more detailed
   commit messages
 - clean up numbering of reserved struct fields in mkh3cvfs

Jan Hoffmann (2):
  mkh3cimg: add image tool for H3C devices
  mkh3cvfs: add filesystem tool for H3C devices

 CMakeLists.txt |   2 +
 src/mkh3cimg.c | 366 ++
 src/mkh3cvfs.c | 426 +
 3 files changed, 794 insertions(+)
 create mode 100644 src/mkh3cimg.c
 create mode 100644 src/mkh3cvfs.c

-- 
2.36.1


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [PATCH firmware-utils] mkh3cimg/mkh3cvfs: add image/filesystem tools for H3C devices

2022-07-27 Thread Sander Vanheule
On Sat, 2022-07-23 at 22:49 +0200, Jan Hoffmann wrote:
> mkh3cimg creates a firmware image. Firmware images for these devices can
> contain multiple files, but this tool is limited to creating images with
> a single application file. In the case of OpenWrt, this is going to
> contain the kernel image. Compressed files are supported by the image
> format, in this case the supplied input file needs to be a 7z archive
> with LZMA compression.
> 
> mkh3cvfs creates a VFS filesystem image. The bootloader can only boot
> images from this filesystem which normally spans most of the flash on
> the device. This tool creates a filesystem image containing a single
> file. While the size of the filesystem is hardcoded in the bootloader,
> an image that is only slightly larger than its content is sufficient,
> as long as no write operations are to be performed on it. This allows to
> append further data (i.e. rootfs) after the end of the generated image.

Since these are two different utilities, could you split this into separate
patches? Nearly 800 lines of code is a bit much to review in one go...

Best,
Sander

> 
> Signed-off-by: Jan Hoffmann 
> ---
> This patch is a prerequisite for HPE 1920 support.
> 
>  CMakeLists.txt |   2 +
>  src/mkh3cimg.c | 366 ++
>  src/mkh3cvfs.c | 426 +
>  3 files changed, 794 insertions(+)
>  create mode 100644 src/mkh3cimg.c
>  create mode 100644 src/mkh3cvfs.c
> 
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index e6592bccb157..9b70226b8dc1 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -65,6 +65,8 @@ FW_UTIL(mkdniimg "" "" "")
>  FW_UTIL(mkedimaximg "" "" "")
>  FW_UTIL(mkfwimage "" "-Wextra -D_FILE_OFFSET_BITS=64" "${ZLIB_LIBRARIES}")
>  FW_UTIL(mkfwimage2 "" "" "${ZLIB_LIBRARIES}")
> +FW_UTIL(mkh3cimg "" "" "")
> +FW_UTIL(mkh3cvfs "" "" "")
>  FW_UTIL(mkheader_gemtek "" "" "${ZLIB_LIBRARIES}")
>  FW_UTIL(mkhilinkfw "" "" "${OPENSSL_CRYPTO_LIBRARIES}")
>  FW_UTIL(mkmerakifw src/sha1.c "" "")
> diff --git a/src/mkh3cimg.c b/src/mkh3cimg.c
> new file mode 100644
> index ..d5660537f196
> --- /dev/null
> +++ b/src/mkh3cimg.c
> @@ -0,0 +1,366 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +
> +#if !defined(__BYTE_ORDER)
> +#error "Unknown byte order"
> +#endif
> +
> +#if __BYTE_ORDER == __BIG_ENDIAN
> +#define cpu_to_be16(x)  (x)
> +#define cpu_to_be32(x)  (x)
> +#elif __BYTE_ORDER == __LITTLE_ENDIAN
> +#define cpu_to_be16(x)  bswap_16(x)
> +#define cpu_to_be32(x)  bswap_32(x)
> +#else
> +#error "Unsupported endianness"
> +#endif
> +
> +
> +#define IMAGE_VERSION    1
> +#define FILE_VERSION 1
> +#define FILE_DESCRIPTION "OpenWrt"
> +#define FILE_TYPE_MASK   0x1
> +
> +
> +#define PACKAGE_FLAG 2
> +
> +#define FILE_TYPE_APPLICATION    0x0400
> +
> +#define VERSION_OFFSET_INVALID   0x
> +
> +#define COMPRESSION_TYPE_NONE    0x
> +#define COMPRESSION_TYPE_7Z  0x0002
> +
> +
> +struct file_header {
> +   uint8_t res1[4];
> +
> +   uint32_t header_crc;
> +
> +   uint32_t file_type;
> +   uint32_t version;
> +   uint32_t product_id;
> +   uint32_t device_id;
> +
> +   uint32_t length_unpadded;
> +
> +   uint32_t version_offset;
> +
> +   uint16_t year;
> +   uint8_t month;
> +   uint8_t day;
> +   uint8_t res2[1];
> +   uint8_t hour;
> +   uint8_t minute;
> +   uint8_t second;
> +
> +   uint8_t res3[64];
> +
> +   char description[224];
> +
> +   uint32_t length;
> +
> +   uint32_t file_crc;
> +
> +   uint32_t compression_type;
> +} __attribute__ ((packed));
> +
> +struct file_desc {
> +   uint32_t file_type;
> +   uint32_t offset;
> +   uint32_t length;
> +   uint32_t file_crc;
> +   uint32_t version;
> +   uint32_t type_mask;
> +} __attribute__ ((packed));
> +
> +struct image_header {
> +   uint32_t version;
> +
> +   uint32_t file_count;
> +
> +   uint32_t product_id;
> +   uint32_t device_id;
> +
> +   uint16_t year;
> +   uint8_t month;
> +   uint8_t day;
> +   uint8_t res1[1];
> +   uint8_t hour;
> +   uint8_t minute;
> +   uint8_t second;
> +
> +   uint16_t package_crc;
> +   uint16_t package_flag;
> +
> +   uint32_t length;
> +
> +   struct file_desc files[128];
> +
> +   /* RSA signature, not required */
> +   uint8_t res2[3072];
> +
> +   uint32_t header_crc;
> +} __attribute__ ((packed));
> +
> +
> +static void *buf;
> +static size_t buflen;
> +
> +static size_t length_unpadded;
> +static size_t length;
> +
> +
> +static uint32_t crc16_xmodem(char *buf, size_t len) {
> +   uint32_t poly = 0x1021;
> +   uint32_t crc = 0;
> +   char b;
> +   int i, j;
> +
> +   for (i = 0; i < 

Re: [PATCH] airoha: Add new target platform

2022-07-27 Thread Robert Marko
On Wed, 27 Jul 2022 at 14:50, Hauke Mehrtens  wrote:
>
> Hi Daniel,
>
> Is it possible to buy devices with this SoC in the retail market or on ebay?
>
> On 7/27/22 13:57, Daniel Danzberger wrote:
> > Airoha is a new ARM platform based on Cortex A7 which has recently been
> > merged into linux-next.

Is this the one where A53 core is being limited to AArch32 by the BootROM?

Regards,
Robert
>
> The device tree says it is a arm,cortex-a53, see
> target/linux/airoha/dts/en7523.dtsi
>
> > This support is based mostly on those linux-next commits backported
> > for kernel 5.15.
> >
> > Patches:
> > 1 - platform support = linux-next
> > 2 - clock driver = linux-next
> > 3 - gpio driver = linux-next
> > 4 - linux,usable-memory-range dts support = linux-next
> > 5 - mtd spinand driver
> > 6 - spi driver
> > 7 - pci driver (kconfig only, uses mediatek PCI) = linux-next
> >
> > Still missing:
> > - Ethernet driver
> > - Sysupgrade support
> >
> > A.t.m there exists one subtarget EN7523 with only one evaluation
> > board.
>
> How close is the hardware to other medaitek SoCs? Should we add this as
> a subtarget to mediatek?
>
> >
> > The initramfs can be run with the following commands from u-boot:
> > -
> > u-boot> setenv bootfile \
> >   openwrt-airoha-airoha_en7523-evb-initramfs-kernel.bin
> > u-boot> tftpboot
> > u-boot> bootm 0x8180
> > -
> >
> > Signed-off-by: Daniel Danzberger 
> > ---
> >   target/linux/airoha/Makefile  |  15 +
> >   target/linux/airoha/config-5.15   | 278 ++
> >   target/linux/airoha/dts/en7523-evb.dts|  73 
> >   target/linux/airoha/dts/en7523.dtsi   | 219 +++
> >   .../files/arch/arm/mach-airoha/Makefile   |   2 +
> >   .../files/arch/arm/mach-airoha/airoha.c   |  16 +
> >   .../airoha/files/drivers/clk/clk-en7523.c | 351 ++
> >   .../airoha/files/drivers/gpio/gpio-en7523.c   | 137 +++
> >   .../include/dt-bindings/clock/en7523-clk.h|  17 +
> >   target/linux/airoha/image/Makefile|  37 ++
> >   target/linux/airoha/image/en7523.mk   |   0
> >   .../0001-add-airoha-platform.patch|  35 ++
> >   .../0002-add-airoha-en7523-clk-driver.patch   |  32 ++
> >   .../0003-add-airoha-en7523-gpio-driver.patch  |  33 ++
> >   ...press-Parse-linux-usable-memory-rang.patch | 111 ++
> >   ...nd-Add-support-for-Etron-EM73D044VCx.patch | 137 +++
> >   ...for-the-Airoha-EN7523-SoC-SPI-contro.patch | 346 +
> >   ...iatek-Allow-building-for-ARCH_AIROHA.patch |  35 ++
> >   18 files changed, 1874 insertions(+)
> >   create mode 100644 target/linux/airoha/Makefile
> >   create mode 100644 target/linux/airoha/config-5.15
> >   create mode 100644 target/linux/airoha/dts/en7523-evb.dts
> >   create mode 100644 target/linux/airoha/dts/en7523.dtsi
> >   create mode 100644 target/linux/airoha/files/arch/arm/mach-airoha/Makefile
> >   create mode 100644 target/linux/airoha/files/arch/arm/mach-airoha/airoha.c
> >   create mode 100644 target/linux/airoha/files/drivers/clk/clk-en7523.c
> >   create mode 100644 target/linux/airoha/files/drivers/gpio/gpio-en7523.c
> >   create mode 100644 
> > target/linux/airoha/files/include/dt-bindings/clock/en7523-clk.h
> >   create mode 100644 target/linux/airoha/image/Makefile
> >   create mode 100644 target/linux/airoha/image/en7523.mk
> >   create mode 100644 
> > target/linux/airoha/patches-5.15/0001-add-airoha-platform.patch
> >   create mode 100644 
> > target/linux/airoha/patches-5.15/0002-add-airoha-en7523-clk-driver.patch
> >   create mode 100644 
> > target/linux/airoha/patches-5.15/0003-add-airoha-en7523-gpio-driver.patch
> >   create mode 100644 
> > target/linux/airoha/patches-5.15/0004-ARM-9124-1-uncompress-Parse-linux-usable-memory-rang.patch
> >   create mode 100644 
> > target/linux/airoha/patches-5.15/0005-mtd-spinand-Add-support-for-Etron-EM73D044VCx.patch
> >   create mode 100644 
> > target/linux/airoha/patches-5.15/0006-spi-Add-support-for-the-Airoha-EN7523-SoC-SPI-contro.patch
> >   create mode 100644 
> > target/linux/airoha/patches-5.15/0007-PCI-mediatek-Allow-building-for-ARCH_AIROHA.patch
> >
> > diff --git a/target/linux/airoha/Makefile b/target/linux/airoha/Makefile
> > new file mode 100644
> > index 00..723bec8cd4
> > --- /dev/null
> > +++ b/target/linux/airoha/Makefile
> > @@ -0,0 +1,15 @@
> > +include $(TOPDIR)/rules.mk
> > +
> > +ARCH:=arm
> > +BOARD:=airoha
> > +BOARDNAME:=Airoha ARM
> > +CPU_TYPE:=cortex-a7
> > +FEATURES:=dt squashfs nand ramdisk gpio source-only
> > +
> > +KERNEL_PATCHVER:=5.15
> > +
> > +include $(INCLUDE_DIR)/target.mk
> > +
> > +KERNELNAME:=Image dtbs
> > +
> > +$(eval $(call BuildTarget))
> > diff --git a/target/linux/airoha/config-5.15 
> > b/target/linux/airoha/config-5.15
> > new file mode 100644
> > index 00..6717e8d19b
> > --- /dev/null
> > +++ b/target/linux/airoha/config-5.15
> > @@ -0,0 +1,278 @@
> .
> > +CONFIG_CACHE_L2X0=y
> > +# 

Re: [PATCH] airoha: Add new target platform

2022-07-27 Thread Hauke Mehrtens

Hi Daniel,

Is it possible to buy devices with this SoC in the retail market or on ebay?

On 7/27/22 13:57, Daniel Danzberger wrote:

Airoha is a new ARM platform based on Cortex A7 which has recently been
merged into linux-next.


The device tree says it is a arm,cortex-a53, see 
target/linux/airoha/dts/en7523.dtsi



This support is based mostly on those linux-next commits backported
for kernel 5.15.

Patches:
1 - platform support = linux-next
2 - clock driver = linux-next
3 - gpio driver = linux-next
4 - linux,usable-memory-range dts support = linux-next
5 - mtd spinand driver
6 - spi driver
7 - pci driver (kconfig only, uses mediatek PCI) = linux-next

Still missing:
- Ethernet driver
- Sysupgrade support

A.t.m there exists one subtarget EN7523 with only one evaluation
board.


How close is the hardware to other medaitek SoCs? Should we add this as 
a subtarget to mediatek?




The initramfs can be run with the following commands from u-boot:
-
u-boot> setenv bootfile \
openwrt-airoha-airoha_en7523-evb-initramfs-kernel.bin
u-boot> tftpboot
u-boot> bootm 0x8180
-

Signed-off-by: Daniel Danzberger 
---
  target/linux/airoha/Makefile  |  15 +
  target/linux/airoha/config-5.15   | 278 ++
  target/linux/airoha/dts/en7523-evb.dts|  73 
  target/linux/airoha/dts/en7523.dtsi   | 219 +++
  .../files/arch/arm/mach-airoha/Makefile   |   2 +
  .../files/arch/arm/mach-airoha/airoha.c   |  16 +
  .../airoha/files/drivers/clk/clk-en7523.c | 351 ++
  .../airoha/files/drivers/gpio/gpio-en7523.c   | 137 +++
  .../include/dt-bindings/clock/en7523-clk.h|  17 +
  target/linux/airoha/image/Makefile|  37 ++
  target/linux/airoha/image/en7523.mk   |   0
  .../0001-add-airoha-platform.patch|  35 ++
  .../0002-add-airoha-en7523-clk-driver.patch   |  32 ++
  .../0003-add-airoha-en7523-gpio-driver.patch  |  33 ++
  ...press-Parse-linux-usable-memory-rang.patch | 111 ++
  ...nd-Add-support-for-Etron-EM73D044VCx.patch | 137 +++
  ...for-the-Airoha-EN7523-SoC-SPI-contro.patch | 346 +
  ...iatek-Allow-building-for-ARCH_AIROHA.patch |  35 ++
  18 files changed, 1874 insertions(+)
  create mode 100644 target/linux/airoha/Makefile
  create mode 100644 target/linux/airoha/config-5.15
  create mode 100644 target/linux/airoha/dts/en7523-evb.dts
  create mode 100644 target/linux/airoha/dts/en7523.dtsi
  create mode 100644 target/linux/airoha/files/arch/arm/mach-airoha/Makefile
  create mode 100644 target/linux/airoha/files/arch/arm/mach-airoha/airoha.c
  create mode 100644 target/linux/airoha/files/drivers/clk/clk-en7523.c
  create mode 100644 target/linux/airoha/files/drivers/gpio/gpio-en7523.c
  create mode 100644 
target/linux/airoha/files/include/dt-bindings/clock/en7523-clk.h
  create mode 100644 target/linux/airoha/image/Makefile
  create mode 100644 target/linux/airoha/image/en7523.mk
  create mode 100644 
target/linux/airoha/patches-5.15/0001-add-airoha-platform.patch
  create mode 100644 
target/linux/airoha/patches-5.15/0002-add-airoha-en7523-clk-driver.patch
  create mode 100644 
target/linux/airoha/patches-5.15/0003-add-airoha-en7523-gpio-driver.patch
  create mode 100644 
target/linux/airoha/patches-5.15/0004-ARM-9124-1-uncompress-Parse-linux-usable-memory-rang.patch
  create mode 100644 
target/linux/airoha/patches-5.15/0005-mtd-spinand-Add-support-for-Etron-EM73D044VCx.patch
  create mode 100644 
target/linux/airoha/patches-5.15/0006-spi-Add-support-for-the-Airoha-EN7523-SoC-SPI-contro.patch
  create mode 100644 
target/linux/airoha/patches-5.15/0007-PCI-mediatek-Allow-building-for-ARCH_AIROHA.patch

diff --git a/target/linux/airoha/Makefile b/target/linux/airoha/Makefile
new file mode 100644
index 00..723bec8cd4
--- /dev/null
+++ b/target/linux/airoha/Makefile
@@ -0,0 +1,15 @@
+include $(TOPDIR)/rules.mk
+
+ARCH:=arm
+BOARD:=airoha
+BOARDNAME:=Airoha ARM
+CPU_TYPE:=cortex-a7
+FEATURES:=dt squashfs nand ramdisk gpio source-only
+
+KERNEL_PATCHVER:=5.15
+
+include $(INCLUDE_DIR)/target.mk
+
+KERNELNAME:=Image dtbs
+
+$(eval $(call BuildTarget))
diff --git a/target/linux/airoha/config-5.15 b/target/linux/airoha/config-5.15
new file mode 100644
index 00..6717e8d19b
--- /dev/null
+++ b/target/linux/airoha/config-5.15
@@ -0,0 +1,278 @@

.

+CONFIG_CACHE_L2X0=y
+# CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE is not set
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y


Why do you select CONFIG_CC_OPTIMIZE_FOR_SIZE ? all other targets except 
the mediatek/mt7629 use CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE.



+CONFIG_CHR_DEV_SCH=y

Why do you need CONFIG_CHR_DEV_SCH?


+CONFIG_CLONE_BACKWARDS=y
+CONFIG_CMDLINE="rootfstype=squashfs,jffs2"
+CONFIG_CMDLINE_FROM_BOOTLOADER=y

.

+CONFIG_DCACHE_WORD_ACCESS=y
+CONFIG_DEBUG_LL_INCLUDE="mach/debug-macro.S"
+CONFIG_DEBUG_MISC=y
+CONFIG_DEFAULT_HOSTNAME="(airoha)"


Setting CONFIG_DEFAULT_HOSTNAME looks wrong.


+CONFIG_DMA_OPS=y

Re: [PATCH netifd] interface: support "zone" config option

2022-07-27 Thread Felix Fietkau


On 27.07.22 07:34, Rafał Miłecki wrote:

From: Rafał Miłecki 

Many protocol handlers support "zone" option independently and they pass
it in the "data". Then it's read e.g. by a firewall[34].

Add support for "zone" directly to the netifd so:
1. It works for all protocols
2. Handlers don't have to duplicate code

Signed-off-by: Rafał Miłecki 
Good idea! I think once this is merged, we should also change the 
default network/firewall config to make use of this and reference zones 
from interfaces instead of the other way around.


- Felix


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH] airoha: Add new target platform

2022-07-27 Thread Daniel Danzberger
Airoha is a new ARM platform based on Cortex A7 which has recently been
merged into linux-next.

This support is based mostly on those linux-next commits backported
for kernel 5.15.

Patches:
1 - platform support = linux-next
2 - clock driver = linux-next
3 - gpio driver = linux-next
4 - linux,usable-memory-range dts support = linux-next
5 - mtd spinand driver
6 - spi driver
7 - pci driver (kconfig only, uses mediatek PCI) = linux-next

Still missing:
- Ethernet driver
- Sysupgrade support

A.t.m there exists one subtarget EN7523 with only one evaluation
board.

The initramfs can be run with the following commands from u-boot:
-
u-boot> setenv bootfile \
openwrt-airoha-airoha_en7523-evb-initramfs-kernel.bin
u-boot> tftpboot
u-boot> bootm 0x8180
-

Signed-off-by: Daniel Danzberger 
---
 target/linux/airoha/Makefile  |  15 +
 target/linux/airoha/config-5.15   | 278 ++
 target/linux/airoha/dts/en7523-evb.dts|  73 
 target/linux/airoha/dts/en7523.dtsi   | 219 +++
 .../files/arch/arm/mach-airoha/Makefile   |   2 +
 .../files/arch/arm/mach-airoha/airoha.c   |  16 +
 .../airoha/files/drivers/clk/clk-en7523.c | 351 ++
 .../airoha/files/drivers/gpio/gpio-en7523.c   | 137 +++
 .../include/dt-bindings/clock/en7523-clk.h|  17 +
 target/linux/airoha/image/Makefile|  37 ++
 target/linux/airoha/image/en7523.mk   |   0
 .../0001-add-airoha-platform.patch|  35 ++
 .../0002-add-airoha-en7523-clk-driver.patch   |  32 ++
 .../0003-add-airoha-en7523-gpio-driver.patch  |  33 ++
 ...press-Parse-linux-usable-memory-rang.patch | 111 ++
 ...nd-Add-support-for-Etron-EM73D044VCx.patch | 137 +++
 ...for-the-Airoha-EN7523-SoC-SPI-contro.patch | 346 +
 ...iatek-Allow-building-for-ARCH_AIROHA.patch |  35 ++
 18 files changed, 1874 insertions(+)
 create mode 100644 target/linux/airoha/Makefile
 create mode 100644 target/linux/airoha/config-5.15
 create mode 100644 target/linux/airoha/dts/en7523-evb.dts
 create mode 100644 target/linux/airoha/dts/en7523.dtsi
 create mode 100644 target/linux/airoha/files/arch/arm/mach-airoha/Makefile
 create mode 100644 target/linux/airoha/files/arch/arm/mach-airoha/airoha.c
 create mode 100644 target/linux/airoha/files/drivers/clk/clk-en7523.c
 create mode 100644 target/linux/airoha/files/drivers/gpio/gpio-en7523.c
 create mode 100644 
target/linux/airoha/files/include/dt-bindings/clock/en7523-clk.h
 create mode 100644 target/linux/airoha/image/Makefile
 create mode 100644 target/linux/airoha/image/en7523.mk
 create mode 100644 
target/linux/airoha/patches-5.15/0001-add-airoha-platform.patch
 create mode 100644 
target/linux/airoha/patches-5.15/0002-add-airoha-en7523-clk-driver.patch
 create mode 100644 
target/linux/airoha/patches-5.15/0003-add-airoha-en7523-gpio-driver.patch
 create mode 100644 
target/linux/airoha/patches-5.15/0004-ARM-9124-1-uncompress-Parse-linux-usable-memory-rang.patch
 create mode 100644 
target/linux/airoha/patches-5.15/0005-mtd-spinand-Add-support-for-Etron-EM73D044VCx.patch
 create mode 100644 
target/linux/airoha/patches-5.15/0006-spi-Add-support-for-the-Airoha-EN7523-SoC-SPI-contro.patch
 create mode 100644 
target/linux/airoha/patches-5.15/0007-PCI-mediatek-Allow-building-for-ARCH_AIROHA.patch

diff --git a/target/linux/airoha/Makefile b/target/linux/airoha/Makefile
new file mode 100644
index 00..723bec8cd4
--- /dev/null
+++ b/target/linux/airoha/Makefile
@@ -0,0 +1,15 @@
+include $(TOPDIR)/rules.mk
+
+ARCH:=arm
+BOARD:=airoha
+BOARDNAME:=Airoha ARM
+CPU_TYPE:=cortex-a7
+FEATURES:=dt squashfs nand ramdisk gpio source-only
+
+KERNEL_PATCHVER:=5.15
+
+include $(INCLUDE_DIR)/target.mk
+
+KERNELNAME:=Image dtbs
+
+$(eval $(call BuildTarget))
diff --git a/target/linux/airoha/config-5.15 b/target/linux/airoha/config-5.15
new file mode 100644
index 00..6717e8d19b
--- /dev/null
+++ b/target/linux/airoha/config-5.15
@@ -0,0 +1,278 @@
+CONFIG_ALIGNMENT_TRAP=y
+CONFIG_ARCH_32BIT_OFF_T=y
+CONFIG_ARCH_AIROHA=y
+CONFIG_ARCH_HIBERNATION_POSSIBLE=y
+CONFIG_ARCH_KEEP_MEMBLOCK=y
+CONFIG_ARCH_MIGHT_HAVE_PC_PARPORT=y
+CONFIG_ARCH_MULTIPLATFORM=y
+CONFIG_ARCH_MULTI_V6_V7=y
+CONFIG_ARCH_MULTI_V7=y
+CONFIG_ARCH_NR_GPIO=0
+CONFIG_ARCH_OPTIONAL_KERNEL_RWX=y
+CONFIG_ARCH_OPTIONAL_KERNEL_RWX_DEFAULT=y
+CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_ARCH_SPARSEMEM_ENABLE=y
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+CONFIG_ARM=y
+CONFIG_ARM_AMBA=y
+CONFIG_ARM_ARCH_TIMER=y
+CONFIG_ARM_ARCH_TIMER_EVTSTREAM=y
+CONFIG_ARM_CPU_SUSPEND=y
+CONFIG_ARM_GIC=y
+CONFIG_ARM_GIC_V3=y
+CONFIG_ARM_GIC_V3_ITS=y
+CONFIG_ARM_GIC_V3_ITS_PCI=y
+CONFIG_ARM_HAS_SG_CHAIN=y
+CONFIG_ARM_HEAVY_MB=y
+# CONFIG_ARM_HIGHBANK_CPUIDLE is not set
+CONFIG_ARM_L1_CACHE_SHIFT=6
+CONFIG_ARM_L1_CACHE_SHIFT_6=y
+CONFIG_ARM_PATCH_IDIV=y
+CONFIG_ARM_PATCH_PHYS_VIRT=y
+CONFIG_ARM_PSCI=y
+CONFIG_ARM_PSCI_FW=y
+# CONFIG_ARM_SMMU is not set
+CONFIG_ARM_THUMB=y

[PATCH] rpcd: plugin: don't query ubusd for known object name

2022-07-27 Thread Daniel Danzberger
The object name is already known and stored in the ubus object,
so there is no need ubus_lookup() all objects and reverse resolve
the id to it's name on every plugin handler call.

Signed-off-by: Daniel Danzberger 
---
 plugin.c | 41 ++---
 1 file changed, 2 insertions(+), 39 deletions(-)

diff --git a/plugin.c b/plugin.c
index ea6e60f..7cd59c4 100644
--- a/plugin.c
+++ b/plugin.c
@@ -20,37 +20,6 @@
 
 static struct blob_buf buf;
 
-struct rpc_plugin_lookup_context {
-   uint32_t id;
-   char *name;
-   bool found;
-};
-
-static void
-rpc_plugin_lookup_plugin_cb(struct ubus_context *ctx,
-struct ubus_object_data *obj, void *priv)
-{
-   struct rpc_plugin_lookup_context *c = priv;
-
-   if (c->id == obj->id)
-   {
-   c->found = true;
-   sprintf(c->name, "%s", obj->path);
-   }
-}
-
-static bool
-rpc_plugin_lookup_plugin(struct ubus_context *ctx, struct ubus_object *obj,
- char *strptr)
-{
-   struct rpc_plugin_lookup_context c = { .id = obj->id, .name = strptr };
-
-   if (ubus_lookup(ctx, NULL, rpc_plugin_lookup_plugin_cb, ))
-   return false;
-
-   return c.found;
-}
-
 static void
 rpc_plugin_json_array_to_blob(struct array_list *a, struct blob_buf *blob);
 
@@ -204,7 +173,7 @@ rpc_plugin_call(struct ubus_context *ctx, struct 
ubus_object *obj,
 {
int rv = UBUS_STATUS_UNKNOWN_ERROR;
struct call_context *c;
-   char *plugin, *mptr;
+   char *mptr;
 
c = calloc_a(sizeof(*c), , strlen(method) + 1);
 
@@ -218,13 +187,7 @@ rpc_plugin_call(struct ubus_context *ctx, struct 
ubus_object *obj,
if (!c->input || !c->tok)
goto fail;
 
-   plugin = c->path + sprintf(c->path, "%s/", RPC_PLUGIN_DIRECTORY);
-
-   if (!rpc_plugin_lookup_plugin(ctx, obj, plugin))
-   {
-   rv = UBUS_STATUS_NOT_FOUND;
-   goto fail;
-   }
+   sprintf(c->path, "%s/%s", RPC_PLUGIN_DIRECTORY, obj->name);
 
c->argv[0] = c->path;
c->argv[1] = "call";
-- 
2.35.1


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel