1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter.git synced 2025-03-09 15:40:20 +00:00

Some fixes for RUTX

This commit is contained in:
Ycarus (Yannick Chabanois) 2022-03-08 21:11:07 +01:00
parent c1f8489be6
commit 56abd19ae3
18 changed files with 536 additions and 40 deletions

View file

@ -15,4 +15,4 @@ CONFIG_TARGET_SQUASHFS_BLOCK_SIZE=64
CONFIG_KERNEL_SWAP=y CONFIG_KERNEL_SWAP=y
CONFIG_PREINITOPT=y CONFIG_PREINITOPT=y
CONFIG_PACKAGE_kmod-r2ec=y CONFIG_PACKAGE_kmod-r2ec=y
CONFIG_PACKAGE_uboot-ipq40xx=y CONFIG_PACKAGE_mnfinfo=y

View file

@ -0,0 +1,58 @@
#
# Copyright (C) 2020 Teltonika
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/download.mk
PKG_NAME:=mnfinfo
PKG_VERSION:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/mnfinfo
SECTION:=net
CATEGORY:=Network
TITLE:=Device mnf-info command line interface
DEPENDS:=+libpthread +libmnfinfo
endef
define Package/libmnfinfo
SECTION:=libs
CATEGORY:=Libraries
TITLE:=Device mnf-info API library
endef
define Package/rpcd-mod-mnfinfo
SECTION:=libs
CATEGORY:=Libraries
TITLE:=mnfinfo rpcd module
DEPENDS:=+rpcd +libmnfinfo
endef
define Build/InstallDev
$(INSTALL_DIR) $(STAGING_DIR)/usr/lib $(STAGING_DIR)/usr/include/libmnfinfo
$(CP) $(PKG_BUILD_DIR)/*.so $(STAGING_DIR)/usr/lib/
$(CP) $(PKG_BUILD_DIR)/src/include/*.h $(STAGING_DIR)/usr/include/libmnfinfo/
endef
define Package/mnfinfo/install
$(INSTALL_DIR) $(1)/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/mnf_info $(1)/sbin/mnf_info
endef
define Package/libmnfinfo/install
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_BUILD_DIR)/libmnfinfo.so $(1)/usr/lib/
endef
define Package/rpcd-mod-mnfinfo/install
$(INSTALL_DIR) $(1)/usr/lib/rpcd
$(INSTALL_BIN) $(PKG_BUILD_DIR)/mnfinfo.so $(1)/usr/lib/rpcd/
endef
$(eval $(call BuildPackage,mnfinfo))
$(eval $(call BuildPackage,libmnfinfo))
$(eval $(call BuildPackage,rpcd-mod-mnfinfo))

View file

@ -0,0 +1,35 @@
MNF_SOURCES = src/mnf_info.c
MNF_OBJS = $(MNF_SOURCES:.c=.o)
MNF_TARGET = mnf_info
MNF_RPC_SOURCES = src/mnf_rpc.c
MNF_RPC_OBJS = $(MNF_RPC_SOURCES:.c=.o)
MNF_RPC_TARGET = mnfinfo.so
LIB_SOURCES = src/libmnfinfo.c
LIB_OBJS = $(LIB_SOURCES:.c=.o)
LIB_TARGET = libmnfinfo.so
CFLAGS += -Wall -Wextra -Wpedantic -Werror -Wno-missing-braces -Wno-unused-function -Wno-unused-parameter -fPIC -I src/include
LDFLAGS += -L.
MNF_LDFLAGS =
MNF_RPC_LDFLAGS = -lmnfinfo
RM = rm -f
all: $(LIB_TARGET) $(MNF_RPC_TARGET) $(MNF_TARGET)
$(LIB_TARGET): $(LIB_OBJS)
$(CC) $(LDFLAGS) -shared -o $@ $^
$(MNF_RPC_TARGET): $(MNF_RPC_OBJS) $(LIB_TARGET)
$(CC) $(LDFLAGS) $(MNF_RPC_LDFLAGS) -shared -o $@ $^
$(MNF_TARGET): $(MNF_OBJS) $(LIB_OBJS)
$(CC) $(LDFLAGS) $(MNF_LDFLAGS) -o $@ $^
clean:
$(RM) $(LIB_OBJS) $(LIB_TARGET)
$(RM) $(MNF_RPC_OBJS) $(MNF_RPC_TARGET)
$(RM) $(MNF_OBJS) $(MNF_TARGET)

View file

@ -0,0 +1,25 @@
# libmnfinfo
How it works: depending on the platform, selected in the menuconfig, a different platform flag is defined during compilation. Depending on that flag, a header file with platform-specific MTD field defines is included. Here are all the defines, (currently) used for these headers:
* `MAX_SIM_ID` - maximum allowed SIM index on the platform.
* `MTD_CONFIG_RO` - absolute path of a read-only MTD partition. Used for most field reads.
* `MTD_CONFIG_RW` - absolute path of a read/write MTD partition. Used for SIM PIN value reads/writes.
* `MAC_OFFSET` - MAC field offset in the `MTD_CONFIG_RO` partition.
* `MAC_LENGTH` - MAC field length in the `MTD_CONFIG_RO` partition.
* `NAME_OFFSET` - product name field offset in the `MTD_CONFIG_RO` partition.
* `NAME_LENGTH` - product name field length in the `MTD_CONFIG_RO` partition.
* `WPS_OFFSET` - WPS field offset in the `MTD_CONFIG_RO` partition.
* `WPS_LENGTH` - WPS field length in the `MTD_CONFIG_RO` partition.
* `SERIAL_OFFSET` - product serial code field offset in the `MTD_CONFIG_RO` partition.
* `SERIAL_LENGTH` - product serial code field length in the `MTD_CONFIG_RO` partition.
* `BATCH_OFFSET` - batch index field offset in the `MTD_CONFIG_RO` partition.
* `BATCH_LENGTH` - batch index field length in the `MTD_CONFIG_RO` partition.
* `HWVER_OFFSET` - hardware version index field offset in the `MTD_CONFIG_RO` partition.
* `HWVER_LENGTH` - hardware version index field length in the `MTD_CONFIG_RO` partition.
* `SIMPIN_OFFSET` - SIM card PIN code field offset in the `MTD_CONFIG_RW` partition.
* `SIMPIN_LENGTH` - SIM card PIN code field length in the `MTD_CONFIG_RW` partition.
* `WIFI_OFFSET` - Wi-Fi password field offset in the `MTD_CONFIG_RO` partition.
* `WIFI_LENGTH` - Wi-Fi password field length in the `MTD_CONFIG_RO` partition.
Only defines with actual values should be written. All other defines should be removed from the platform-specific header file.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,115 @@
#include <stdint.h>
#include <stdbool.h>
#define STRING_NA(a) do { (a)[0] = 'N'; (a)[1] = '/'; (a)[2] = 'A'; (a)[3] = 0; } while(0)
#define STRING_NA_LENGTH 3
#define PARTITION_SIZE 0xA0
#define SECTION_SIZE 0x10
#if defined(RUTX_PLATFORM)
#include "rutx.h"
#elif defined(TRB1_PLATFORM)
#include "trb1.h"
#elif defined(TRB2_PLATFORM)
#include "trb2.h"
#elif defined(RUT2_PLATFORM)
#include "rut2.h"
#elif defined(RUT300_PLATFORM) || defined(RUT360_PLATFORM)
#include "rut3.h"
#else
#error Platform not recognized!
#endif
#if !(defined(MAC_OFFSET) && defined(MAC_LENGTH))
#undef MAC_OFFSET
#undef MAC_LENGTH
#define MAC_OFFSET 0
#define MAC_LENGTH STRING_NA_LENGTH
#else
#define MAC_ENABLED
#endif
#if !(defined(NAME_OFFSET) && defined(NAME_LENGTH))
#undef NAME_OFFSET
#undef NAME_LENGTH
#define NAME_OFFSET 0
#define NAME_LENGTH STRING_NA_LENGTH
#else
#define NAME_ENABLED
#endif
#if !(defined(WPS_OFFSET) && defined(WPS_LENGTH))
#undef WPS_OFFSET
#undef WPS_LENGTH
#define WPS_OFFSET 0
#define WPS_LENGTH STRING_NA_LENGTH
#else
#define WPS_ENABLED
#endif
#if !(defined(SERIAL_OFFSET) && defined(SERIAL_LENGTH))
#undef SERIAL_OFFSET
#undef SERIAL_LENGTH
#define SERIAL_OFFSET 0
#define SERIAL_LENGTH STRING_NA_LENGTH
#else
#define SERIAL_ENABLED
#endif
#if !(defined(BATCH_OFFSET) && defined(BATCH_LENGTH))
#undef BATCH_OFFSET
#undef BATCH_LENGTH
#define BATCH_OFFSET 0
#define BATCH_LENGTH STRING_NA_LENGTH
#else
#define BATCH_ENABLED
#endif
#if !(defined(HWVER_OFFSET) && defined(HWVER_LENGTH))
#undef HWVER_OFFSET
#undef HWVER_LENGTH
#define HWVER_OFFSET 0
#define HWVER_LENGTH STRING_NA_LENGTH
#else
#define HWVER_ENABLED
#endif
#if !(defined(SIMPIN_OFFSET) && defined(SIMPIN_LENGTH))
#undef SIMPIN_OFFSET
#undef SIMPIN_LENGTH
#define SIMPIN_OFFSET 0
#define SIMPIN_LENGTH STRING_NA_LENGTH
#else
#define SIMPIN_ENABLED
#endif
#if !(defined(WIFI_OFFSET) && defined(WIFI_LENGTH))
#undef WIFI_OFFSET
#undef WIFI_LENGTH
#define WIFI_OFFSET 0
#define WIFI_LENGTH STRING_NA_LENGTH
#else
#define WIFI_ENABLED
#endif
/*
* mnfinfo_get_*() functions return ptr to static memory, which is not to be free()d!
* the returned memory ptr is safely accessible throughout the using program's runtime
* bad: free(mnfinfo_get_mac());
*
* returns NULL on /dev/mtdX reading failure, "N/A" if the particular device
* doesn't support the field, or a dummy string if the mtdblock space contains garbage
*/
char* mnfinfo_get_mac(void);
char* mnfinfo_get_name(void);
char* mnfinfo_get_maceth(void);
char* mnfinfo_get_sn(void);
char* mnfinfo_get_hwver(void);
char* mnfinfo_get_batch(void);
char* mnfinfo_get_wps(void);
char* mnfinfo_get_wifi_pw(void);
char* mnfinfo_get_sim_pin(uint8_t sim_id);
// returns true on success
bool mnfinfo_set_sim_pin(uint8_t sim_id, const char *pin);

