ASR_BASE
Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/package/system/procd/patches/0001-add-prod_init-script.patch b/package/system/procd/patches/0001-add-prod_init-script.patch
new file mode 100644
index 0000000..90d9247
--- /dev/null
+++ b/package/system/procd/patches/0001-add-prod_init-script.patch
@@ -0,0 +1,66 @@
+--- a/inittab.c
++++ b/inittab.c
+@@ -44,6 +44,7 @@
+
+ struct init_action;
+ char *console = NULL;
++int production_mode = 0;
+
+ struct init_handler {
+ const char *name;
+@@ -313,9 +314,24 @@ void procd_inittab(void)
+ #define LINE_LEN 128
+ FILE *fp = fopen(tab, "r");
+ struct init_action *a;
+- regex_t pat_inittab;
+- regmatch_t matches[5];
+- char *line;
++ regex_t pat_inittab, pat_cmdline;
++ regmatch_t matches[5], cmd_matches[2];
++ char *line, cmdline[1024];
++ int r, fd = open("/proc/cmdline", O_RDONLY);
++
++ if (fd < 0) {
++ ERROR("Failed to open /proc/cmdline\n");
++ return;
++ }
++
++ r = read(fd, cmdline, sizeof(cmdline) - 1);
++ cmdline[r] = '\0';
++ close(fd);
++ regcomp(&pat_cmdline, "PROD=([0-2])", REG_EXTENDED);
++ if (!regexec(&pat_cmdline, cmdline, 1, cmd_matches, 0)) {
++ cmdline[cmd_matches[0].rm_eo] = '\0';
++ production_mode = atoi(&cmdline[cmd_matches[0].rm_eo - 1]);
++ }
+
+ if (!fp) {
+ ERROR("Failed to open %s: %m\n", tab);
+--- a/rcS.c
++++ b/rcS.c
+@@ -34,6 +34,7 @@
+ #include "rcS.h"
+
+ static struct runqueue q, r;
++extern int production_mode;
+
+ struct initd {
+ struct ustream_fd fd;
+@@ -172,7 +173,17 @@ static int _rc(struct runqueue *q, char
+ }
+
+ for (j = 0; j < gl.gl_pathc; j++)
++ {
++ if (strstr(gl.gl_pathv[j], "prod_init")) {
++ if (production_mode) {
++ add_initd(q, gl.gl_pathv[j], param);
++ break;
++ } else {
++ continue;
++ }
++ }
+ add_initd(q, gl.gl_pathv[j], param);
++ }
+
+ globfree(&gl);
+
diff --git a/package/system/procd/patches/0002-Production-change-init-script-choosing-method.patch b/package/system/procd/patches/0002-Production-change-init-script-choosing-method.patch
new file mode 100644
index 0000000..85b1645
--- /dev/null
+++ b/package/system/procd/patches/0002-Production-change-init-script-choosing-method.patch
@@ -0,0 +1,77 @@
+--- a/rcS.c
++++ b/rcS.c
+@@ -33,6 +33,12 @@
+ #include "procd.h"
+ #include "rcS.h"
+
++/*These are the scripts that are loaded both in normal and production mode.
++ However, product mode only executes the scripts in BASE_SCRIPTS with
++ lower START index than prod_init and prod_init itself.
++ */
++#define BASE_SCRIPTS "sysfixtime boot system sysctl log firewall network odhcpd fstab"
++
+ static struct runqueue q, r;
+ extern int production_mode;
+
+@@ -154,11 +160,26 @@ static void add_initd(struct runqueue *q
+ runqueue_task_add(q, &s->proc.task, false);
+ }
+
++static void remove_str_from_list(char *str, char *list)
++{
++ char *pnt1, *pnt2;
++ if (!str || !list)
++ return;
++ pnt1 = strstr(list, str);
++ if (pnt1 == NULL)
++ return;
++ pnt2 = pnt1 + strlen(str) + 1;
++ memmove(pnt1, pnt2, strlen(pnt2) + 1);
++}
++
+ static int _rc(struct runqueue *q, char *path, const char *file, char *pattern, char *param)
+ {
+ char *dir = alloca(2 + strlen(path) + strlen(file) + strlen(pattern));
+ glob_t gl;
+ int j;
++ char available_strings[] = BASE_SCRIPTS;
++ char str[] = BASE_SCRIPTS;
++ char *token;
+
+ if (!dir) {
+ ERROR("Out of memory in %s.\n", file);
+@@ -174,17 +195,31 @@ static int _rc(struct runqueue *q, char
+
+ for (j = 0; j < gl.gl_pathc; j++)
+ {
+- if (strstr(gl.gl_pathv[j], "prod_init")) {
+- if (production_mode) {
++ if (production_mode) {
++ strcpy(str, available_strings);
++ token = strtok(str, " ");
++ do
++ {
++ if (strstr(gl.gl_pathv[j], token)) {
++ add_initd(q, gl.gl_pathv[j], param);
++ remove_str_from_list(token, available_strings);
++ break;
++ }
++ token = strtok(NULL, " ");
++ } while (token != NULL);
++ if (token == NULL && strstr(gl.gl_pathv[j], "prod_init"))
++ {
+ add_initd(q, gl.gl_pathv[j], param);
+ break;
+ } else {
+ continue;
+ }
++ } else {
++ if (strstr(gl.gl_pathv[j], "prod_init"))
++ continue;
+ }
+ add_initd(q, gl.gl_pathv[j], param);
+ }
+-
+ globfree(&gl);
+
+ return 0;
diff --git a/package/system/procd/patches/0003-Marvell-fast-boot-solution.patch b/package/system/procd/patches/0003-Marvell-fast-boot-solution.patch
new file mode 100644
index 0000000..1439a3f
--- /dev/null
+++ b/package/system/procd/patches/0003-Marvell-fast-boot-solution.patch
@@ -0,0 +1,60 @@
+--- a/inittab.c
++++ b/inittab.c
+@@ -16,6 +16,7 @@
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/ioctl.h>
++#include <sys/wait.h>
+
+ #include <fcntl.h>
+ #include <stdio.h>
+@@ -385,3 +386,28 @@ void procd_inittab(void)
+ free(a);
+ regfree(&pat_inittab);
+ }
++
++/*Implementation of Marvell Fast Boot routine*/
++void mrvl_fast_boot()
++{
++ char *init[] = { "/etc/telinit", NULL };
++ int i, pid;
++
++ pid = fork();
++ if (!pid) {
++ execvp(init[0], init);
++ ERROR("Failed to start telinit\n");
++ exit(-1);
++ }
++ if (pid <= 0) {
++ ERROR("Failed to start new telinit instance\n");
++ return;
++ } else {
++ for (i = 0; i < 200; i++) {
++ if (waitpid(pid, NULL, WNOHANG) > 0)
++ break;
++ usleep(10 * 1000);
++ }
++ }
++}
++
+--- a/procd.h
++++ b/procd.h
+@@ -46,6 +46,7 @@ void procd_inittab(void);
+ void procd_inittab_run(const char *action);
+ void procd_inittab_kill(void);
+ void procd_bcast_event(char *event, struct blob_attr *msg);
++void mrvl_fast_boot(void);
+
+ struct trigger;
+ void trigger_event(const char *type, struct blob_attr *data);
+--- a/state.c
++++ b/state.c
+@@ -137,6 +137,8 @@ static void state_enter(void)
+ break;
+
+ case STATE_UBUS:
++ LOG("- telinit -\n");
++ mrvl_fast_boot();
+ // try to reopen incase the wdt was not available before coldplug
+ watchdog_init(0);
+ set_stdio("console");
diff --git a/package/system/procd/patches/0004-fix-procd-debuglevel-no-output.patch b/package/system/procd/patches/0004-fix-procd-debuglevel-no-output.patch
new file mode 100644
index 0000000..fcf00d4
--- /dev/null
+++ b/package/system/procd/patches/0004-fix-procd-debuglevel-no-output.patch
@@ -0,0 +1,11 @@
+--- a/initd/preinit.c
++++ b/initd/preinit.c
+@@ -91,7 +91,7 @@ static void
+ spawn_procd(struct uloop_process *proc, int ret)
+ {
+ char *wdt_fd = watchdog_fd();
+- char *argv[] = { "/sbin/procd", NULL};
++ char *argv[] = { "/sbin/procd", "-S", NULL};
+ char dbg[2];
+
+ if (plugd_proc.pid > 0)
diff --git a/package/system/procd/patches/0005-add-ramdump-init-script.patch b/package/system/procd/patches/0005-add-ramdump-init-script.patch
new file mode 100644
index 0000000..8c65764
--- /dev/null
+++ b/package/system/procd/patches/0005-add-ramdump-init-script.patch
@@ -0,0 +1,46 @@
+--- a/inittab.c
++++ b/inittab.c
+@@ -327,8 +327,8 @@ void procd_inittab(void)
+
+ r = read(fd, cmdline, sizeof(cmdline) - 1);
+ cmdline[r] = '\0';
+- close(fd);
+- regcomp(&pat_cmdline, "PROD=([0-2])", REG_EXTENDED);
++ close(fd);
++ regcomp(&pat_cmdline, "PROD=([0-5])", REG_EXTENDED);
+ if (!regexec(&pat_cmdline, cmdline, 1, cmd_matches, 0)) {
+ cmdline[cmd_matches[0].rm_eo] = '\0';
+ production_mode = atoi(&cmdline[cmd_matches[0].rm_eo - 1]);
+--- a/rcS.c
++++ b/rcS.c
+@@ -207,15 +207,26 @@ static int _rc(struct runqueue *q, char
+ }
+ token = strtok(NULL, " ");
+ } while (token != NULL);
+- if (token == NULL && strstr(gl.gl_pathv[j], "prod_init"))
++
++ if (token == NULL && strstr(gl.gl_pathv[j], "rdp_init"))
+ {
+- add_initd(q, gl.gl_pathv[j], param);
+- break;
++ if (production_mode == 5) {
++ add_initd(q, gl.gl_pathv[j], param);
++ break;
++ } else
++ continue;
++ } else if (token == NULL && strstr(gl.gl_pathv[j], "prod_init"))
++ {
++ if (production_mode == 1) {
++ add_initd(q, gl.gl_pathv[j], param);
++ break;
++ } else
++ continue;
+ } else {
+ continue;
+ }
+ } else {
+- if (strstr(gl.gl_pathv[j], "prod_init"))
++ if (strstr(gl.gl_pathv[j], "prod_init") || strstr(gl.gl_pathv[j], "rdp_init"))
+ continue;
+ }
+ add_initd(q, gl.gl_pathv[j], param);
diff --git a/package/system/procd/patches/0010-fix_make_option_boot_on_console.patch b/package/system/procd/patches/0010-fix_make_option_boot_on_console.patch
new file mode 100644
index 0000000..40d299c
--- /dev/null
+++ b/package/system/procd/patches/0010-fix_make_option_boot_on_console.patch
@@ -0,0 +1,13 @@
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -43,6 +43,10 @@ IF(EARLY_PATH)
+ ADD_DEFINITIONS(-DEARLY_PATH="${EARLY_PATH}")
+ ENDIF()
+
++IF(SHOW_BOOT_ON_CONSOLE)
++ ADD_DEFINITIONS(-DSHOW_BOOT_ON_CONSOLE)
++ENDIF()
++
+ IF(SELINUX)
+ include(FindPkgConfig)
+ pkg_search_module(SELINUX REQUIRED libselinux)
diff --git a/package/system/procd/patches/0040-disable_watchdog.patch b/package/system/procd/patches/0040-disable_watchdog.patch
new file mode 100644
index 0000000..e4b1edd
--- /dev/null
+++ b/package/system/procd/patches/0040-disable_watchdog.patch
@@ -0,0 +1,12 @@
+--- a/watchdog.c
++++ b/watchdog.c
+@@ -190,6 +190,9 @@ char* watchdog_fd(void)
+
+ void watchdog_init(int preinit)
+ {
++ /* skip here, we handled wdt in kernel */
++ return;
++
+ wdt_timeout.cb = watchdog_timeout_cb;
+
+ if (watchdog_open(!preinit) < 0)
diff --git a/package/system/procd/patches/0050-disable_support_of_loongarch64.patch b/package/system/procd/patches/0050-disable_support_of_loongarch64.patch
new file mode 100644
index 0000000..e94abc1
--- /dev/null
+++ b/package/system/procd/patches/0050-disable_support_of_loongarch64.patch
@@ -0,0 +1,61 @@
+--- a/jail/seccomp-bpf.h
++++ b/jail/seccomp-bpf.h
+@@ -80,9 +80,6 @@ struct seccomp_data {
+ #elif defined(__i386__)
+ # define REG_SYSCALL REG_EAX
+ # define ARCH_NR AUDIT_ARCH_I386
+-#elif defined(__loongarch_lp64)
+-# define REG_SYSCALL regs[11]
+-# define ARCH_NR AUDIT_ARCH_LOONGARCH64
+ #elif defined(__mips__)
+ # define REG_SYSCALL regs[2]
+ # if __BYTE_ORDER == __LITTLE_ENDIAN
+--- a/jail/seccomp-oci.c
++++ b/jail/seccomp-oci.c
+@@ -119,8 +119,6 @@ static uint32_t resolve_architecture(cha
+ return AUDIT_ARCH_ARM;
+ else if (!strcmp(archname, "SCMP_ARCH_AARCH64"))
+ return AUDIT_ARCH_AARCH64;
+- else if (!strcmp(archname, "SCMP_ARCH_LOONGARCH64"))
+- return AUDIT_ARCH_LOONGARCH64;
+ else if (!strcmp(archname, "SCMP_ARCH_MIPS"))
+ return AUDIT_ARCH_MIPS;
+ else if (!strcmp(archname, "SCMP_ARCH_MIPS64"))
+@@ -422,7 +420,7 @@ struct sock_fprog *parseOCIlinuxseccomp(
+ return prog;
+
+ errout1:
+- free(prog->filter);
++ free(filter);
+ errout2:
+ free(prog);
+ return NULL;
+--- a/trace/trace.c
++++ b/trace/trace.c
+@@ -48,7 +48,7 @@
+ #define _offsetof(a, b) __builtin_offsetof(a,b)
+ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+-#if defined (__aarch64__) || defined(__loongarch_lp64)
++#if defined (__aarch64__)
+ #include <linux/ptrace.h>
+ #elif defined(__amd64__)
+ #define reg_syscall_nr _offsetof(struct user, regs.orig_rax)
+@@ -226,7 +226,7 @@ static void tracer_cb(struct uloop_proce
+ if (WIFSTOPPED(ret) || (ret >> 16)) {
+ if (WSTOPSIG(ret) & 0x80) {
+ if (!tracee->in_syscall) {
+-#if defined(__aarch64__) || defined(__loongarch_lp64)
++#ifdef __aarch64__
+ int syscall = -1;
+ struct ptrace_syscall_info ptsi = {.op=PTRACE_SYSCALL_INFO_ENTRY};
+ if (ptrace(PTRACE_GET_SYSCALL_INFO, c->pid, sizeof(ptsi), &ptsi) != -1)
+@@ -260,7 +260,7 @@ static void tracer_cb(struct uloop_proce
+ } else if ((ret >> 16) == PTRACE_EVENT_STOP) {
+ /* Nothing special to do here */
+ } else if ((ret >> 8) == (SIGTRAP | (PTRACE_EVENT_SECCOMP << 8))) {
+-#if defined(__aarch64__) || defined(__loongarch_lp64)
++#ifdef __aarch64__
+ int syscall = -1;
+ struct ptrace_syscall_info ptsi = {.op=PTRACE_SYSCALL_INFO_SECCOMP};
+ if (ptrace(PTRACE_GET_SYSCALL_INFO, c->pid, sizeof(ptsi), &ptsi) != -1)