1 /*
2 * emmc_test.c -- emmc test application
3 *
4 * Copyright (c) 2017 Rockchip Electronics Co. Ltd.
5 * Author: Panzhenzhuan Wang <randy.wang@rock-chips.com>
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27 #include <unistd.h>
28
29 #include "test_case.h"
30 #include "emmc_test.h"
31 #include "language.h"
32 #include "common.h"
33
34 #define TAG "[PCBA,EMMC]: "
35 #define LOG(x...) printf(TAG x)
36
37 //
38 #ifdef PCBA_PX3SE
39 #define EMMCPATH "/sys/bus/mmc/devices/mmc0:1234/block/mmcblk0/size"
40 #else
41 #define EMMCPATH "/sys/bus/mmc/devices/mmc0:0001/block/mmcblk0/size"
42 #endif
43
44 #define EMMCPATH1 "/sys/bus/mmc/devices/mmc1:0001/block/mmcblk1/size"
45 #define READ_DDR_COMMAND "cat /proc/zoneinfo | busybox grep present | \
46 busybox awk 'BEGIN{a=0}{a+=$2}END{print a}'"
47
48 #define RKNAND_TEST_CMD "cat /proc/rknand > %s"
49 #define RKNAND_TEST_FILE "/tmp/rknand_test.txt"
50
51
52 /* for emmc */
readFromFile(const char * path,char * emmcsize_char,size_t size)53 static int readFromFile(const char *path, char *emmcsize_char, size_t size)
54 {
55 if (!path)
56 return -1;
57
58 int fd = open(path, O_RDONLY|O_NOCTTY|O_NDELAY, 0);
59 if (fd == -1) {
60 printf("open '%s' failed!\n", path);
61 return -1;
62 }
63 ssize_t count = read(fd, emmcsize_char, size);
64
65 //�������Ч���ַ��ֽ���
66 if (count > 0) {
67 while (count > 0 && emmcsize_char[count-1] == '\n')
68 count--;
69 emmcsize_char[count] = '\0';
70 } else {
71 emmcsize_char[0] = '\0';
72 }
73 close(fd);
74 return count;
75 }
76
get_emmc_size(char * size_data)77 int get_emmc_size(char *size_data)
78 {
79 int count;
80 int emmc_size=1;
81 double size = (double)(atoi(size_data))/2/1024/1024; //��Ҫ #include<stdlib.h>
82
83 if (size > 0 && size <= 1) /*1 GB */
84 return 1;
85 for (count = 1; count < 10; count++)
86 {
87 if ((size > emmc_size) && (size <= emmc_size*2)) /*2 - 512 GB*/
88 return emmc_size*2;
89
90 emmc_size *=2;
91 }
92 return -1;
93 }
94
95 #ifdef PCBA_PX3SE//emmc
emmc_test(void * argv)96 void *emmc_test(void *argv)
97 {
98 struct testcase_info *tc_info = (struct testcase_info *)argv;
99 int emmc_ret = 0;
100 char emmcsize_char[20];
101 int emmc_size = 0;
102
103 char cmd[128];
104
105 if (tc_info->y <= 0)
106 tc_info->y = get_cur_print_y();
107
108 ui_print_xy_rgba(0, tc_info->y, 255, 255, 0, 255, "%s:[%s..]\n",
109 PCBA_DDR_EMMC, PCBA_TESTING);
110
111 LOG("======= emmc test starting ========\n");
112 //sprintf(cmd,"aplay %s/emmc_test_start.wav",AUDIO_PATH);
113 //system(cmd);
114 //system("aplay /data/test/emmc_test_start.wav");
115 /* For emmc */
116 memset(emmcsize_char, 0, sizeof(emmcsize_char));
117 emmc_ret = readFromFile(EMMCPATH, emmcsize_char, sizeof(emmcsize_char));
118
119 printf("readFromFile effective bytes is %d \n",emmc_ret);
120 if (emmc_ret < 0) {
121 emmc_ret = readFromFile(EMMCPATH1, emmcsize_char, sizeof(emmcsize_char));
122 }
123
124 if (emmc_ret >= 0) { /*read back normal*/
125 emmc_size = get_emmc_size(emmcsize_char);
126 if(emmc_size < 0){
127 emmc_ret = -1;
128 }
129 LOG("======= emmc_size is: %d GB ========\n",emmc_size);
130 }
131
132 if (emmc_ret >= 0) {
133 ui_print_xy_rgba(0, tc_info->y, 0, 255, 0, 255,
134 "%s:[%s] { %s:%dGB }\n",
135 PCBA_EMMC, PCBA_SECCESS,
136 PCBA_EMMC, emmc_size);
137
138 tc_info->result = 1;
139 } else {
140 ui_print_xy_rgba(0, tc_info->y, 0, 255, 0, 255,
141 "%s:[%s] { %s: Get capacity Fail.}\n",
142 PCBA_EMMC, PCBA_FAILED,
143 PCBA_EMMC);
144
145 tc_info->result = -1;
146 }
147
148 return argv;
149 }
150 #endif
151
152 #ifdef PCBA_3308
emmc_test(void * argv)153 void *emmc_test(void *argv)
154 {
155 char cmd[128];
156 char buf[128];
157 FILE *fp;
158 int emmc_ret = -1;
159
160 printf("======= emmc test starting ========\n");
161
162 sprintf(cmd,RKNAND_TEST_CMD,RKNAND_TEST_FILE);
163 system(cmd);
164 printf("cmd is: %s.\n",cmd);
165 sleep(1);
166 fp = fopen(RKNAND_TEST_FILE, "r");
167 //����ļ���ʧ�ܣ������������Ϣ
168 if (!fp)
169 {
170 printf("%s fopen err:%s\n",__func__,strerror(errno));
171 return (void*)-1;
172 }
173
174 //����Ƿ���� "Device Capacity: 4096 MB"��Ϣ�������˵�������������������ʧ��
175 while(!feof(fp))
176 {
177 fgets(buf,sizeof(buf),fp);
178 if(strstr(buf,"Device Capacity: 256 MB")!=NULL)
179 {
180 emmc_ret = 0;
181 break;
182 }
183 }
184 fclose(fp);
185 remove(RKNAND_TEST_FILE);
186
187 printf("\n=================== function :%s finish======================\n",__func__);
188 return (void*)emmc_ret;
189 }
190 #endif
191
192
193