View file

@ -0,0 +1,21 @@
#define MAX_SIM_ID 1
#define MTD_CONFIG_RO "/dev/mtd1"
#define MTD_CONFIG_RW "/dev/mtd1"
#define MAC_OFFSET 0x00
#define MAC_LENGTH 6
#define NAME_OFFSET 0x10
#define NAME_LENGTH 12
#define WPS_OFFSET 0x20
#define WPS_LENGTH 8
#define SERIAL_OFFSET 0x30
#define SERIAL_LENGTH 10
#define BATCH_OFFSET 0x40
#define BATCH_LENGTH 4
#define HWVER_OFFSET 0x50
#define HWVER_LENGTH 4
#define SIMPIN_OFFSET 0x70
#define SIMPIN_LENGTH 4
#define WIFI_OFFSET 0x90
#define WIFI_LENGTH 16

View file

@ -0,0 +1,21 @@
#define MAX_SIM_ID 1
#define MTD_CONFIG_RO "/dev/mtd1"
#define MTD_CONFIG_RW "/dev/mtd1"
#define MAC_OFFSET 0x00
#define MAC_LENGTH 6
#define NAME_OFFSET 0x10
#define NAME_LENGTH 12
#define WPS_OFFSET 0x20
#define WPS_LENGTH 8
#define SERIAL_OFFSET 0x30
#define SERIAL_LENGTH 10
#define BATCH_OFFSET 0x40
#define BATCH_LENGTH 4
#define HWVER_OFFSET 0x50
#define HWVER_LENGTH 4
#define SIMPIN_OFFSET 0x70
#define SIMPIN_LENGTH 4
#define WIFI_OFFSET 0x90
#define WIFI_LENGTH 16

