Changeset 100036 in vbox
- Timestamp:
- Jun 1, 2023 3:13:25 PM (18 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/fdt.h
r100029 r100036 121 121 122 122 /** 123 * Allocates a new phandle serving as a unique identifer within the given FDT. 124 * 125 * @returns The phandle value 126 * @retval UINT32_MAX in case the given FDT handle is invalid or the FDT is out of free phandle values. 127 * @param hFdt The flattened devicetree handle to destroy. 128 */ 129 RTDECL(uint32_t) RTFdtPHandleAllocate(RTFDT hFdt); 130 131 132 /** 123 133 * Dumps the given flattened devicetree to the given VFS file. 124 134 * -
trunk/include/iprt/mangling.h
r100029 r100036 965 965 # define RTFdtNodePropertyAddString RT_MANGLER(RTFdtNodePropertyAddString) 966 966 # define RTFdtNodePropertyAddU32 RT_MANGLER(RTFdtNodePropertyAddU32) 967 # define RTFdtPHandleAllocate RT_MANGLER(RTFdtPHandleAllocate) 967 968 # define RTFdtSetPhysBootCpuId RT_MANGLER(RTFdtSetPhysBootCpuId) 968 969 # define RTFileAioCtxAssociateWithFile RT_MANGLER(RTFileAioCtxAssociateWithFile) -
trunk/src/VBox/Runtime/common/misc/fdt.cpp
r100032 r100036 45 45 #include <iprt/assert.h> 46 46 #include <iprt/err.h> 47 #include <iprt/file.h> 47 48 #include <iprt/log.h> 48 49 #include <iprt/mem.h> … … 93 94 /** Current tree depth in the structure block. */ 94 95 uint32_t cTreeDepth; 96 /** The next free phandle value. */ 97 uint32_t idPHandle; 95 98 } RTFDTINT; 96 99 /** Pointer to the internal Flattened Devicetree instance. */ … … 266 269 pThis->u32CpuIdPhysBoot = 0; 267 270 pThis->cTreeDepth = 0; 271 pThis->idPHandle = UINT32_MAX; 268 272 RTMemFree(pThis); 269 273 } … … 415 419 pThis->cbStruct = DtbHdr.cbDtStruct; 416 420 pThis->u32CpuIdPhysBoot = DtbHdr.u32CpuIdPhysBoot; 421 pThis->idPHandle = UINT32_MAX; /** @todo Would need to parse the whole tree to find the next free handle. */ 417 422 418 423 /* Load the memory reservation block. */ … … 1193 1198 1194 1199 uint32_t cbNew = RT_ALIGN_32(pThis->cbStruct + cbSpaceRequired, _1K); 1200 Assert(cbNew > pThis->cbStructMax); 1195 1201 void *pvStructNew = RTMemReallocZ(pThis->pbStruct, pThis->cbStructMax, cbNew); 1196 1202 if (!pvStructNew) … … 1301 1307 if (pThis) 1302 1308 { 1309 pThis->idPHandle = 1; /* 0 is invalid */ 1310 1303 1311 /* Add the root node. */ 1304 1312 rc = RTFdtNodeAdd(pThis, ""); … … 1332 1340 RTDECL(int) RTFdtCreateFromFile(PRTFDT phFdt, const char *pszFilename, RTFDTTYPE enmInType, PRTERRINFO pErrInfo) 1333 1341 { 1334 RT_NOREF(phFdt, pszFilename, enmInType, pErrInfo); 1335 return VERR_NOT_IMPLEMENTED; 1342 RTVFSIOSTREAM hVfsIos = NIL_RTVFSIOSTREAM; 1343 int rc = RTVfsChainOpenIoStream(pszFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE, 1344 &hVfsIos, NULL /*poffError*/, pErrInfo); 1345 if (RT_FAILURE(rc)) 1346 return rc; 1347 1348 rc = RTFdtCreateFromVfsIoStrm(phFdt, hVfsIos, enmInType, pErrInfo); 1349 RTVfsIoStrmRelease(hVfsIos); 1350 return rc; 1336 1351 } 1337 1352 … … 1360 1375 return rc; 1361 1376 1362 uint32_t *pu32 = (uint32_t *)pThis->pbStruct; 1363 while (pThis->cTreeDepth--) 1377 uint32_t *pu32 = (uint32_t *)(pThis->pbStruct + pThis->cbStruct); 1378 while (pThis->cTreeDepth) 1379 { 1364 1380 *pu32++ = DTB_FDT_TOKEN_END_NODE_BE; 1381 pThis->cTreeDepth--; 1382 } 1365 1383 1366 1384 *pu32 = DTB_FDT_TOKEN_END_BE; 1367 1385 pThis->cbStruct += cbStructSpace; 1368 1386 return VINF_SUCCESS; 1387 } 1388 1389 1390 RTDECL(uint32_t) RTFdtPHandleAllocate(RTFDT hFdt) 1391 { 1392 PRTFDTINT pThis = hFdt; 1393 AssertPtrReturn(pThis, UINT32_MAX); 1394 1395 return pThis->idPHandle++; 1369 1396 } 1370 1397 … … 1388 1415 RTDECL(int) RTFdtDumpToFile(RTFDT hFdt, RTFDTTYPE enmOutType, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo) 1389 1416 { 1390 RT_NOREF(hFdt, enmOutType, fFlags, pszFilename, pErrInfo); 1391 return VERR_NOT_IMPLEMENTED; 1417 RTVFSIOSTREAM hVfsIos = NIL_RTVFSIOSTREAM; 1418 int rc = RTVfsChainOpenIoStream(pszFilename, RTFILE_O_WRITE | RTFILE_O_CREATE | RTFILE_O_DENY_NONE, 1419 &hVfsIos, NULL /*poffError*/, pErrInfo); 1420 if (RT_FAILURE(rc)) 1421 return rc; 1422 1423 rc = RTFdtDumpToVfsIoStrm(hFdt, enmOutType, fFlags, hVfsIos, pErrInfo); 1424 RTVfsIoStrmRelease(hVfsIos); 1425 return rc; 1392 1426 } 1393 1427 … … 1493 1527 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1494 1528 1495 RT_H2BE_U32(u32);1529 u32 = RT_H2BE_U32(u32); 1496 1530 return rtFdtStructAppendProperty(pThis, pszProperty, &u32, sizeof(u32)); 1497 1531 } … … 1529 1563 return rc; 1530 1564 1531 uint32_t cbProp Aligned = RT_ALIGN_32(cCells * sizeof(uint32_t) + 3 * sizeof(uint32_t), sizeof(uint32_t));1532 1533 rc = rtFdtStructEnsureSpace(pThis, cbProp Aligned);1565 uint32_t cbProp = cCells * sizeof(uint32_t) + 3 * sizeof(uint32_t); 1566 1567 rc = rtFdtStructEnsureSpace(pThis, cbProp); 1534 1568 if (RT_FAILURE(rc)) 1535 1569 return rc; … … 1540 1574 *pu32++ = RT_H2BE_U32(offStr); 1541 1575 for (uint32_t i = 0; i < cCells; i++) 1542 *pu32++ = va_arg(va, uint32_t); 1543 1544 pThis->cbStruct += cbPropAligned; 1545 return VINF_SUCCESS; 1546 } 1576 { 1577 uint32_t u32 = va_arg(va, uint32_t); 1578 *pu32++ = RT_H2BE_U32(u32); 1579 } 1580 1581 pThis->cbStruct += cbProp; 1582 return VINF_SUCCESS; 1583 }
Note:
See TracChangeset
for help on using the changeset viewer.