[Feature][T106][task-view-1450]add emmc io test in lynq-at-factory
Only Configure:No
Affected branch:master
Affected module:at-factory
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Change-Id: I6028fc66a583c9baaad2500e566de3b6f1b5ced2
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-at-factory/liblynq-at-factory.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-at-factory/liblynq-at-factory.cpp
index 5add3a1..fbd5a5c 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-at-factory/liblynq-at-factory.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-at-factory/liblynq-at-factory.cpp
@@ -5,6 +5,7 @@
#include <sys/time.h>
#include <unistd.h>
#include <error.h>
+#include <fcntl.h>
#include <string.h>
#include <netinet/in.h>
#include <netinet/ether.h>
@@ -101,6 +102,153 @@
pclose(fp);
}
+
+static int create_emmc_partitions()
+{
+
+ int ret = -1;
+
+ const char *fdisk_cmd = "echo -e 'n\np\n1\n\n\nw\n' | fdisk '/dev/mmcblk1'";
+
+ ret = system(fdisk_cmd);
+ if(ret < 0)
+ {
+ ALOGE("create_emmc_partitions failed");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int check_emmc_partitions()
+{
+ int fd = open("/dev/mmcblk1p1", O_RDONLY);
+
+ if(fd < 0) //no exist,need create
+ {
+ return 0;
+ }
+
+ close(fd);
+ return 1;
+}
+
+
+
+int lynq_handle_emmc_io(void)
+{
+ int fd;
+ int data_size = 512;
+ int ret;
+ char *write_buf;
+ char *read_buf;
+
+ //check partitions
+ ret = check_emmc_partitions();
+
+ if(ret == 0)//no exist
+ {
+ //create a new partitions(mmcblk1p1)
+ ret = create_emmc_partitions();
+ if(ret < 0)
+ {
+ return -1;
+ }
+
+ //check partitions again
+ ret = check_emmc_partitions();
+ if(ret < 0)
+ {
+ ALOGE("check partitions again failed");
+ }
+
+ //format partitions
+ system("echo -e '/n/n' | mkfs.ext4 /dev/mmcblk1p1");
+
+ //mount to /var/log
+ system("mount /dev/mmcblk1p1 /var/log");
+ }
+
+ //already exist,so no need to create
+
+ write_buf = malloc(data_size);
+ if(write_buf == NULL)
+ {
+ ALOGE("malloc failed");
+ return;
+ }
+
+ memset(write_buf, 0XAA, data_size);
+
+ fd = open("/var/log/emmc_test.txt", O_WRONLY | O_SYNC | O_CREAT | O_TRUNC,0600 );
+ if(fd == -1)
+ {
+ ALOGE("Open for write failed");
+ free(write_buf);
+ return -1;
+ }
+
+ //write data
+ if (write(fd, write_buf, data_size) != data_size) {
+ ALOGE("Write failed");
+ handle_output("Write failed", strlen("Write failed"), Response);
+ close(fd);
+ free(write_buf);
+ return -1;
+ }
+
+ close(fd);
+ system("sync");
+
+ //read data
+ read_buf = malloc(data_size);
+ if(read_buf == NULL)
+ {
+ ALOGE("malloc failed");
+ free(write_buf);
+ return -1;
+ }
+
+ //reopen(read mode)
+ fd = open("/var/log/emmc_test.txt", O_RDONLY);
+ if(fd == -1)
+ {
+ ALOGE("open for read failed");
+ free(write_buf);
+ free(read_buf);
+ return -1;
+ }
+
+ if(read(fd, read_buf, data_size) != data_size)
+ {
+ ALOGE("Read failed");
+ handle_output("Read failed", strlen("Read failed"), Response);
+ free(write_buf);
+ free(read_buf);
+ close(fd);
+ return -1;
+ }
+
+ //check data
+ if (memcmp(write_buf, read_buf, data_size) == 0) {
+ ALOGE("Data verification success!,");
+ handle_output("emmc write/read success", strlen("emmc write/read success"), Response);
+ close(fd);
+ free(write_buf);
+ free(read_buf);
+ return 0;
+ } else {
+ ALOGE("Data verification failed!");
+ handle_output("Data verification failed!", strlen("Data verification failed!"), Response);
+ close(fd);
+ free(write_buf);
+ free(read_buf);
+ return -1;
+ }
+}
+
+
void lynq_handle_emmc(char *input)
{
FILE *fp;
@@ -119,7 +267,14 @@
return;
}
while(fgets(buf, sizeof(buf), fp) != NULL){
- lynq_response_ok();
+ if(lynq_handle_emmc_io() < 0)
+ {
+ lynq_response_error(100);
+ }
+ else
+ {
+ lynq_response_ok();
+ }
pclose(fp);
return;
}
@@ -128,6 +283,8 @@
}
+
+
/******gpio API******/
/*sc_gpio_init(gpio, direction, value, pullsel);
sc_gpio_direction_set(test_gpio_handle[gpio], direction, 0);