[][MAC80211][WiFi6/7][app][Fix atenl sync eeprom all issue]

[Description]
Fix atenl sync eeprom all issue
If two or more chip devices use flash mode, it is possibe to cross
the user-specified boundary when we call "sync eeprom all" to
write the entire atenl eeprom temp file into mtd.
Note that the size of atenl eeprom temp file is fixed
at 0xFF000 for Eagle pre-cal.
Therefore, we utilize the dd cmd to slice the file to
a proper size before writting it to mtd.

[Release-log]
N/A

Change-Id: Id26d757d5422ef985b5775b0c2c1daa007905676
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/8234404
diff --git a/feed/atenl/src/eeprom.c b/feed/atenl/src/eeprom.c
index d7a2467..d112dc7 100644
--- a/feed/atenl/src/eeprom.c
+++ b/feed/atenl/src/eeprom.c
@@ -424,30 +424,27 @@
 
 int atenl_eeprom_write_mtd(struct atenl *an)
 {
+#define TMP_FILE	"/tmp/tmp_eeprom.bin"
 	pid_t pid;
-	char offset[10];
+	u32 size = an->eeprom_size;
+	u32 *precal_info = an->eeprom_data + an->eeprom_size;
+	u32 precal_size = precal_info[0] + precal_info[1];
+	char cmd[100];
 
 	if (an->mtd_part == NULL || !(~an->mtd_offset))
 		return 0;
 
-	pid = fork();
-	if (pid < 0) {
-		perror("Fork");
-		return EXIT_FAILURE;
-	} else if (pid == 0) {
-		int ret;
-		char *part = strdup(an->mtd_part);
-		snprintf(offset, sizeof(offset), "%d", an->mtd_offset);
-		char *cmd[] = {"mtd", "-p", offset, "write", eeprom_file, part, NULL};
+	if (precal_size)
+		size += PRE_CAL_INFO + precal_size;
+
+	sprintf(cmd, "dd if=%s of=%s bs=1 count=%d", eeprom_file, TMP_FILE, size);
+	system(cmd);
+
+	sprintf(cmd, "mtd -p %d write %s %s", an->mtd_offset, TMP_FILE, an->mtd_part);
+	system(cmd);
 
-		ret = execvp("mtd", cmd);
-		if (ret < 0) {
-			atenl_err("%s: exec error\n", __func__);
-			exit(0);
-		}
-	} else {
-		wait(&pid);
-	}
+	sprintf(cmd, "rm %s", TMP_FILE);
+	system(cmd);
 
 	return 0;
 }