View file

@ -0,0 +1,21 @@
#define MAX_SIM_ID 4
#define MTD_CONFIG_RO "/dev/mtd13"
#define MTD_CONFIG_RW "/dev/mtd14"
#define MAC_OFFSET 0x00
#define MAC_LENGTH 6
#define NAME_OFFSET 0x10
#define NAME_LENGTH 12
#define WPS_OFFSET 0x20
#define WPS_LENGTH 8
#define SERIAL_OFFSET 0x30
#define SERIAL_LENGTH 10
#define BATCH_OFFSET 0x40
#define BATCH_LENGTH 4
#define HWVER_OFFSET 0x50
#define HWVER_LENGTH 4
#define SIMPIN_OFFSET 0x00
#define SIMPIN_LENGTH 4
#define WIFI_OFFSET 0x90
#define WIFI_LENGTH 16

View file

@ -0,0 +1,17 @@
#define MAX_SIM_ID 1
#define MTD_CONFIG_RO "/dev/mtd7"
#define MTD_CONFIG_RW "/dev/mtd7"
#define MAC_OFFSET 0x50
#define MAC_LENGTH 12
#define NAME_OFFSET 0x20
#define NAME_LENGTH 12
#define SERIAL_OFFSET 0x10
#define SERIAL_LENGTH 10
#define BATCH_OFFSET 0x40
#define BATCH_LENGTH 3
#define HWVER_OFFSET 0x30
#define HWVER_LENGTH 4
#define SIMPIN_LENGTH 4
#define SIMPIN_OFFSET 0x70

