[][openwrt][mt7988][tops][update tops-tool default behavior]

Change TOPS tool default behavior.

By default, TOPS tool will automatically start even if TOPS is not loaded.
Add another package that depends on TOPS auto load package to separate TOPS
program installation and initialization auto start script. Right now, TOPS
tool will only be started at boot time if TOPS auto load package is

Fix coredump file open failed issue. The open system call accept second
argument as open file mode not the file permission. Fix the issue by
giving the right file open mode.

Complement TOPS tool description will more information.


Change-Id: Ife306851d8e01e9fbf8314d63eecbfd22a34d72b
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7961257
diff --git a/feed/tops-tool/Makefile b/feed/tops-tool/Makefile
index 621c4cd..67f5995 100644
--- a/feed/tops-tool/Makefile
+++ b/feed/tops-tool/Makefile
@@ -22,7 +22,10 @@
 define Package/tops-tool/description
-  Mediatek Tunnel Offload Processor System User Tool
+  This package is support for MediaTek tunnel offload processor system user tool.
+  The tool will monitor TOPS status, such as TOPS core utilization rate and core
+  debug dump info. Some features are not monitored by default unless user trigger
+  it to start. The tool will support logging functionality in the future.
@@ -38,9 +41,26 @@
 define Package/tops-tool/install
 	$(INSTALL_DIR) $(1)/usr/sbin
 	$(INSTALL_BIN) $(PKG_BUILD_DIR)/tops-tool $(1)/usr/sbin/
+define Package/tops-tool-autoload
+  TITLE:=Mediatek Tunnel Offload Processor System User Tool Auto Load
+  CATEGORY:=MTK Properties
+  SUBMENU:=Applications
+  DEPENDS:=tops-tool
+  DEFAULT:=y if PACKAGE_kmod-tops-release-autoload || PACKAGE_kmod-tops-dev-autoload
+define Package/tops-tool-autoload/description
+  This package is support for MediaTek tunnel offload processor system user tool
+  autoload. The tool will automatically start monitor TOPS status when system
+  boot up.
+define Package/tops-tool-autoload/install
 	$(INSTALL_DIR) $(1)/etc/init.d
 	$(INSTALL_BIN) ./files/tops-tool.init $(1)/etc/init.d/tops-tool
 $(eval $(call BuildPackage,tops-tool))
+$(eval $(call BuildPackage,tops-tool-autoload))
diff --git a/feed/tops-tool/files/tops-tool.init b/feed/tops-tool/files/tops-tool.init
index 6c4e612..57ec788 100644
--- a/feed/tops-tool/files/tops-tool.init
+++ b/feed/tops-tool/files/tops-tool.init
@@ -1,7 +1,7 @@
 #!/bin/sh /etc/rc.common
-#the priority of TOPS driver is 41
+#the priority of TOPS driver is 51
diff --git a/feed/tops-tool/src/dump.c b/feed/tops-tool/src/dump.c
index d3a8bf1..b117362 100644
--- a/feed/tops-tool/src/dump.c
+++ b/feed/tops-tool/src/dump.c
@@ -88,7 +88,7 @@
 		/* TODO: only keep latest three dump directories */
-	fd = open(dump_file, 0664);
+	fd = open(dump_file, O_WRONLY | O_CREAT, 0664);
 	if (fd < 0) {
 			DUMP_LOG_FMT("open(%s) fail(%s)\n"),