1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #include "hcs_blob_if.h" 10 #include "hcs_parser.h" 11 #include "hcs_tree_if.h" 12 #include "hdf_base.h" 13 #include "hdf_log.h" 14 15 #define HDF_LOG_TAG hcs_parser 16 17 static struct DeviceResourceNode *g_hcsTreeRoot = NULL; 18 19 void __attribute__((weak)) HdfGetBuildInConfigData(const unsigned char **data, unsigned int *size); 20 BuildHcsTree(void)21static bool BuildHcsTree(void) 22 { 23 uint32_t length; 24 const unsigned char *hcsBlob = NULL; 25 if (HdfGetBuildInConfigData == NULL) { 26 HDF_LOGE("no build-in hdf config"); 27 return false; 28 } 29 HdfGetBuildInConfigData(&hcsBlob, &length); 30 if (!HcsCheckBlobFormat((const char *)hcsBlob, length)) { 31 return false; 32 } 33 if (!HcsDecompile((const char *)hcsBlob, HBC_HEADER_LENGTH, &g_hcsTreeRoot)) { 34 return false; 35 } 36 return true; 37 } 38 HcsGetRootNode(void)39const struct DeviceResourceNode *HcsGetRootNode(void) 40 { 41 if (g_hcsTreeRoot == NULL && !BuildHcsTree()) { 42 HDF_LOGE("failed to rebuild config tree"); 43 return NULL; 44 } 45 46 if (g_hcsTreeRoot == NULL) { 47 HDF_LOGE("failed to get build-in hcs root node"); 48 } 49 return g_hcsTreeRoot; 50 }