2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
19 File name : _pbCommon.cpp
20 System name : 05 Integration Platform
21 Subsystem name : System wide functions
22 Title : System API _CWORD64_ configuration processes
23 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
26 #include <sys/types.h>
29 #include <vehicle_service/positioning_base_library.h>
31 #include "_pbCommon.h"
32 #include "WPF_STD_private.h"
33 #include "sysup_addr.h"
38 Constants and data type definitions
39 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
40 #define BLOCK_SIZE (1*1024*1024)
41 #define WDTC_REG_ADDR (0x13500000 | ADDR_P2) /* WDT clear register address */
43 #define ALLOC_SIZE 0x00200000
44 #define EXIST_CLEAR 0x434c4f4b /* Flag to indicate cleared Non-OS management area */
46 #define PRCM_BASE 0x48180000
47 #define PRM_RSTCTRL 0xA0
49 #define RST_GLOBAL_COLD_SW (0x01 << 1)
50 #define RST_GLOBAL_WARM_SW (0x01 << 0)
53 Internal function prototype declarations
54 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
55 u_int32 RomCheck(u_int32 *start_addr, u_int32 check_size);
56 u_int32 RomCheckEx(u_int32 *start_addr, u_int32 check_size);
57 uint64_t AtoxLong(char* str, unsigned int ascii_size);
58 void XtoaLong(uint64_t x, char* str);
59 #ifdef PBCOM_CONFIGREAD
60 static RET_API SysGetConfigSize(FILE*, u_int32*);
61 static RET_API SysReadConfigInfo(FILE*, TCHAR*, TCHAR*, u_int32);
62 static int SysUniToInt(TCHAR*, u_int32);
63 #endif /* PBCOM_CONFIGREAD */
66 External function prototype declarations
67 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
70 Global Variable Definitions
71 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
73 extern int g_n_api_set_id; /* ID variable for PSL registration */
76 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
77 * MODULE : _CWORD64_NotOSAreaInit
78 * ABSTRACT : Initialization non-OS managed areas of _CWORD64_
79 * NOTE : This function initializes the non-OS control areas of _CWORD64_.
81 * RETURN : RET_API defined
82 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
84 _CWORD64_NotOSAreaInit(void) { // LCOV_EXCL_START 8:dead code
85 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
86 #ifndef CEPC_EM /* If not emulated in CEPC */
90 u_int32 *p_clear_flag; /* Pointer for storing non-OS management area clear flag */
93 /* Link of shared memory area to store the non-OS management area clear flag */
94 ret = _pb_LinkShareData(const_cast<char*>("NOTOS_DATA"), reinterpret_cast<void**>(&cp_addr), &size);
95 if (ret != RET_NORMAL) {
96 /* Create a shared memory area to store the non-OS management area clear flag */
97 Memset64pSync(cp_addr, 0, sizeof(p_clear_flag)); /* NULL initialization process of acquisition area */
100 p_clear_flag = reinterpret_cast<u_int32*>(cp_addr);
102 /* Non-OS management area clear processing */
103 /* Because an exception occurs when garbage data remains in the message pool at startup,
104 Clear the entire non-OS management area as 0 Only for the first time after startup. */
105 if (*p_clear_flag != EXIST_CLEAR) {
106 /* Execute mapping to non-OS management area */
107 ret = PbAccessPhysicalMem(TOP_ADDR_NOTOS, /* Start address non-OS management area for of the _CWORD64_ */
108 ¬os_topaddr, /* Start address of the mapping */
109 NOTOS_SISE, /* Area-size */
113 if (ret != RET_NORMAL) {
114 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
115 "_CWORD64_msg.lib:%s:LINE %d\r\n PbAccessPhysicalMem ERROR In " \
116 "_CWORD64_NotOSAreaInit ... ret[%d] \r\n",
117 LTEXT(__FILE__), __LINE__, ret);
121 /* Non-OS management area clear processing */
122 Memset64pSync(notos_topaddr, 0, NOTOS_SISE);
124 /* Shared area release processing */
125 ret = PbFreePhysicalMem(TOP_ADDR_NOTOS, /* Start address of the _CWORD64_ non-OS management area */
126 notos_topaddr, /* Start address of the mapped area */
127 NOTOS_SISE); /* Size */
129 if (ret != RET_NORMAL) {
130 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
131 "_CWORD64_msg.lib:%s:LINE %d\r\n PbFreePhysicalMem ERROR " \
132 "In_CWORD64_NotOSAreaInit ... ret[%d] \r\n",
133 LTEXT(__FILE__), __LINE__, ret);
137 *p_clear_flag = EXIST_CLEAR; /* Set non-OS management area clear flag */
145 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
146 * MODULE : _CWORD64_APIInit
147 * ABSTRACT : System initialization of _CWORD64_API
148 * NOTE : This function is called once from the initialization process
149 * : at system startup to perform the _CWORD64_API initialization process.
150 * ARGUMENT : u_int32 (*sighand)() Completion of signal handling within APIs if NULL
151 * : Otherwise calls this first when a signal is raised
152 * RETURN : RET_API defined
153 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
155 _CWORD64_APIInit(u_int32 (*sighand)()) { // NOLINT(readability/nolint) API // LCOV_EXCL_START 8:dead code
156 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
157 RET_API RetSts = RET_ERROR;
159 if (sighand == NULL) {
160 /* Parameter is set to an error other than NULL */
161 RetSts = _pb_Setup_CWORD64_API(NULL); /* Execute initialization processing for normal processing */
168 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
169 * MODULE : _pb_GetPrgVer
170 * ABSTRACT : Get the program version
171 * NOTE : Get the program version of the mask ROM (BootLoader) and flash
172 * : ROM (NK-image) into specified buffers.
173 * : In hardware-independent CEPC emulation environment, return the following version,
174 * : otherwise always return RET_NORMAL as the return value.
175 * : mask_ver=0x0102 0304 0506 0708
176 * : flash_ver1=0x0102 0304 0506 0708
177 * : flash_ver2=0x0102 0304 0506 0708
178 * : flash_ver3=0x0102 0304 0506 0708
179 * ARGUMENT : T_SYS_PRGVER *pbuf Destination buffer address
180 * RETURN : RET_API defined
181 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
183 _pb_GetPrgVer(T_SYS_PRGVER *pbuf) { // LCOV_EXCL_START 8:dead code
184 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
189 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
190 * MODULE : _pb_UpManage
191 * ABSTRACT : Boot management process
192 * NOTE : Set the startup identifier in the SDRAM startup identification table (SDRAM)
193 * : or TinyFugue area (FLASH) at the next startup.
194 * : Which one to set depends on the table type of the argument.
195 * : Soft reset is performed when reset is instructed by the parameter.
196 * : In hardware-independent CEPC emulation environment, return the RET_NORMAL as the return value without recording the startup identifier.
197 * ARGUMENT : u_int16 up_sts :Startup Identifier Value
198 * : int reset :Reset instruction
199 * : u_int8 table :Table Type
200 * RETURN : RET_API defined
201 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
203 _pb_UpManage(u_int32 up_sts, int reset, u_int8 table) { // LCOV_EXCL_START 8:dead code
204 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
205 /* Is reset instructed? */
206 if ((reset == SYS_RESET) || (reset == SYS_ONLY_RESET)) {
207 PbReset(); /* Soft reset */
214 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
215 * MODULE : _pb_RomcheckMask
216 * ABSTRACT : Check the sum value of masked part
217 * NOTE : Check the sum value of the mask ROM (BOOTROM)
219 * RETURN : RET_API RET_NORMAL :Sum value normal
220 * REL_ERROR :Sum value error
221 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
223 _pb_RomcheckMask(void) { // LCOV_EXCL_START 8:dead code
224 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
229 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
230 * MODULE : _pb_RomcheckApl
231 * ABSTRACT : Check sum value of APL part (NK image)
232 * NOTE : In hardware-independent CEPC emulations do nothing and return RET_NORMAL.
234 * RETURN : RET_API RET_NORMAL :Sum Value Normal
235 * REL_ERROR :Sum value error
236 * RET_OSERROR :AccessPhysicalMem error
237 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
239 _pb_RomcheckApl(void) { // LCOV_EXCL_START 8:dead code
240 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
245 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
247 * ABSTRACT : Hard reset processing
248 * NOTE : Manipulate the WDT control register to generate a hard reset
249 * : Hardware-independent CEPC emulations do nothing and return RET_NORMAL.
252 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
254 PbReset(void) { // LCOV_EXCL_START 8:dead code
255 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
257 /* Message log output processing */
258 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " PbReset:%s:LINE %d\r\n #### HARD RESET !! ####\r\n",
259 LTEXT(__FILE__), __LINE__);
263 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
264 * MODULE : _pb_GetDeviceInfo
265 * ABSTRACT : Getting device information
266 * NOTE : Gets device information into the specified buffer.
267 * : In hardware-independent CEPC emulations, the following device
268 * : information is returned permanently. The return value is always RET_NORMAL.
269 * : _CWORD31__no="8611052060010001" mci_no="CNCS0200A" date="200301011200"
270 * ARGUMENT : T_SYS_PRGVER *pbuf Destination buffer address
271 * RETURN : RET_API defined
272 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
274 _pb_GetDeviceInfo(T_SYS_DEVINFO *pbuf) { // LCOV_EXCL_START 8:dead code
275 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
280 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
281 * MODULE : _pb_WriteDeviceInfo
282 * ABSTRACT : Write device key information
283 * NOTE : Write device key information to flash memory
284 * ARGUMENT : u_char *ucpData Start address of write data (256 bytes)
285 * RETURN : int32 VUP_SUCCESS Flash write complete
286 * : VUP_FAILED Flash write abend
287 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
289 _pb_WriteDeviceInfo(u_char *ucpData) { // LCOV_EXCL_START 8:dead code
290 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
295 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
296 * MODULE : _pb_GetSramVer
297 * ABSTRACT : SRAM versioning process
298 * NOTE : Getting SRAM version
299 * : In hardware-independent CEPC emulations, return the following SRAM Version statically.
300 * : The return value is always RET_NORMAL.
301 * : SRAM Version=0x1112 1314
302 * ARGUMENT : char *pbuf Destination buffer address
303 * RETURN : RET_API defined
304 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
306 _pb_GetSramVer(char *pbuf) { // LCOV_EXCL_START 8:dead code
307 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
312 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
313 * MODULE : _pb_GetDisplayInfo
314 * ABSTRACT : Getting display information
315 * NOTE : Get the screen size (width and height) into the buffer of the DISPLAY_INFO structure
316 * ARGUMENT : DISPLAY_INFO *pSystemInfo Screen size acquisition destination buffer address
317 * RETURN : RET_API defined
318 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
319 #define DISPLAYINFO_SUBKEY_SIZE 56
320 #define DISPLAYINFO_VALNAME_SIZE 16
321 #define DISPLAYINFO_VAL_SIZE 8
324 _pb_GetDisplayInfo(DISPLAY_INFO *pSystemInfo) { // LCOV_EXCL_START 8:dead code
325 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
326 #ifdef PBCOM_CONFIGREAD
327 FILE* fpConfigFile = NULL; /* Configuration file handle */
328 TCHAR tcData[DISPLAYINFO_VAL_SIZE] = {0}; /* Data section read buffer */
329 TCHAR tcDataName[DISPLAYINFO_VALNAME_SIZE] = {0}; /* Data information storage buffer */
330 int iRet = PBCOM_API_NORMAL; /* API return value */
332 int iHeight = 0; /* Screen height information */
333 int iWidth = 0; /* Screen width information */
334 RET_API Retapi = RET_NORMAL; /* Results of this Module process */
336 /************************************************************
338 ************************************************************/
339 if (NULL == pSystemInfo) {
340 /* Parameter is set to error */
341 Retapi = RET_ERRPARAM;
344 /************************************************************
345 * Set the information in the configuration file
346 ************************************************************/
347 #ifdef PBCOM_CONFIGREAD
348 /************************************************************
349 * Open configuration file
350 ************************************************************/
351 if (RET_NORMAL == Retapi) {
352 fpConfigFile = fopen(PBCOM_CONFIGFILE, "r");
353 if (NULL == fpConfigFile) {
354 /* Set error in as a result */
359 /************************************************************
360 * Get screen width information from configuration file
361 ************************************************************/
362 if (RET_NORMAL == Retapi) {
364 memset(tcData, 0x00, sizeof(tcData));
365 memset(tcDataName, 0x00, sizeof(tcDataName));
367 /* Data information setting */
368 memcpy(tcDataName, PBCOM_CONFIG_INDEX_SCRWIDTH, strlen(PBCOM_CONFIG_INDEX_SCRWIDTH));
370 /************************************************************
371 * Setting file information reading process
372 ************************************************************/
373 Retapi = SysReadConfigInfo(fpConfigFile, tcDataName, tcData, (u_int32)sizeof(tcData));
375 /************************************************************
376 * Conversion process from character string (UNICODE) to numeric
377 ************************************************************/
378 if (RET_NORMAL == Retapi) {
379 /* Conversion from string to numeric */
380 iHeight = SysUniToInt(tcData, strlen(tcData));
384 /************************************************************
385 * Get screen height information from setting file
386 ************************************************************/
387 if (RET_NORMAL == Retapi) {
389 memset(tcData, 0x00, sizeof(tcData));
390 memset(tcDataName, 0x00, sizeof(tcDataName));
392 /* Data information setting */
393 memcpy(tcDataName, PBCOM_CONFIG_INDEX_SCRHEIGHT, strlen(PBCOM_CONFIG_INDEX_SCRHEIGHT));
395 /************************************************************
396 * Setting file information reading process
397 ************************************************************/
398 Retapi = SysReadConfigInfo(fpConfigFile, tcDataName, tcData, (u_int32)sizeof(tcData));
400 /************************************************************
401 * Conversion process from character string (UNICODE) to numeric
402 ************************************************************/
403 if (RET_NORMAL == Retapi) {
404 /* Conversion from string to numeric */
405 iWidth = SysUniToInt(tcData, strlen(tcData));
409 /************************************************************
410 * Configuration file close
411 ************************************************************/
412 /* Executed only when the open is successful. */
413 if (NULL != fpConfigFile) {
414 iRet = fclose(fpConfigFile);
415 if (PBCOM_API_NORMAL != iRet) {
420 /************************************************************
421 * Direct value setting
422 ************************************************************/
427 /************************************************************
428 * Display information setting
429 ************************************************************/
431 if (RET_NORMAL == Retapi) {
432 /* Coverity CID: 18756 compliant */
433 pSystemInfo->i_height_size = iHeight;
434 pSystemInfo->i_width_size = iWidth;
435 } /* Coverity CID: 18756 compliant */
441 /******************************************************************************
443 * ABSTRACT : Calculate sum value within range of address specified by argument
444 * FUNCTION : u_int32 RomCheck()
445 * ARGUMENT : u_int32 *addr Start address for which sum value is to be calculated
446 * u_int32 check_size Size for which the sum is to be calculated
448 * RETURN : u_int32 sum Sum value
449 ******************************************************************************/
451 RomCheck(u_int32 *start_addr, u_int32 check_size) { // LCOV_EXCL_START 8:dead code
452 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
457 end_addr = start_addr + check_size / sizeof(u_int32);
458 addr_tmp = start_addr;
460 for (sum = 0; addr_tmp < end_addr;) {
461 sum += *(addr_tmp++);
467 /******************************************************************************
468 * MODULE : RomCheckEx
469 * ABSTRACT : Calculate sum value in range of address on ROM specified by argument
470 * FUNCTION : u_int32 RomCheckEx()
471 * ARGUMENT : u_int32 *addr Start address for which sum value is to be calculated
472 * u_int32 check_size Size for which the sum is to be calculated
473 * NOTE : For single operation(For a one-bank configuration). APIs provided by FROM management
474 * are used because FROM management must be exclusively controled.
475 * The sum calculation unit is assumed to be the sector size of FlashROM.
476 * RETURN : u_int32 sum Sum value
477 * When this function terminates with an error, "RET_ERROR" is returned.
478 ******************************************************************************/
480 RomCheckEx(u_int32 *start_addr, u_int32 check_size) { // LCOV_EXCL_START 8:dead code
481 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
486 /*******************************************************************************
488 * ABSTRACT : Convert ASCII to hex
489 * FUNCTION : Convert a ASCII string (up to 8 characters) to a uint64_t hexadecimal string
491 * RETURN : uint64_t :Converted hexadecimal number (up to 8 digits)
492 * INPUT : char *str -------------------- Pointer to a source ASCII string
493 * unsigned int ascii_size ------ Number of characters in source ASCII string
495 ******************************************************************************/
496 uint64_t AtoxLong(char* str, unsigned int ascii_size) { // LCOV_EXCL_START 8:dead code
497 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
498 uint64_t x = 0; /* Return value */
499 unsigned int i; /* For work */
500 unsigned int tmp; /* For work */
502 /* Check that the specified ASCII number of characters does not exceed the number of digits represented by int64_t (8 hexadecimal digits). */
503 if (ascii_size > (sizeof(x)) * 2) {
504 ascii_size = static_cast<unsigned int>(sizeof(x) * 2);
506 /* Convert one character at a time to hexadecimal */
507 for (i = 0; i < ascii_size; i++) {
511 /* Coverity CID: 18790 compliant */
513 tmp = *str - 'a' + 10;
514 if ((tmp < 0x0a) || (tmp > 0x0f)) {
516 tmp = *str - 'A' + 10;
517 if ((tmp < 0x0a) || (tmp > 0x0f)) {
518 /* Stop when a non-hexadecimal value is found */
524 /* Increase the digit */
526 /* Add to the bottom digit */
535 /*******************************************************************************
537 * ABSTRACT : Convert HEX to ASCII
538 * FUNCTION : This function converts the 8-digit hexadecimal number from str[0] to the ASCII code and stores the code.
539 * NOTE : The string to be passed as *str must be at least 8 characters in length. * RETURN :
540 * INPUT : uint64_t x ------------ Source hexadecimal number
541 * OUTPUT : char* str ------------------ Converted ASCII Strings (8 Characters)
542 ******************************************************************************/
543 void XtoaLong(uint64_t x, char* str) { // LCOV_EXCL_START 8:dead code
544 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
545 int i; /* For looping */
546 int size; /* For looping */
547 char tmp; /* Conversion temporary buffer */
549 /* Maximum number of loops (for character string) */
550 size = static_cast<int>(sizeof(int64_t) * 2);
551 /* Convert eight digits */
552 for (i = 0; i < size; i++) {
553 tmp = static_cast<char>((x >> ((size - i - 1) * 4)) & 0x0F);
557 str[i] = static_cast<char>('A' + tmp - 0x0A);
559 str[i] = static_cast<char>('0' + tmp);
565 /******************************************************************************
566 * MODULE : _pb_SendSystemError
567 * ABSTRACT : System error notification
568 * FUNCTION : Notify the system error and reset the software.
569 * ARGUMENT : PNO pno Error process No.
570 * int32 errcode Error code
571 * NOTE : _pb_SndMsg : Send message (System API)
572 * _sys_GetPno : PNO to be gotten
573 * RETURN : RET_API defined
574 ******************************************************************************/
575 RET_API _pb_SendSystemError(PNO pno, int32 errcode) { // LCOV_EXCL_START 8:dead code
576 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
577 T_SYS_SYSTEMERROR msg; /* Message */
578 register T_APIMSG_HEADER *hdr; /* Message header */
581 /* Message Header Settings */
582 hdr = &(msg.bhead.hdr);
584 msg.bhead.signo = 0; /* Extension member */
585 hdr->sndpno = 0; /* Source Process No. */
586 hdr->respno = 0; /* Response destination process No.(None) */
587 hdr->cid = CID_INI_SYSTEMERR; /* Command ID */
588 hdr->msgbodysize = static_cast<uint16_t>(sizeof(T_SYS_SYSTEMERROR) - sizeof(T_APIMSG_MSGBUF_HEADER));
590 hdr->rid = 0; /* Resources ID (Dummy) */
592 msg.pno = pno; /* Error process No. */
593 msg.errcode = errcode; /* Error code */
596 api_ret = _pb_SndMsg(PNO_GINI_MAIN, sizeof(msg), &msg, 0);
602 /******************************************************************************
603 * MODULE : _pb_GetVupFileName
604 * ABSTRACT : Getting the version upgrade file name
605 * FUNCTION : Get the path name and file name of the version upgrade.
606 * ARGUMENT : LPTSTR filename File name storage
607 * u_char media Container media
609 * RETURN : RET_API defined
610 ******************************************************************************/
611 RET_API _pb_GetVupFileName(LPTSTR filename , u_char media) { // LCOV_EXCL_START 8:dead code
612 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
613 RET_API api_ret = RET_NORMAL; /* API return value */
614 T_SYS_PRGVER ver; /* Version Information */
615 RET_API ret; /* Internal function return value */
616 u_char kisyu; /* Storage of model code */
619 ret = _pb_GetPrgVer(&ver);
621 if (ret == RET_NORMAL) {
622 /* Extract model code from version */
623 kisyu = ver.mask_ver[3];
625 /* If the media is a disk */
626 if (media == VUP_GETNAME_MEDIA_DISC) {
627 _stprintf(filename, _T("%s%s%s%02x%s"),
628 VUP_DISC_PATHNAME, VUP_PATHNAME_SYSTEM, VUP_FNAME_TOP, kisyu, VUP_FNAME_BTM);
631 _stprintf(filename, _T("%s%s%s%02x%s"),
632 VUP_USB_PATHNAME, VUP_PATHNAME_SYSTEM, VUP_FNAME_TOP, kisyu, VUP_FNAME_BTM);
642 /******************************************************************************
643 * MODULE : _pb_GetForceVupFileName
644 * ABSTRACT : Getting the version upgrade file name
645 * FUNCTION : Get the path name and file name of the version upgrade.
646 * ARGUMENT : LPTSTR filename File name storage
647 * u_char media Container media
649 * RETURN : RET_API defined
650 ******************************************************************************/
651 RET_API _pb_GetForceVupFileName(LPTSTR filename , u_char media) { // LCOV_EXCL_START 8:dead code
652 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
653 RET_API api_ret = RET_NORMAL; /* API return value */
655 /* If the media is a disk */
656 if (media == VUP_GETNAME_MEDIA_DISC) {
657 _stprintf(filename, _T("%s%s%s"),
658 VUP_DISC_PATHNAME, VUP_PATHNAME_SYSTEM, VUP_FNAME_FORCEVUP);
661 _stprintf(filename, _T("%s%s%s"),
662 VUP_USB_PATHNAME, VUP_PATHNAME_SYSTEM, VUP_FNAME_FORCEVUP);
669 #ifdef PBCOM_CONFIGREAD
670 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
671 * MODULE : SysGetConfigSize
672 * ABSTRACT : Setting file size acquisition processing
673 * NOTE : Get file size.
674 * : When this Module is called, an area must be allocated at a higher level.
675 * : Parameter checking is not performed in this Module.
676 * ARGUMENT : FILE* fpFile(File handle)
677 * : int* piSize(File size storage area)
678 * RETURN : RET_API defined
679 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
681 SysGetConfigSize(FILE* fpFile, u_int32* puiSize) {
682 int64_t lCurrentPos = 0; /* File current position */
683 int64_t lEndPos = 0; /* End position of the file */
684 int iRet = PBCOM_API_NORMAL; /* API processing result */
685 RET_API Retapi = RET_NORMAL; /* Result of this Module process */
687 /************************************************************
689 ************************************************************/
690 lCurrentPos = ftell(fpFile);
692 /* If the return value is abnormal, the processing result is set to abnormal. */
693 if (PBCOM_API_ERROR == lCurrentPos) {
697 /************************************************************
698 * Get end offset (size)
699 * -Set offset to end-of-file
700 * -Get end-of-file offset
701 ************************************************************/
702 if (RET_NORMAL == Retapi) {
703 /* Set offset to end-of-file */
704 iRet = fseek(fpFile, 0L, SEEK_END);
706 /* If the return value is abnormal, the processing result is set to abnormal. */
707 if (PBCOM_API_NORMAL != iRet) {
712 if (RET_NORMAL == Retapi) {
713 /* Get end-of-file offset */
714 lEndPos = ftell(fpFile);
716 /* Set file size if the return value is normal */
717 if (PBCOM_API_ERROR != lEndPos) {
718 *puiSize = (u_int32)lEndPos;
720 /* If the return value is abnormal, the processing result is set to abnormal. */
725 /************************************************************
726 * Revert current offset
727 ************************************************************/
728 if (RET_NORMAL == Retapi) {
729 /* Revert offset and complete processing */
730 iRet = fseek(fpFile, lCurrentPos, SEEK_SET);
732 /* If the return value is abnormal, the processing result is set to abnormal. */
733 if (PBCOM_API_NORMAL != iRet) {
740 #endif /* PBCOM_CONFIGREAD */
742 #ifdef PBCOM_CONFIGREAD
743 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
744 * MODULE : SysReadConfigInfo
745 * ABSTRACT : Setting file information reading process
746 * NOTE : Read the data associated with the specified data information from the configuration file.
747 * : When this module is called, an area must be allocated at a higher level.
748 * : Parameter checking is not performed in this module.
749 * ARGUMENT : FILE* fpConfig(File handle)
750 * : TCHAR* tcDataIndex(Data information)
751 * : TCHAR* tcDataBuf(Data read buffer)
752 * : int tcDataSize(Data read size)
753 * RETURN : RET_API defined
754 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
756 SysReadConfigInfo(FILE* fpConfig, TCHAR* tcDataIndex, TCHAR* tcDataValue, u_int32 tcDataSize) {
757 TCHAR tcReadBuf[PBCOM_CONFIGSIZE_MAX] = {0}; /* Read buffer */
758 u_int32 uiDataPos = 0; /* Data position */
759 u_int32 uiCpyPos = 0; /* Copy position */
760 u_int32 uiFileSize = 0; /* File size */
761 u_int32 uiReadSize = 0; /* Data read size */
762 u_int32 uiDataNum = 0; /* Number of read data */
763 int iRet = 0; /* API processing result */
764 RET_API Retapi = RET_NORMAL; /* Result of this Module process */
766 /************************************************************
767 * Get setting file size
768 ************************************************************/
769 /* Get setting file size */
770 Retapi = SysGetConfigSize(fpConfig, &uiFileSize);
772 /* When the setting file size is gotten successfully */
773 if (RET_NORMAL == Retapi) {
774 /* The maximum size of the configuration file is greater than or equal to the maximum size of the configuration file. */
775 if (uiFileSize > PBCOM_CONFIGSIZE_MAX) {
776 /* Set the maximum value of the configuration file as the size */
777 uiFileSize = PBCOM_CONFIGSIZE_MAX;
781 /************************************************************
783 ************************************************************/
784 if (RET_NORMAL == Retapi) {
785 /* Read data count */
786 uiDataNum = uiFileSize / sizeof(TCHAR);
788 /* Set file pointer to the beginning of file */
792 uiReadSize = fread(tcReadBuf, sizeof(TCHAR), uiDataNum, fpConfig);
794 /* When the data corresponding to the file size cannot be read */
795 if (uiReadSize != uiFileSize) {
796 /* Set error in processing result */
801 /************************************************************
802 * Data information search & retrieval
803 * -Find data information from the configuration file you read
804 * -Read associated data if data information can be found
805 ************************************************************/
806 if (RET_NORMAL == Retapi) {
807 /* Set error to processing result (Set normal when search is normal) */
810 for (uiDataPos = 0; uiDataPos < uiDataNum; uiDataPos++) {
811 /* Determine file information */
812 iRet = memcmp(&tcReadBuf[uiDataPos], tcDataIndex, strlen(tcDataIndex));
814 /************************************************************
815 * If the applicable data information(Data information matched)
816 ************************************************************/
818 /* Move to data position (Move file information)*/
819 uiDataPos += strlen(tcDataIndex) / sizeof(TCHAR);
821 /* Set normal to processing result for data discovery */
824 /************************************************************
825 * Data read processing
826 * -Read data from the read data size
827 * -Assume that he end of the data has been reached when the following conditions are met
828 * NULL character code
829 * Line feed character code
830 * The data end of the configuration file is exceeded.
831 ************************************************************/
832 for (uiCpyPos = 0; uiCpyPos < tcDataSize; uiCpyPos++) {
833 if (uiDataNum > uiDataPos) {
834 /* Coverity CID: 18781 compliant */
835 /* If it is valid data */
836 if ((PBCOM_UNICODE_NUL != tcReadBuf[uiDataPos]) &&
837 (PBCOM_UNICODE_LF != tcReadBuf[uiDataPos])) {
839 tcDataValue[uiCpyPos] = tcReadBuf[uiDataPos];
841 /* Exit from this loop */
845 /* When the end of data is reached */
846 /* Exit from this loop */
849 /* Move the data position by the set amount */
852 /************************************************************
853 * Completion of data information search
854 ************************************************************/
857 /************************************************************
858 * Not applicable data information(Data information mismatch)
859 ************************************************************/
860 /************************************************************
861 * Move to next data information
862 * -Determine supine data if following condition is met
863 * Line feed character code
864 * -End processing when the end of file is reached
865 ************************************************************/
866 while (uiDataPos < uiDataNum) {
867 /* Data determination */
868 if (PBCOM_UNICODE_LF == tcReadBuf[uiDataPos]) {
869 /*Next Data Detection */
872 /* Move the data by the determined amount */
880 #endif /* PBCOM_CONFIGREAD */
882 #ifdef PBCOM_CONFIGREAD
883 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
884 * MODULE : SysUniToInt
885 * ABSTRACT : Converting from Unicode(string) to Int(number)
886 * NOTE : Convert from Unicode(string) to Int(number).
887 * : The number of characters that can be converted is defined in PBCOM_UTOIMAX_NUM.
888 * : When this module is called, an area must be allocated at a higher level.
889 * : Parameter checking is not performed in this module.
890 * ARGUMENT : TCHAR* tcData(Character string storage area)
891 * : int iDataSize(Character array size)
892 * RETURN : Number converted from character string
893 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
894 static int SysUniToInt(TCHAR* tcData, u_int32 iDataSize) {
895 int iValue = 0; /* Converted value */
896 u_int8 ucCount = 0; /* Character string data position */
898 /************************************************************
900 ************************************************************/
901 if (PBCOM_UTOIMAX_NUM < iDataSize) {
902 iDataSize = PBCOM_UTOIMAX_NUM;
905 /************************************************************
906 * Conversion from string to number
907 ************************************************************/
908 for (ucCount = 0; ucCount < iDataSize; ucCount++) {
909 /*If it is a number */
910 if ((tcData[ucCount] >= '0') &&
911 (tcData[ucCount] <= '9')) {
912 iValue = (iValue * 10) + (tcData[ucCount] - '0');
914 /* If it is not a digit */
921 #endif /* PBCOM_CONFIGREAD */
924 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
925 End of File : _sysCommon.cpp
926 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *