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

[Description]
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
enabled.

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.

[Release-log]
N/A

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 @@
 endef
 
 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.
 endef
 
 TARGET_CFLAGS += \
@@ -38,9 +41,26 @@
 define Package/tops-tool/install
 	$(INSTALL_DIR) $(1)/usr/sbin
 	$(INSTALL_BIN) $(PKG_BUILD_DIR)/tops-tool $(1)/usr/sbin/
+endef
+
+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
+endef
+
+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.
+endef
 
+define Package/tops-tool-autoload/install
 	$(INSTALL_DIR) $(1)/etc/init.d
 	$(INSTALL_BIN) ./files/tops-tool.init $(1)/etc/init.d/tops-tool
 endef
 
 $(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
-START=42
+#the priority of TOPS driver is 51
+START=52
 
 USE_PROCD=1
 NAME=tops-tool
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) {
 		fprintf(stderr,
 			DUMP_LOG_FMT("open(%s) fail(%s)\n"),