mirror of
https://github.com/openharmony/developtools_syscap_codec.git
synced 2026-08-27 02:11:19 -04:00
Uniform syscap length.
Signed-off-by: yudechen <chenyude@huawei.com> Change-Id: I68c43b300e2a729aae0a1aa7a287ee1916b1c5a1
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MAX_OS_SYSCAP_NUM 960
|
||||
#define OS_SYSCAP_BYTES 120
|
||||
#define TYPE_FILE 1
|
||||
#define TYPE_STRING 2
|
||||
|
||||
@@ -28,7 +28,7 @@ typedef struct ProductCompatibilityID {
|
||||
uint16_t systemType : 3;
|
||||
uint16_t reserved : 13;
|
||||
uint32_t manufacturerID;
|
||||
uint8_t osSyscap[MAX_OS_SYSCAP_NUM / 8];
|
||||
uint8_t osSyscap[OS_SYSCAP_BYTES];
|
||||
} PCIDMain;
|
||||
|
||||
typedef struct pcidHeader {
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
#ifndef _SYSCAP_DEFINE_H
|
||||
#define _SYSCAP_DEFINE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SINGLE_SYSCAP_LEN (256 + 17)
|
||||
|
||||
typedef struct SystemCapabilityWithNum {
|
||||
char syscapStr[128];
|
||||
char syscapStr[SINGLE_SYSCAP_LEN];
|
||||
uint16_t num;
|
||||
} SyscapWithNum;
|
||||
|
||||
|
||||
@@ -247,8 +247,13 @@ bool DecodePrivateSyscap(char *input, char (**output)[SINGLE_SYSCAP_LEN], int *o
|
||||
}
|
||||
inputPos++;
|
||||
}
|
||||
inputPos = input;
|
||||
if (syscapCnt == 0) {
|
||||
*output = outputArray;
|
||||
*outputCnt = syscapCnt;
|
||||
return true;
|
||||
}
|
||||
|
||||
inputPos = input;
|
||||
bufferLen = SINGLE_SYSCAP_LEN * syscapCnt;
|
||||
outputArray = (char (*)[SINGLE_SYSCAP_LEN])malloc(bufferLen);
|
||||
if (outputArray == NULL) {
|
||||
|
||||
@@ -19,9 +19,13 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef SINGLE_SYSCAP_LEN
|
||||
#define SINGLE_SYSCAP_LEN (256 + 17)
|
||||
#endif // SINGLE_SYSCAP_LEN
|
||||
#define MAX_MISS_SYSCAP 512
|
||||
#define SINGLE_SYSCAP_LEN 256
|
||||
#define PCID_MAIN_BYTES 128
|
||||
#define PCID_MAIN_INTS 32
|
||||
|
||||
#define E_OK 0
|
||||
#define E_APIVERSION 1
|
||||
#define E_SYSCAP 2
|
||||
|
||||
@@ -27,7 +27,6 @@ EXTERN_C_START
|
||||
constexpr size_t OS_SYSCAP_U32_NUM = 30;
|
||||
constexpr size_t PCID_MAIN_U32 = OS_SYSCAP_U32_NUM + 2;
|
||||
constexpr size_t U32_TO_STR_MAX_LEN = 11;
|
||||
constexpr size_t PCID_MAIN_LEN = 128;
|
||||
constexpr size_t KEY_BUFFER_SIZE = 32;
|
||||
|
||||
#define PRINT_ERR(...) \
|
||||
@@ -71,7 +70,7 @@ static char* getSystemCapability()
|
||||
char osCapArray[PCID_MAIN_U32][U32_TO_STR_MAX_LEN] = {};
|
||||
char (*priCapArray)[SINGLE_SYSCAP_LEN] = nullptr;
|
||||
|
||||
retBool = EncodeOsSyscap(osOutput, PCID_MAIN_LEN);
|
||||
retBool = EncodeOsSyscap(osOutput, PCID_MAIN_BYTES);
|
||||
if (!retBool) {
|
||||
PRINT_ERR("get encoded os syscap failed.");
|
||||
return nullptr;
|
||||
|
||||
+20
-20
@@ -30,12 +30,12 @@
|
||||
#include "syscap_define.h"
|
||||
#include "create_pcid.h"
|
||||
|
||||
#define SINGLE_FEAT_LENGTH (32 * 8)
|
||||
#define PER_SYSCAP_LEN_MAX 128
|
||||
#define SYSCAP_PREFIX_LEN 17
|
||||
#define SINGLE_FEAT_LEN (SINGLE_SYSCAP_LEN - SYSCAP_PREFIX_LEN)
|
||||
#define PCID_OUT_BUFFER 32
|
||||
#define PRIVATE_SYSCAP_SIZE 1000
|
||||
#define UINT8_BIT 8
|
||||
#define BYTES_OF_OS_SYSCAP 120
|
||||
|
||||
#define U32_TO_STR_MAX_LEN 11
|
||||
|
||||
#define PRINT_ERR(...) \
|
||||
@@ -264,7 +264,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath)
|
||||
}
|
||||
sectorOfBits = (osCapIndex->valueint) / UINT8_BIT;
|
||||
posOfBits = (osCapIndex->valueint) % UINT8_BIT;
|
||||
if (sectorOfBits >= BYTES_OF_OS_SYSCAP) {
|
||||
if (sectorOfBits >= OS_SYSCAP_BYTES) {
|
||||
PRINT_ERR("num of \"os syscap\" is out of 960\n");
|
||||
ret = -1;
|
||||
goto FREE_PCID_BUFFER_OUT;
|
||||
@@ -341,8 +341,8 @@ int32_t DecodePCID(char *inputFile, char *outDirPath)
|
||||
int32_t ret;
|
||||
errno_t nRet = 0;
|
||||
char *contextBuffer = NULL;
|
||||
uint8_t osSyscap[BYTES_OF_OS_SYSCAP] = {0};
|
||||
uint16_t indexOfSyscap[BYTES_OF_OS_SYSCAP * UINT8_BIT] = {0};
|
||||
uint8_t osSyscap[OS_SYSCAP_BYTES] = {0};
|
||||
uint16_t indexOfSyscap[OS_SYSCAP_BYTES * UINT8_BIT] = {0};
|
||||
uint32_t i, j, contextBufLen, countOfSyscap = 0;
|
||||
|
||||
ret = GetFileContext(inputFile, &contextBuffer, &contextBufLen);
|
||||
@@ -369,7 +369,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath)
|
||||
ret = -1;
|
||||
goto FREE_CONTEXT_OUT;
|
||||
}
|
||||
|
||||
|
||||
cJSON *capVectorPtr = cJSON_CreateArray();
|
||||
if (capVectorPtr == NULL) {
|
||||
PRINT_ERR("cJSON_CreateArray failed\n");
|
||||
@@ -377,13 +377,13 @@ int32_t DecodePCID(char *inputFile, char *outDirPath)
|
||||
goto FREE_CONTEXT_OUT;
|
||||
}
|
||||
|
||||
nRet = memcpy_s(osSyscap, BYTES_OF_OS_SYSCAP, (uint8_t *)pcidMain + 8, BYTES_OF_OS_SYSCAP); // 8, bytes of pcid header
|
||||
nRet = memcpy_s(osSyscap, OS_SYSCAP_BYTES, (uint8_t *)pcidMain + 8, OS_SYSCAP_BYTES); // 8, bytes of pcid header
|
||||
if (EOK != nRet) {
|
||||
PRINT_ERR("memcpy_s failed.");
|
||||
ret = -1;
|
||||
goto FREE_VECTOR_OUT;
|
||||
}
|
||||
for (i = 0; i < BYTES_OF_OS_SYSCAP; i++) {
|
||||
for (i = 0; i < OS_SYSCAP_BYTES; i++) {
|
||||
for (j = 0; j < UINT8_BIT; j++) {
|
||||
if (osSyscap[i] & (0x01 << j)) {
|
||||
indexOfSyscap[countOfSyscap++] = i * UINT8_BIT + j;
|
||||
@@ -423,9 +423,9 @@ int32_t DecodePCID(char *inputFile, char *outDirPath)
|
||||
|
||||
char *ptrPrivateSyscap = (char *)(pcidMain + 1);
|
||||
uint16_t privateSyscapLen = contextBufLen - sizeof(PCIDMain) - 1;
|
||||
char priSyscapStr[PER_SYSCAP_LEN_MAX] = {0};
|
||||
char priSyscapStr[SINGLE_SYSCAP_LEN] = {0};
|
||||
char *tempPriSyscapStr = priSyscapStr;
|
||||
char fullPriSyscapStr[PER_SYSCAP_LEN_MAX] = {0};
|
||||
char fullPriSyscapStr[SINGLE_SYSCAP_LEN] = {0};
|
||||
if (privateSyscapLen < 0) {
|
||||
PRINT_ERR("parse private syscap failed.");
|
||||
ret = -1;
|
||||
@@ -437,7 +437,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath)
|
||||
while (*ptrPrivateSyscap != '\0') {
|
||||
if (*ptrPrivateSyscap == ',') {
|
||||
*tempPriSyscapStr = '\0';
|
||||
ret = sprintf_s(fullPriSyscapStr, PER_SYSCAP_LEN_MAX, "SystemCapability.%s", priSyscapStr);
|
||||
ret = sprintf_s(fullPriSyscapStr, SINGLE_SYSCAP_LEN, "SystemCapability.%s", priSyscapStr);
|
||||
if (ret == -1) {
|
||||
printf("sprintf_s failed\n");
|
||||
goto FREE_VECTOR_OUT;
|
||||
@@ -594,8 +594,8 @@ static int32_t AddOsSyscapToJsonObj(uint32_t *osSyscapArray, uint32_t osSyscapAr
|
||||
|
||||
uint32_t i, j;
|
||||
uint32_t osSyscapCount = 0;
|
||||
uint16_t index[BYTES_OF_OS_SYSCAP * UINT8_BIT] = {0};
|
||||
for (i = 0; i < BYTES_OF_OS_SYSCAP; i++) {
|
||||
uint16_t index[OS_SYSCAP_BYTES * UINT8_BIT] = {0};
|
||||
for (i = 0; i < OS_SYSCAP_BYTES; i++) {
|
||||
for (j = 0; j < UINT8_BIT; j++) {
|
||||
if (osSysCapArrayUint8[i] & (0x01 << j)) {
|
||||
index[osSyscapCount++] = i * UINT8_BIT + j;
|
||||
@@ -761,19 +761,19 @@ int32_t EncodePcidscToString(char *inputFile, char *outDirPath)
|
||||
if (priSyscapCount == 0) {
|
||||
goto OUT_PUT;
|
||||
}
|
||||
priSyscapFull = (char *)malloc(priSyscapCount * SINGLE_FEAT_LENGTH);
|
||||
priSyscapFull = (char *)malloc(priSyscapCount * SINGLE_SYSCAP_LEN);
|
||||
if (priSyscapFull == NULL) {
|
||||
PRINT_ERR("malloc failed\n");
|
||||
goto FREE_PRISYSCAP_FULL;
|
||||
}
|
||||
(void)memset_s(priSyscapFull, priSyscapCount * SINGLE_FEAT_LENGTH,
|
||||
0, priSyscapCount * SINGLE_FEAT_LENGTH);
|
||||
char tempSyscap[SINGLE_FEAT_LENGTH] = {0};
|
||||
(void)memset_s(priSyscapFull, priSyscapCount * SINGLE_SYSCAP_LEN,
|
||||
0, priSyscapCount * SINGLE_SYSCAP_LEN);
|
||||
char tempSyscap[SINGLE_SYSCAP_LEN] = {0};
|
||||
char *temp = tempSyscap;
|
||||
for (i = 0, j = 0; i < privateSyscapLen; i++) {
|
||||
if (*privateSyscap == ',') {
|
||||
*temp = '\0';
|
||||
ret = sprintf_s(priSyscapFull + j * SINGLE_FEAT_LENGTH, SINGLE_FEAT_LENGTH,
|
||||
ret = sprintf_s(priSyscapFull + j * SINGLE_SYSCAP_LEN, SINGLE_SYSCAP_LEN,
|
||||
"SystemCapability.%s", tempSyscap);
|
||||
if (ret == -1) {
|
||||
PRINT_ERR("sprintf_s failed\n");
|
||||
@@ -809,7 +809,7 @@ OUT_PUT:
|
||||
}
|
||||
}
|
||||
for (i = 0; i < priSyscapCount; i++) {
|
||||
ret = sprintf_s(output, outputLen, "%s,%s", output, priSyscapFull + i * SINGLE_FEAT_LENGTH);
|
||||
ret = sprintf_s(output, outputLen, "%s,%s", output, priSyscapFull + i * SINGLE_SYSCAP_LEN);
|
||||
if (ret == -1) {
|
||||
PRINT_ERR("sprintf_s failed\n");
|
||||
goto FREE_OUTPUT;
|
||||
|
||||
+7
-7
@@ -125,19 +125,19 @@ int main(int argc, char **argv)
|
||||
ret = RPCIDEncode(inputfile, outputpath); break;
|
||||
case 0x10A: // 0x10A, -Rdi inputfile
|
||||
ret = RPCIDDecode(inputfile, outputpath); break;
|
||||
case 0x10D:
|
||||
case 0x10D: // 0x10D, -Resi inputfile
|
||||
ret = EncodeRpcidscToString(inputfile, outputpath); break;
|
||||
case 0x115:
|
||||
case 0x115: // 0x115, -Pesi inputfile
|
||||
ret = EncodePcidscToString(inputfile, outputpath); break;
|
||||
case 0x60:
|
||||
case 0x60: // 0x60, -C PCID.txt RPCID.txt
|
||||
ret = ComparePcidWithRpcidString(pcidfile, rpcidfile); break;
|
||||
case 0x111:
|
||||
case 0x111: // 0x111, -Pei inputfile
|
||||
ret = CreatePCID(inputfile, outputpath); break;
|
||||
case 0x112:
|
||||
case 0x112: // 0x112, -Pdi inputfile
|
||||
ret = DecodePCID(inputfile, outputpath); break;
|
||||
case 0x116:
|
||||
case 0x116: // 0x116, -Pdsi inputfile
|
||||
ret = DecodeStringPCIDToJson(inputfile, outputpath, TYPE_FILE); break;
|
||||
case 0x80:
|
||||
case 0x80: // 0x80, -v
|
||||
(void)OutputVersion(argv[optind], optind); break;
|
||||
default:
|
||||
(void)OutputHelp();
|
||||
|
||||
@@ -44,7 +44,6 @@ typedef struct RequiredProductCompatibilityIDHead {
|
||||
uint16_t apiVersionType : 1;
|
||||
} RPCIDHead;
|
||||
|
||||
#define SINGLE_SYSCAP_LEN 256
|
||||
#define SYSCAP_PREFIX_LEN 17
|
||||
#define SINGLE_FEAT_LEN (SINGLE_SYSCAP_LEN - SYSCAP_PREFIX_LEN)
|
||||
#define UINT8_BIT 8
|
||||
|
||||
Reference in New Issue
Block a user