diff --git a/core/common/src/hdf_attribute.c b/core/common/src/hdf_attribute.c index ac3849bd63e98619f03d79e5d1fd5811b8ac49ed..b672e8b2397f2c27793aed20abec37177ae796da 100644 --- a/core/common/src/hdf_attribute.c +++ b/core/common/src/hdf_attribute.c @@ -244,26 +244,20 @@ static bool GetDeviceNodeInfo(const struct DeviceResourceNode *deviceNode, struc return CheckDeviceInfo(deviceNodeInfo); } -struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *hostName) +static struct HdfSList *HdfDeviceListAddOrder(const struct DeviceResourceNode *hostNode, uint16_t hostId) { uint16_t deviceIdx = 0; uint8_t deviceNnodeIdx = 0; struct HdfDeviceInfo *deviceNodeInfo = NULL; - const struct DeviceResourceNode *hostNode = GetHostNode(hostName); - struct HdfSList *deviceList = NULL; - const struct DeviceResourceNode *device = NULL; - if (hostNode == NULL) { - return NULL; - } - deviceList = (struct HdfSList *)OsalMemCalloc(sizeof(struct HdfSList)); + const struct DeviceResourceNode *device = hostNode->child; + struct HdfSList *deviceList = (struct HdfSList *)OsalMemCalloc(sizeof(struct HdfSList)); if (deviceList == NULL) { return NULL; } - device = hostNode->child; + while (device != NULL) { const struct DeviceResourceNode *deviceNode = device->child; while (deviceNode != NULL) { - deviceNnodeIdx = 0; deviceNodeInfo = HdfDeviceInfoNewInstance(); if (deviceNodeInfo == NULL) { HdfSListFlush(deviceList, HdfDeviceInfoDelete); @@ -278,6 +272,7 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h deviceNode = deviceNode->sibling; continue; } + if (!HdfSListAddOrder(deviceList, &deviceNodeInfo->node, HdfDeviceListCompare)) { HDF_LOGE("%s: failed to add device %s", __func__, deviceNodeInfo->svcName); HdfDeviceInfoFreeInstance(deviceNodeInfo); @@ -299,6 +294,16 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h return deviceList; } +struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *hostName) +{ + const struct DeviceResourceNode *hostNode = GetHostNode(hostName); + if (hostNode == NULL) { + return NULL; + } + + return HdfDeviceListAddOrder(hostNode, hostId); +} + bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const void *privateData) { struct HdfSListIterator itDeviceInfo; diff --git a/core/host/src/hdf_device_node.c b/core/host/src/hdf_device_node.c index 93c33556dd2ba01d1151bf738d41aee1a9d14e8b..7f33ac76ec6484c32a1a67f4db9e6ded32288e01 100644 --- a/core/host/src/hdf_device_node.c +++ b/core/host/src/hdf_device_node.c @@ -194,7 +194,7 @@ void HdfDeviceNodeDestruct(struct HdfDeviceNode *devNode) } HDF_LOGI("release devnode %s", devNode->servName); switch (devNode->devStatus) { - case DEVNODE_LAUNCHED: + case DEVNODE_LAUNCHED: // fall-through HdfDeviceReleaseNode(devNode); HdfDeviceTokenFreeInstance(devNode->token); devNode->token = NULL; diff --git a/core/host/src/hdf_driver_loader.c b/core/host/src/hdf_driver_loader.c index 14e4d2040263dd789c54ed7ff4f6657cfd7866ef..0247e0cdcd46f8c5207b2f11f2487ba23c1c73a1 100755 --- a/core/host/src/hdf_driver_loader.c +++ b/core/host/src/hdf_driver_loader.c @@ -7,13 +7,10 @@ */ #include "hdf_driver_loader.h" -#include "devsvc_manager_clnt.h" -#include "hcs_tree_if.h" #include "hdf_device_desc.h" #include "hdf_device_node.h" #include "hdf_log.h" #include "hdf_object_manager.h" -#include "hdf_attribute_manager.h" #define HDF_LOG_TAG driver_loader @@ -22,9 +19,8 @@ int32_t HdfDriverEntryConstruct() int i; struct HdfDriverEntry *driverEntry = NULL; size_t *addrBegin = NULL; - int32_t count = 0; + int32_t count = (int32_t)(((uint8_t *)(HDF_DRIVER_END()) - (uint8_t *)(HDF_DRIVER_BEGIN())) / sizeof(size_t)); - count = (int32_t)(((uint8_t *)(HDF_DRIVER_END()) - (uint8_t *)(HDF_DRIVER_BEGIN())) / sizeof(size_t)); if (count <= 0) { HDF_LOGE("%s: no hdf driver exist", __func__); return HDF_FAILURE; diff --git a/tools/hc-gen/src/bytecode_gen.cpp b/tools/hc-gen/src/bytecode_gen.cpp index 88e3bc2d499480763b2f02995d327015efdbe8be..50e82c02ce04a3c5529f606283551d1a10be58de 100644 --- a/tools/hc-gen/src/bytecode_gen.cpp +++ b/tools/hc-gen/src/bytecode_gen.cpp @@ -15,7 +15,7 @@ using namespace OHOS::Hardware; ByteCodeGen::ByteCodeGen(std::shared_ptr ast) : Generator(ast), - needAlign_(false) + needAlign_(false), dummyOutput_(false), writeSize_(0) { } @@ -253,7 +253,7 @@ bool ByteCodeGen::WriteBad() bool ByteCodeGen::HexdumpInitialize(FILE *&in, FILE *&out) { ofs_.close(); - std::string hexdumpOutName = Util::File::StripSuffix(outFileName_).append("_hex.c"); + std::string hexdumpOutName = Util::File::AbsPath(Util::File::StripSuffix(outFileName_).append("_hex.c")); in = fopen(outFileName_.data(), "rb"); if (in == nullptr) { diff --git a/tools/hc-gen/src/macro_gen.cpp b/tools/hc-gen/src/macro_gen.cpp index 07460d049f1c2c292e51812e1f2c7a2209d5cf1b..6b089c4f2008a79257ceaaa428eae166779cd1f3 100755 --- a/tools/hc-gen/src/macro_gen.cpp +++ b/tools/hc-gen/src/macro_gen.cpp @@ -224,56 +224,63 @@ bool MacroGen::NodeWalk() static uint32_t arraySize = 0; static uint32_t arrayType = 0; - Logger().Debug() << "name,type:[" << current->Name() << "," << type << "] depth:" << depth - << " arraySize:" << std::dec << arraySize << '\n'; - switch (type) { - case PARSEROP_UINT8: - case PARSEROP_UINT16: - case PARSEROP_UINT32: - case PARSEROP_UINT64: { - if (arraySize != 0) { - GenArray(arrayName, arraySize, arrayType, current); - } else { - ofs_ << " " << current->IntegerValue() << std::endl; - } - break; - } - case PARSEROP_STRING: - if (arraySize != 0) { - GenArray(arrayName, arraySize, arrayType, current); - } else { - ofs_ << " " << '"' << current->StringValue() << '"' << std::endl; - } - break; - case PARSEROP_CONFTERM: - ofs_ << "#define " << GenFullName(depth, current, "_") << "_exists 1" << std::endl; - ofs_ << "#define " << GenFullName(depth, current, "_"); - break; - case PARSEROP_CONFNODE: { - if (nodeName != current->Name()) { - ofs_ << std::endl; - } - nodeName = current->Name(); - nodeNameMap_[depth] = nodeName; - GenNodeForeach(depth, current); - break; - } - case PARSEROP_ARRAY: { - std::shared_ptr parent(current->Parent()); - arraySize = ConfigArray::CastFrom(current)->ArraySize(); - arrayType = ConfigArray::CastFrom(current)->ArrayType(); - ofs_ << "_array_size " << arraySize << std::endl; - arrayName = GenFullName(depth - 1, parent, "_"); - break; - } - case PARSEROP_NODEREF: { - ofs_ << " " << GenRefObjName(depth, current) << std::endl; - break; - } - default: - break; - } + Logger().Debug() << "name,type:[" << current->Name() << "," << type \ + << "] depth:" << depth \ + << " arraySize:" << std::dec << arraySize << '\n'; + SetTypeData(type, current, nodeName, arrayName, arraySize, arrayType, depth); return NOERR; }); } + +void MacroGen::SetTypeData(uint32_t type, const std::shared_ptr ¤t, std::string &nodeName, + std::string &arrayName, uint32_t &arraySize, uint32_t &arrayType, uint32_t depth) +{ + switch (type) { + case PARSEROP_UINT8: + case PARSEROP_UINT16: + case PARSEROP_UINT32: + case PARSEROP_UINT64: { + if (arraySize != 0) { + GenArray(arrayName, arraySize, arrayType, current); + } else { + ofs_ << " " << current->IntegerValue() << std::endl; + } + break; + } + case PARSEROP_STRING: + if (arraySize != 0) { + GenArray(arrayName, arraySize, arrayType, current); + } else { + ofs_ << " " << '"' << current->StringValue() << '"' << std::endl; + } + break; + case PARSEROP_CONFTERM: + ofs_ << "#define " << GenFullName(depth, current, "_") << "_exists 1" << std::endl; + ofs_ << "#define " << GenFullName(depth, current, "_"); + break; + case PARSEROP_CONFNODE: { + if (nodeName != current->Name()) { + ofs_ << std::endl; + } + nodeName = current->Name(); + nodeNameMap_[depth] = nodeName; + GenNodeForeach(depth, current); + break; + } + case PARSEROP_ARRAY: { + std::shared_ptr parent(current->Parent()); + arraySize = ConfigArray::CastFrom(current)->ArraySize(); + arrayType = ConfigArray::CastFrom(current)->ArrayType(); + ofs_ << "_array_size " << arraySize << std::endl; + arrayName = GenFullName(depth - 1, parent, "_"); + break; + } + case PARSEROP_NODEREF: { + ofs_ << " " << GenRefObjName(depth, current) << std::endl; + break; + } + default: + break; + } +} \ No newline at end of file diff --git a/tools/hc-gen/src/macro_gen.h b/tools/hc-gen/src/macro_gen.h index 250716b519dfc583c3d3365c3d292e6bc784a819..4aab864e5738d1fb8931dd0e5d4c99a5cc79f9ef 100755 --- a/tools/hc-gen/src/macro_gen.h +++ b/tools/hc-gen/src/macro_gen.h @@ -47,6 +47,8 @@ private: std::ofstream ofs_; std::string outFileName_; std::map nodeNameMap_; + void SetTypeData(uint32_t type, const std::shared_ptr ¤t, std::string &nodeName, + std::string &arrayName, uint32_t &arraySize, uint32_t &arrayType, uint32_t depth); }; } // Hardware } // OHOS diff --git a/tools/hc-gen/src/option.cpp b/tools/hc-gen/src/option.cpp index 88576278a73d08c8afd2eb0fc5cd6b74f949786a..afe0d75d0b14aa2eb21a08fc995357a87da31120 100644 --- a/tools/hc-gen/src/option.cpp +++ b/tools/hc-gen/src/option.cpp @@ -41,6 +41,12 @@ Option &Option::Parse(int argc, char **argv) break; } + if (optind <= 0) { + Logger().Error() << "invalid optind"; + SetOptionError(); + break; + } + if (optind >= argc) { Logger().Error() << "Miss input file name"; SetOptionError(); @@ -58,57 +64,62 @@ bool Option::ParseOptions(int argc, char **argv) int32_t op = 0; while (op != OPTION_END) { op = getopt(argc, argv, HCS_SUPPORT_ARGS); - switch (op) { - case 'o': - outputName_ = optarg; - break; - case 'a': - shouldAlign_ = true; - break; - case 'b': - shouldGenByteCodeConfig_ = true; - break; - case 't': - shouldGenTextConfig_ = true; - shouldGenByteCodeConfig_ = false; - shouldGenMacroConfig_ = false; - break; - case 'm': - shouldGenTextConfig_ = false; - shouldGenByteCodeConfig_ = false; - shouldGenMacroConfig_ = true; - break; - case 'p': - symbolNamePrefix_ = optarg; - break; - case 'i': - showGenHexDump_ = true; - break; - case 'V': - verboseLog_ = true; - break; - case 'd': - shouldDecompile_ = true; - break; - case 'v': - showVersion_ = true; - return false; - case 'h': /* fall-through */ - showUsage_ = true; - return false; - case '?': - showUsage_ = true; - optionError_ = true; - SetOptionError(); - return false; - default: - break; - } + SetOptionData(op); } return true; } +void Option::SetOptionData(char op) +{ + switch (op) { + case 'o': + outputName_ = optarg; + break; + case 'a': + shouldAlign_ = true; + break; + case 'b': + shouldGenByteCodeConfig_ = true; + break; + case 't': + shouldGenTextConfig_ = true; + shouldGenByteCodeConfig_ = false; + shouldGenMacroConfig_ = false; + break; + case 'm': + shouldGenTextConfig_ = false; + shouldGenByteCodeConfig_ = false; + shouldGenMacroConfig_ = true; + break; + case 'p': + symbolNamePrefix_ = optarg; + break; + case 'i': + showGenHexDump_ = true; + break; + case 'V': + verboseLog_ = true; + break; + case 'd': + shouldDecompile_ = true; + break; + case 'v': + showVersion_ = true; + break; + case 'h': /* fall-through */ + showUsage_ = true; + break; + case '?': + showUsage_ = true; + optionError_ = true; + SetOptionError(); + break; + default: + break; + } +} + void Option::ShowUsage() { Logger() << diff --git a/tools/hc-gen/src/option.h b/tools/hc-gen/src/option.h index 8a4522dc98c169a3fadbd2be29eaa14d00e8e2ea..1446abda446a309701d2e039bbe288f7345d071d 100644 --- a/tools/hc-gen/src/option.h +++ b/tools/hc-gen/src/option.h @@ -83,6 +83,7 @@ private: std::string sourceNameBase_; std::string outputName_; std::string sourceDir_; + void SetOptionData(char op); }; } // Hardware diff --git a/tools/hc-gen/test/update_case.py b/tools/hc-gen/test/update_case.py index bbfee99e1d3b415067bfe753e5d22070d446909a..6706b19764a4a86a82ec2c14ecc9f4bf623760d8 100755 --- a/tools/hc-gen/test/update_case.py +++ b/tools/hc-gen/test/update_case.py @@ -169,6 +169,7 @@ def build_text(hcgen_path, case_name): os.rename(target_file + '.h', target_file + '.h.gen') return True + def build_macro(hcgen_path, case_name): source_file = os.path.join(WORK_DIR, case_name, 'case.hcs') target_file = os.path.join(WORK_DIR, case_name, 'macro') diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py index a06ff1b468a3736f63ee11aa34fbea4e6867eabe..b8c6c9e0e84c6bf7c33c602c22f8e4793e8c1358 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py @@ -153,7 +153,9 @@ class HdfSetHandler(HdfCommandHandlerBase): self.check_arg_raise_if_not_exist("board_name") self.check_arg_raise_if_not_exist("module_name") root, vendor, model, _, board, _ = self.get_args() - return EnableOperation(root=root, vendor=vendor, board=board, model=model).operation_enable() + return EnableOperation( + root=root, vendor=vendor, board=board, + model=model).operation_enable() def _disable_operation(self): self.check_arg_raise_if_not_exist("root_dir") @@ -161,4 +163,6 @@ class HdfSetHandler(HdfCommandHandlerBase): self.check_arg_raise_if_not_exist("board_name") self.check_arg_raise_if_not_exist("module_name") root, vendor, model, _, board, _ = self.get_args() - return EnableOperation(root=root, vendor=vendor, board=board, model=model).operation_disable() \ No newline at end of file + return EnableOperation( + root=root, vendor=vendor, board=board, + model=model).operation_disable() \ No newline at end of file