From aaa7d1824d7a96923e0d9c049ad9936a0bf46deb Mon Sep 17 00:00:00 2001 From: viktorxda <35473052+viktorxda@users.noreply.github.com> Date: Tue, 26 Mar 2024 08:07:23 +0100 Subject: [PATCH] Package: add proper logcat source (#1361) --- .../configs/t10_lite_defconfig | 1 + .../configs/t20_lite_defconfig | 1 + .../configs/t20_ultimate_defconfig | 1 + .../configs/t21_lite_defconfig | 1 + .../configs/t21_ultimate_defconfig | 1 + .../configs/t30_lite_defconfig | 1 + br-ext-chip-ingenic/configs/t31_fpv_defconfig | 1 + .../configs/t31_lite_defconfig | 1 + .../configs/t31_ultimate_defconfig | 1 + .../configs/t40_lite_defconfig | 1 + .../configs/t40_ultimate_defconfig | 1 + general/overlay/etc/profile | 10 +- general/package/Config.in | 1 + general/package/logcat-openipc/Config.in | 4 + .../package/logcat-openipc/logcat-openipc.mk | 18 +++ general/package/logcat-openipc/src/logcat.c | 125 ++++++++++++++++++ 16 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 general/package/logcat-openipc/Config.in create mode 100644 general/package/logcat-openipc/logcat-openipc.mk create mode 100644 general/package/logcat-openipc/src/logcat.c diff --git a/br-ext-chip-ingenic/configs/t10_lite_defconfig b/br-ext-chip-ingenic/configs/t10_lite_defconfig index 26c9a49c..356c0835 100644 --- a/br-ext-chip-ingenic/configs/t10_lite_defconfig +++ b/br-ext-chip-ingenic/configs/t10_lite_defconfig @@ -108,6 +108,7 @@ BR2_PACKAGE_WIREGUARD_LINUX_COMPAT=y BR2_PACKAGE_WIREGUARD_TOOLS=y # DEBUG +BR2_PACKAGE_LOGCAT_OPENIPC=y # BR2_PACKAGE_HOST_GDB is not set # BR2_PACKAGE_GDB is not set diff --git a/br-ext-chip-ingenic/configs/t20_lite_defconfig b/br-ext-chip-ingenic/configs/t20_lite_defconfig index b7bfd105..af3e821b 100644 --- a/br-ext-chip-ingenic/configs/t20_lite_defconfig +++ b/br-ext-chip-ingenic/configs/t20_lite_defconfig @@ -108,6 +108,7 @@ BR2_PACKAGE_WIREGUARD_LINUX_COMPAT=y BR2_PACKAGE_WIREGUARD_TOOLS=y # DEBUG +BR2_PACKAGE_LOGCAT_OPENIPC=y # BR2_PACKAGE_HOST_GDB is not set # BR2_PACKAGE_GDB is not set diff --git a/br-ext-chip-ingenic/configs/t20_ultimate_defconfig b/br-ext-chip-ingenic/configs/t20_ultimate_defconfig index 515a950c..d81350cb 100644 --- a/br-ext-chip-ingenic/configs/t20_ultimate_defconfig +++ b/br-ext-chip-ingenic/configs/t20_ultimate_defconfig @@ -123,6 +123,7 @@ BR2_PACKAGE_ZEROTIER_ONE=y # BR2_PACKAGE_NABTO is not set # DEBUG +BR2_PACKAGE_LOGCAT_OPENIPC=y # BR2_PACKAGE_HOST_GDB is not set # BR2_PACKAGE_GDB is not set diff --git a/br-ext-chip-ingenic/configs/t21_lite_defconfig b/br-ext-chip-ingenic/configs/t21_lite_defconfig index 05c4c6db..acb0488c 100644 --- a/br-ext-chip-ingenic/configs/t21_lite_defconfig +++ b/br-ext-chip-ingenic/configs/t21_lite_defconfig @@ -108,6 +108,7 @@ BR2_PACKAGE_WIREGUARD_LINUX_COMPAT=y BR2_PACKAGE_WIREGUARD_TOOLS=y # DEBUG +BR2_PACKAGE_LOGCAT_OPENIPC=y # BR2_PACKAGE_HOST_GDB is not set # BR2_PACKAGE_GDB is not set diff --git a/br-ext-chip-ingenic/configs/t21_ultimate_defconfig b/br-ext-chip-ingenic/configs/t21_ultimate_defconfig index ccdded41..243a7ccf 100644 --- a/br-ext-chip-ingenic/configs/t21_ultimate_defconfig +++ b/br-ext-chip-ingenic/configs/t21_ultimate_defconfig @@ -111,6 +111,7 @@ BR2_PACKAGE_WIREGUARD_LINUX_COMPAT=y BR2_PACKAGE_WIREGUARD_TOOLS=y # DEBUG +BR2_PACKAGE_LOGCAT_OPENIPC=y # BR2_PACKAGE_HOST_GDB is not set # BR2_PACKAGE_GDB is not set diff --git a/br-ext-chip-ingenic/configs/t30_lite_defconfig b/br-ext-chip-ingenic/configs/t30_lite_defconfig index 3ec14f43..0433cccc 100644 --- a/br-ext-chip-ingenic/configs/t30_lite_defconfig +++ b/br-ext-chip-ingenic/configs/t30_lite_defconfig @@ -108,6 +108,7 @@ BR2_PACKAGE_WIREGUARD_LINUX_COMPAT=y BR2_PACKAGE_WIREGUARD_TOOLS=y # DEBUG +BR2_PACKAGE_LOGCAT_OPENIPC=y # BR2_PACKAGE_HOST_GDB is not set # BR2_PACKAGE_GDB is not set diff --git a/br-ext-chip-ingenic/configs/t31_fpv_defconfig b/br-ext-chip-ingenic/configs/t31_fpv_defconfig index b772d6ea..cab61b07 100644 --- a/br-ext-chip-ingenic/configs/t31_fpv_defconfig +++ b/br-ext-chip-ingenic/configs/t31_fpv_defconfig @@ -114,6 +114,7 @@ BR2_PACKAGE_WIFIBROADCAST=y BR2_PACKAGE_MAVFWD=y # DEBUG +BR2_PACKAGE_LOGCAT_OPENIPC=y # BR2_PACKAGE_HOST_GDB is not set # BR2_PACKAGE_GDB is not set diff --git a/br-ext-chip-ingenic/configs/t31_lite_defconfig b/br-ext-chip-ingenic/configs/t31_lite_defconfig index 734ba756..53844389 100644 --- a/br-ext-chip-ingenic/configs/t31_lite_defconfig +++ b/br-ext-chip-ingenic/configs/t31_lite_defconfig @@ -111,6 +111,7 @@ BR2_PACKAGE_WIREGUARD_TOOLS=y # BR2_PACKAGE_ONVIF_SIMPLE_SERVER is not set # DEBUG +BR2_PACKAGE_LOGCAT_OPENIPC=y # BR2_PACKAGE_HOST_GDB is not set # BR2_PACKAGE_GDB is not set diff --git a/br-ext-chip-ingenic/configs/t31_ultimate_defconfig b/br-ext-chip-ingenic/configs/t31_ultimate_defconfig index 8cbece8e..b215d404 100644 --- a/br-ext-chip-ingenic/configs/t31_ultimate_defconfig +++ b/br-ext-chip-ingenic/configs/t31_ultimate_defconfig @@ -129,6 +129,7 @@ BR2_PACKAGE_ZEROTIER_ONE=y # BR2_PACKAGE_NABTO is not set # DEBUG +BR2_PACKAGE_LOGCAT_OPENIPC=y # BR2_PACKAGE_HOST_GDB is not set # BR2_PACKAGE_GDB is not set diff --git a/br-ext-chip-ingenic/configs/t40_lite_defconfig b/br-ext-chip-ingenic/configs/t40_lite_defconfig index c81992d2..30d2c12a 100644 --- a/br-ext-chip-ingenic/configs/t40_lite_defconfig +++ b/br-ext-chip-ingenic/configs/t40_lite_defconfig @@ -108,6 +108,7 @@ BR2_PACKAGE_WIREGUARD_LINUX_COMPAT=y BR2_PACKAGE_WIREGUARD_TOOLS=y # DEBUG +BR2_PACKAGE_LOGCAT_OPENIPC=y # BR2_PACKAGE_HOST_GDB is not set # BR2_PACKAGE_GDB is not set diff --git a/br-ext-chip-ingenic/configs/t40_ultimate_defconfig b/br-ext-chip-ingenic/configs/t40_ultimate_defconfig index 612a29db..6cc91d89 100644 --- a/br-ext-chip-ingenic/configs/t40_ultimate_defconfig +++ b/br-ext-chip-ingenic/configs/t40_ultimate_defconfig @@ -120,6 +120,7 @@ BR2_PACKAGE_ZEROTIER_ONE=y # BR2_PACKAGE_NABTO is not set # DEBUG +BR2_PACKAGE_LOGCAT_OPENIPC=y # BR2_PACKAGE_HOST_GDB is not set # BR2_PACKAGE_GDB is not set diff --git a/general/overlay/etc/profile b/general/overlay/etc/profile index 66357f06..399687d8 100644 --- a/general/overlay/etc/profile +++ b/general/overlay/etc/profile @@ -46,13 +46,15 @@ show_help() { } show_gain() { - while sleep 1; do wget -T1 -q -O - http://127.0.0.1/metrics/isp | grep ^isp_again; done + while sleep 1; do wget -T1 -q -O - localhost/metrics/isp | grep ^isp_again; done } show_gpio() { - mount -t debugfs none /sys/kernel/debug - cat /sys/kernel/debug/gpio - umount /sys/kernel/debug + if [ -e /sys/kernel/debug ]; then + mount -t debugfs none /sys/kernel/debug + cat /sys/kernel/debug/gpio + umount /sys/kernel/debug + fi } show_modules() { diff --git a/general/package/Config.in b/general/package/Config.in index 8e270edb..230742b6 100644 --- a/general/package/Config.in +++ b/general/package/Config.in @@ -56,6 +56,7 @@ source "$BR2_EXTERNAL_GENERAL_PATH/package/libsrtp-openipc/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/libwebsockets-openipc/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/linux-firmware-openipc/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/linux-patcher/Config.in" +source "$BR2_EXTERNAL_GENERAL_PATH/package/logcat-openipc/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/majestic-fonts/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/majestic-plugins/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/majestic-webui/Config.in" diff --git a/general/package/logcat-openipc/Config.in b/general/package/logcat-openipc/Config.in new file mode 100644 index 00000000..2ba85069 --- /dev/null +++ b/general/package/logcat-openipc/Config.in @@ -0,0 +1,4 @@ +config BR2_PACKAGE_LOGCAT_OPENIPC + bool "logcat-openipc" + help + Logcat tool for Ingenic diff --git a/general/package/logcat-openipc/logcat-openipc.mk b/general/package/logcat-openipc/logcat-openipc.mk new file mode 100644 index 00000000..992bc028 --- /dev/null +++ b/general/package/logcat-openipc/logcat-openipc.mk @@ -0,0 +1,18 @@ +################################################################################ +# +# logcat-openipc +# +################################################################################ + +LOGCAT_OPENIPC_SITE_METHOD = local +LOGCAT_OPENIPC_SITE = $(LOGCAT_OPENIPC_PKGDIR)/src + +define LOGCAT_OPENIPC_BUILD_CMDS + $(TARGET_CC) $(@D)/logcat.c -o $(@D)/logcat -s +endef + +define LOGCAT_OPENIPC_INSTALL_TARGET_CMDS + $(INSTALL) -m 755 -t $(TARGET_DIR)/usr/bin $(@D)/logcat +endef + +$(eval $(generic-package)) diff --git a/general/package/logcat-openipc/src/logcat.c b/general/package/logcat-openipc/src/logcat.c new file mode 100644 index 00000000..d1003093 --- /dev/null +++ b/general/package/logcat-openipc/src/logcat.c @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOGGER_ENTRY_MAX_LEN (4 * 1024) +#define LOGGER_FLUSH_LOG _IO(__LOGGERIO, 4) +#define __LOGGERIO 0xAE + +struct logger_entry { + uint16_t len; + uint16_t __pad; + int32_t pid; + int32_t tid; + int32_t sec; + int32_t nsec; + char msg[4096]; +} entry; + +enum android_LogPriority { + ANDROID_LOG_UNKNOWN = 0, + ANDROID_LOG_DEFAULT, + ANDROID_LOG_VERBOSE, + ANDROID_LOG_DEBUG, + ANDROID_LOG_INFO, + ANDROID_LOG_WARN, + ANDROID_LOG_ERROR, + ANDROID_LOG_FATAL, + ANDROID_LOG_SILENT, +}; + +int main(int argc, char *argv[]) { + int fd; + int msize; + int readsize; + int numread; + + if (argc > 1) { + if (strcmp(argv[1], "-c") == 0) { + fd = open("/dev/log_main", O_WRONLY); + if (fd < 0) { + perror("Error opening /dev/log_main\n"); + return -1; + } + ioctl(fd, LOGGER_FLUSH_LOG); + close(fd); + return 0; + } else { + printf("Usage: %s [-c] [-h]\n", argv[0]); + printf("Options:\n"); + printf(" -c Clear the log\n"); + printf(" -h Show this help\n"); + return 0; + } + } + + fd = open("/dev/log_main", O_RDONLY); + if (fd < 0) { + perror("Error opening /dev/log_main\n"); + return -1; + } + + int pos; + while (1) { + numread = read(fd, &entry, LOGGER_ENTRY_MAX_LEN); + if (numread < 1) { + perror("Error: "); + strerror(errno); + return -1; + } + + char *tag = entry.msg; + char *prog = entry.msg + 1; + char *msg = entry.msg + strlen(entry.msg) + 1; + char tagbyte; + + switch (*tag) { + case ANDROID_LOG_UNKNOWN: + tagbyte = 'U'; + break; + + case ANDROID_LOG_DEFAULT: + tagbyte = '*'; + break; + + case ANDROID_LOG_VERBOSE: + tagbyte = 'V'; + break; + + case ANDROID_LOG_DEBUG: + tagbyte = 'D'; + break; + + case ANDROID_LOG_INFO: + tagbyte = 'I'; + break; + + case ANDROID_LOG_WARN: + tagbyte = 'W'; + break; + + case ANDROID_LOG_ERROR: + tagbyte = 'E'; + break; + + case ANDROID_LOG_FATAL: + tagbyte = 'F'; + break; + + case ANDROID_LOG_SILENT: + tagbyte = 'S'; + break; + + default: + tagbyte = '?'; + break; + } + + printf("%c/%s(%5d): %s", tagbyte, prog, entry.pid, msg); + } +}