factory_file_parser.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #ifdef CONFIG_SPECIALFILE1_CONTAINCHECK
  2. #include "stdio.h"
  3. #include "types.h"
  4. #include <rom_def.h>
  5. #include <factory_file_parser.h>
  6. #include <drv_kmf_interface.h>
  7. #define FIELD_NUM 5
  8. BOOL bFactory_File_Exit=FALSE;
  9. struct field {
  10. const char *tag;
  11. int value;
  12. };
  13. struct factory_file {
  14. struct field fields[FIELD_NUM];
  15. };
  16. struct factory_file ft_file = { \
  17. { \
  18. {"P",0}, \
  19. {"B",0}, \
  20. {"M",0}, \
  21. {"F",0}, \
  22. {"R",0}, \
  23. },\
  24. };
  25. static void get_line(char *file_data, int line, char *ret_line)
  26. {
  27. int i, j, s, e;
  28. int current_line = 0;
  29. char *ptr;
  30. s = 0;
  31. for (i = 0; i < 2048; i++) {
  32. if (file_data[i] == '\n' || file_data[i] == '\0') {
  33. current_line++;
  34. if (current_line > line) {
  35. e = i;
  36. break;
  37. } else {
  38. s = i+1;
  39. }
  40. }
  41. }
  42. memcpy(ret_line, &file_data[s], e-s);
  43. ret_line[e-s] = '\0';
  44. if (ret_line[e-s-1] == '\r')
  45. ret_line[e-s-1] = '\0';
  46. }
  47. static int paser_field(char *line)
  48. {
  49. char tag[256];
  50. char value[256];
  51. int i,j;
  52. j = 0;
  53. for (i = 0; i < 256; i++) {
  54. if ((line[i] != ' ') && (line[i] != ':')) {
  55. tag[j++] = line[i];
  56. } else if (line[i] == ':') {
  57. tag[j] = '\0';
  58. i++;
  59. break;
  60. }
  61. }
  62. j = 0;
  63. for (i; i < 256; i++) {
  64. if ((line[i] != ' ') && (line[i] != '\0')) {
  65. if ((line[i] >= '0') && (line[i] <= '9'))
  66. value[j++] = line[i];
  67. } else if (line[i] == '\0') {
  68. value[j] = '\0';
  69. break;
  70. }
  71. }
  72. for (i = 0; i < FIELD_NUM; i++) {
  73. if(!strcmp(ft_file.fields[i].tag, tag)) {
  74. ft_file.fields[i].value = myatoi(value);
  75. break;
  76. }
  77. }
  78. if (i != FIELD_NUM) {
  79. printf("tag:%s value:%s\n", tag, value);
  80. return TRUE;
  81. } else {
  82. printf("unknow tag:%s\n", tag);
  83. return FALSE;
  84. }
  85. }
  86. BOOL parser_special_file(char *file_data)
  87. {
  88. int i,ret;
  89. char line[256];
  90. for (i = 0; i < 10; i++) {
  91. memset(line,0x0,256);
  92. get_line(file_data,i, line);
  93. if (line[0] == 'Z')
  94. break;
  95. ret = paser_field(line);
  96. if (ret == FALSE) {
  97. printf(" special_file format error!!!!\n");
  98. return FALSE;
  99. }
  100. }
  101. if(get_special_value("P")>0 && get_special_value("P")<4)
  102. bFactory_File_Exit = TRUE;
  103. return TRUE;
  104. }
  105. int get_special_value(const char *tag)
  106. {
  107. int i;
  108. int ret = -1;
  109. for (i = 0; i < FIELD_NUM; i++) {
  110. if(!strcmp(ft_file.fields[i].tag, tag)) {
  111. ret = ft_file.fields[i].value;
  112. break;
  113. }
  114. }
  115. return ret;
  116. }
  117. BOOL has_factory_file()
  118. {
  119. return bFactory_File_Exit;
  120. }
  121. void factory_file_setting(Factory_File_Setting status)
  122. {
  123. BootRomShareData_t *BootromShareData = (void *) KMFBR_ShareData_ShadowAddress;
  124. int panel_index = 0;
  125. int BurnMode = 0;
  126. if(bFactory_File_Exit)
  127. {
  128. if(status==Factory_Panel_Resolution)
  129. {
  130. panel_index = get_special_value("P");
  131. switch(panel_index)
  132. {
  133. case 0:
  134. BootromShareData->Panelresolution = 0;
  135. break;
  136. case 1:
  137. BootromShareData->Panelresolution = 1440;
  138. break;
  139. case 2:
  140. BootromShareData->Panelresolution = 1366;
  141. break;
  142. case 3:
  143. BootromShareData->Panelresolution = 1920;
  144. break;
  145. default:
  146. BootromShareData->Panelresolution = 0;
  147. break;
  148. }
  149. }
  150. else if (status==Factory_BurnMode)
  151. {
  152. BurnMode = get_special_value("B");
  153. if(BurnMode)
  154. *(volatile UINT8 *)OnEvent_INT_Status_MMIOAddress |= Special_FileBit1;
  155. }
  156. }
  157. }
  158. #endif //CONFIG_SPECIALFILE1_CONTAINCHECK