6#include "dawn/common/descriptor.hxx"
10#include "dawn/debug.hxx"
11#include "dawn/porting/crc.hxx"
15#if defined(CONFIG_DAWN_DESC_SLOTS) && CONFIG_DAWN_DESC_SLOTS > 1
16# define DAWN_DESC_CRC_REQUIRED 1
17#elif defined(CONFIG_DAWN_DESC_VALID_CRC32)
18# define DAWN_DESC_CRC_REQUIRED 1
20# define DAWN_DESC_CRC_REQUIRED 0
23static int binValidateDtypes(
const uint32_t *bin,
size_t len)
29 if (bin ==
nullptr || len < 8 || len %
sizeof(uint32_t))
34 words = len /
sizeof(uint32_t);
36 count = bin[1] & 0xffff;
38 for (
size_t obj = 0; obj < count; obj++)
46 DAWNERR(
"(i + 2) > words\n");
60 for (
size_t cfg = 0; cfg < objsize; cfg++)
67 DAWNERR(
"i >= words\n");
80 if ((i + cfgsize) > words)
82 DAWNERR(
"(i + cfgsize) > words\n");
92 DAWNERR(
"i != words\n");
110 DAWNINFO(
"BINDUMP ptr:%p len:%zu:\n\n", bin, len);
113 DAWNINFO(
"\tMAGIC: 0x%" PRIx32
"\n", tmp);
116 DAWNINFO(
"\tObjects: 0x%" PRIx32
"\n", tmp);
129 DAWNINFO(
"\tObjectID: 0x%" PRIx32
"\n", tmp);
131 DAWNINFO(
"\t size: 0x%zx\n", objsize);
135 for (
size_t j = 0; j < objsize; j++)
138 DAWNINFO(
"\t objcfg: 0x%" PRIx32
"\n", objcfg.
v);
140 for (
size_t k = 0; k < objcfg.
s.
size; k++)
144 DAWNINFO(
"\t data: 0x%" PRIx32
"\n", tmp);
151 DAWNINFO(
"\tLAST: 0x%" PRIx32
"\n", tmp);
154 DAWNINFO(
"\tCHECK: 0x%" PRIx32
"\n", tmp);
179#if DAWN_DESC_CRC_REQUIRED
191 dret = binValidateDtypes(bin, len);
218 bin[(len / 4) - 1] = crc32(
reinterpret_cast<const uint8_t *
>(bin), len - 4);
228void CDescriptor::parseMeta()
230 size_t words = objectWords();
233 if (!bindesc || bindesc->hdr.size == 0)
248 if (!objectWordAt(1, &word))
253 size_t numItems = word;
256 for (
size_t i = 0; i < numItems; i++)
265 if (!objectWordAt(off, &cfgid))
270 uint32_t size = (cfgid >> 5) & 0x3FF;
271 uint32_t
id = cfgid & 0x1F;
274 if (off + size > words)
281 case DESC_CFG_NO_IDLE_QUIT:
284 if (!objectWordAt(off, &word))
288 noIdleQuit = (word != 0);
292 case DESC_CFG_VERSION:
293 case DESC_CFG_STRING:
307 DAWNINFO(
"delete desc for 0x%" PRIx32
"\n", obj->getObjectIdV());
369size_t CDescriptor::objectWords()
const
371 if (bindesc ==
nullptr || bindescLen <
sizeof(SDescriptorBinHdr) +
sizeof(SDescriptorBinFtr))
376 return (bindescLen -
sizeof(SDescriptorBinHdr) -
sizeof(SDescriptorBinFtr)) /
sizeof(uint32_t);
379bool CDescriptor::objectWordAt(
size_t offset, uint32_t *value)
const
381 if (value ==
nullptr || bindesc ==
nullptr || offset >= objectWords())
386 const uint8_t *objects =
reinterpret_cast<const uint8_t *
>(bindesc) +
sizeof(SDescriptorBinHdr);
387 std::memcpy(value, objects + offset *
sizeof(uint32_t),
sizeof(*value));
393 if (bindesc ==
nullptr || offset + 2 > objectWords())
399 reinterpret_cast<uint32_t *
>(&bindesc->objects) + offset);
404 if (bindesc ==
nullptr || offset >= objectWords())
410 reinterpret_cast<uint32_t *
>(&bindesc->objects) + offset);
413void CDescriptor::alloc_objects(
CHandler &h,
const allocobj_func_t &func)
418 DAWNASSERT(cfg !=
nullptr,
"invalid input");
422 for (
size_t i = 0; i < cfg->hdr.size; i++)
447 DAWNERR(
"duplicate 0x%" PRIx32
" 0x%" PRIx32
" \n", tmp1, tmp2);
454 vobjcfg.push_back(desc);
467 for (
size_t j = 0; j < ocfg->
size; j++)
470 if (!objectWordAt(offset, &objcfg))
Descriptor wrapper for individual object configuration.
void reset()
Clear currently loaded descriptor state.
static uint32_t DAWN_DESCRIPTOR_FOOT
Footer magic number (0x02030a0d).
~CDescriptor()
Destructor - release loaded descriptor resources.
SObjectCfg::UObjectCfgId * objectCfgIdAtOffset(size_t offset)
Get configuration ID at offset.
static uint32_t DAWN_DESCRIPTOR_HDR
Header magic number (0x0d0a0302).
SObjectCfg::SObjectCfgData * objectCfgAtOffset(size_t offset)
Get object configuration at offset.
static void binDump(const uint32_t *bin, size_t len)
Print descriptor contents to console (debug).
static int binCheckFill(uint32_t *bin, size_t len)
Calculate and store descriptor CRC32 checksum.
int loadBin(uint32_t *bin, size_t len, bool force_valid=false, bool dump=false)
Load binary descriptor from memory.
size_t getBinLen()
Get loaded descriptor size in bytes.
static int binValid(const uint32_t *bin, size_t len)
Validate binary descriptor integrity.
static bool binCheckValid(const uint32_t *bin, size_t len)
Validate descriptor CRC32 checksum.
SDescriptorBin * getBin()
Get loaded descriptor binary structure.
Base implementation of IHandler interface.
static int validateDesc(const uint32_t *desc, size_t len)
Validate entire descriptor.
virtual bool isObjectValid(SObjectId::UObjectId &obj) const =0
Validate if object ID is valid for this handler.
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
static uint16_t objectCfgGetSize(const ObjectCfgId objcfg)
Extract configuration data size from ConfigID.
static uint8_t objectCfgGetDtype(const ObjectCfgId objcfg)
Extract data type from ConfigID.
Out-of-tree user-extension hooks for Dawn.
Complete binary descriptor container.
Object configuration data container.
SObjectId::UObjectId objid
Object identifier (type, class, dtype, instance).
uint32_t size
Number of configuration items for this object (0-32).
@ OBJTYPE_ANY
Wildcard/metadata object type.
static const char * dtypeToString(uint8_t dtype)
Convert data type to human-readable string.
static uint8_t objectIdGetType(const ObjectId objid)
Extract object type from ObjectID.
static uint8_t objectIdGetDtype(const ObjectId objid)
Extract data type field from ObjectID.
static bool isDtypeSupported(uint8_t dtype)
Check if a data type is enabled in build configuration.
uint32_t ObjectId
ObjectID type - single 32-bit value.
32-bit encoded configuration identifier (union with bit field).
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.
32-bit encoded object identifier (union with bit field).
ObjectId v
Raw 32-bit ObjectID value (for comparison, hashing, storage).