View file

@ -0,0 +1,21 @@
#define MAX_SIM_ID 2
#define MTD_CONFIG_RO "/dev/mtd1"
#define MTD_CONFIG_RW "/dev/mtd1"
#define MAC_OFFSET 0x00
#define MAC_LENGTH 6
#define NAME_OFFSET 0x10
#define NAME_LENGTH 12
#define WPS_OFFSET 0x20
#define WPS_LENGTH 8
#define SERIAL_OFFSET 0x30
#define SERIAL_LENGTH 10
#define BATCH_OFFSET 0x40
#define BATCH_LENGTH 4
#define HWVER_OFFSET 0x50
#define HWVER_LENGTH 4
#define SIMPIN_OFFSET 0x70
#define SIMPIN_LENGTH 4
#define WIFI_OFFSET 0x90
#define WIFI_LENGTH 16

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -113,7 +113,7 @@ generate_network() {
local ipad local ipad
case "$1" in case "$1" in
lan) lan)
ipad=${ipaddr:-"192.168.1.1"} ipad=${ipaddr:-"192.168.100.1"}
;; ;;
*) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;; *) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
esac esac
@ -365,10 +365,9 @@ generate_static_system() {
if json_is_a system object; then if json_is_a system object; then
json_select system json_select system
local hostname local hostname
if json_get_var hostname hostname; then #if json_get_var hostname hostname; then
#uci -q set "system.@system[-1].hostname=$hostname" # uci -q set "system.@system[-1].hostname=$hostname"
uci -q set "system.@system[-1].hostname=OpenMPTCProuter" #fi
fi
if json_is_a ntpserver array; then if json_is_a ntpserver array; then
local keys key local keys key

View file

@ -1,45 +1,208 @@
PART_NAME=firmware PART_NAME=firmware
REQUIRE_IMAGE_METADATA=1 REQUIRE_IMAGE_METADATA=1
RAMFS_COPY_BIN='fw_printenv fw_setenv'
RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
platform_check_image() { platform_check_image() {
platform_check_image_ipq "$1" case "$(board_name)" in
asus,rt-ac42u |\
asus,rt-ac58u)
local ubidev=$(nand_find_ubi $CI_UBIPART)
local asus_root=$(nand_find_volume $ubidev jffs2)
[ -n "$asus_root" ] || return 0
cat << EOF
jffs2 partition is still present.
There's probably no space left
to install the filesystem.
You need to delete the jffs2 partition first:
# ubirmvol /dev/ubi0 --name=jffs2
Once this is done. Retry.
EOF
return 1
;;
zte,mf286d)
CI_UBIPART="rootfs"
local mtdnum="$( find_mtd_index $CI_UBIPART )"
[ ! "$mtdnum" ] && return 1
ubiattach -m "$mtdnum" || true
local ubidev="$( nand_find_ubi $CI_UBIPART )"
local ubi_rootfs=$(nand_find_volume $ubidev ubi_rootfs)
local ubi_rootfs_data=$(nand_find_volume $ubidev ubi_rootfs_data)
[ -n "$ubi_rootfs" ] || [ -n "$ubi_rootfs_data" ] || return 0
cat << EOF
ubi_rootfs partition is still present.
You need to delete the stock partition first:
# ubirmvol /dev/ubi0 -N ubi_rootfs
Please also delete ubi_rootfs_data, if exist:
# ubirmvol /dev/ubi0 -N ubi_rootfs_data
Once this is done. Retry.
EOF
return 1
;;
esac
return 0;
}
askey_do_upgrade() {
local tar_file="$1"
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
nand_do_upgrade "$1"
}
zyxel_do_upgrade() {
local tar_file="$1"
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
tar Oxf $tar_file ${board_dir}/kernel | mtd write - kernel
if [ -n "$UPGRADE_BACKUP" ]; then
tar Oxf $tar_file ${board_dir}/root | mtd -j "$UPGRADE_BACKUP" write - rootfs
else
tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
fi
}
platform_do_upgrade_mikrotik_nand() {
local fw_mtd=$(find_mtd_part kernel)
fw_mtd="${fw_mtd/block/}"
[ -n "$fw_mtd" ] || return
local board_dir=$(tar tf "$1" | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
[ -n "$board_dir" ] || return
local kernel_len=$(tar xf "$1" ${board_dir}/kernel -O | wc -c)
[ -n "$kernel_len" ] || return
tar xf "$1" ${board_dir}/kernel -O | ubiformat "$fw_mtd" -y -S $kernel_len -f -
CI_KERNPART="none"
nand_do_upgrade "$1"
} }
platform_do_upgrade() { platform_do_upgrade() {
platform_do_upgrade_ipq "$1" case "$(board_name)" in
8dev,jalapeno |\
aruba,ap-303 |\
aruba,ap-303h |\
aruba,ap-365 |\
avm,fritzbox-7530 |\
avm,fritzrepeater-1200 |\
avm,fritzrepeater-3000 |\
buffalo,wtr-m2133hp |\
cilab,meshpoint-one |\
edgecore,ecw5211 |\
edgecore,oap100 |\
engenius,eap2200 |\
glinet,gl-ap1300 |\
luma,wrtq-329acn |\
mobipromo,cm520-79f |\
netgear,wac510 |\
p2w,r619ac-64m |\
p2w,r619ac-128m |\
qxwlan,e2600ac-c2)
nand_do_upgrade "$1"
;;
glinet,gl-b2200)
CI_KERNPART="0:HLOS"
CI_ROOTPART="rootfs"
CI_DATAPART="rootfs_data"
emmc_do_upgrade "$1"
;;
alfa-network,ap120c-ac)
part="$(awk -F 'ubi.mtd=' '{printf $2}' /proc/cmdline | sed -e 's/ .*$//')"
if [ "$part" = "rootfs1" ]; then
fw_setenv active 2 || exit 1
CI_UBIPART="rootfs2"
else
fw_setenv active 1 || exit 1
CI_UBIPART="rootfs1"
fi
nand_do_upgrade "$1"
;;
asus,map-ac2200)
CI_KERNPART="linux"
nand_do_upgrade "$1"
;;
asus,rt-ac42u |\
asus,rt-ac58u)
CI_KERNPART="linux"
nand_do_upgrade "$1"
;;
cellc,rtl30vw)
CI_UBIPART="ubifs"
askey_do_upgrade "$1"
;;
compex,wpj419)
nand_do_upgrade "$1"
;;
linksys,ea6350v3 |\
linksys,ea8300 |\
linksys,mr8300)
platform_do_upgrade_linksys "$1"
;;
meraki,mr33)
CI_KERNPART="part.safe"
nand_do_upgrade "$1"
;;
mikrotik,cap-ac|\
mikrotik,hap-ac2|\
mikrotik,lhgg-60ad|\
mikrotik,sxtsq-5-ac)
[ "$(rootfs_type)" = "tmpfs" ] && mtd erase firmware
default_do_upgrade "$1"
;;
mikrotik,hap-ac3)
platform_do_upgrade_mikrotik_nand "$1"
;;
netgear,rbr50 |\
netgear,rbs50 |\
netgear,srr60 |\
netgear,srs60)
platform_do_upgrade_netgear_orbi_upgrade "$1"
;;
openmesh,a42 |\
openmesh,a62 |\
plasmacloud,pa1200 |\
plasmacloud,pa2200)
PART_NAME="inactive"
platform_do_upgrade_dualboot_datachk "$1"
;;
teltonika,rutx |\
zte,mf286d)
CI_UBIPART="rootfs"
nand_do_upgrade "$1"
;;
zyxel,nbg6617)
zyxel_do_upgrade "$1"
;;
*)
default_do_upgrade "$1"
;;
esac
} }
# added with io_expander validation platform_copy_config() {
platform_check_hw_support() { case "$(board_name)" in
local metadata="/tmp/sysupgrade.meta" glinet,gl-b2200)
local io_expander_file="/proc/device-tree/io_expander" emmc_copy_config
local found=0 ;;
esac
[ -e "$metadata" ] || ( fwtool -q -i $metadata $1 ) && {
json_load_file "$metadata"
# previous devices were always supported
[ ! -e "$io_expander_file" ] && return 0
json_select hw_support
# io_expander type validation
local io_expander="$(cat $io_expander_file)"
# if support type is absent in metadata, we assume it's supported
if ( json_select io_expander 2> /dev/null ); then
json_select io_expander
json_get_values io_exp_values
for val in $io_exp_values; do
regex_value=$(echo "$io_expander" | grep -e "$val")
[ "$io_expander" = "$regex_value" ] && found=1
done
[ $found -eq 0 ] && return 1
json_select ..
else
# fail if not default/initial type
[ "$io_expander" != "stm32" ] && return 1
fi
# ...
}
return 0; return 0;
} }