VirtualBox

Changeset 100036 in vbox


Ignore:
Timestamp:
Jun 1, 2023 3:13:25 PM (18 months ago)
Author:
vboxsync
Message:

Runtime/RTFdt: Some additions and fixes, bugref:10401

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/fdt.h

    r100029 r100036  
    121121
    122122/**
     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 */
     129RTDECL(uint32_t) RTFdtPHandleAllocate(RTFDT hFdt);
     130
     131
     132/**
    123133 * Dumps the given flattened devicetree to the given VFS file.
    124134 *
  • trunk/include/iprt/mangling.h

    r100029 r100036  
    965965# define RTFdtNodePropertyAddString                     RT_MANGLER(RTFdtNodePropertyAddString)
    966966# define RTFdtNodePropertyAddU32                        RT_MANGLER(RTFdtNodePropertyAddU32)
     967# define RTFdtPHandleAllocate                           RT_MANGLER(RTFdtPHandleAllocate)
    967968# define RTFdtSetPhysBootCpuId                          RT_MANGLER(RTFdtSetPhysBootCpuId)
    968969# define RTFileAioCtxAssociateWithFile                  RT_MANGLER(RTFileAioCtxAssociateWithFile)
  • trunk/src/VBox/Runtime/common/misc/fdt.cpp

    r100032 r100036  
    4545#include <iprt/assert.h>
    4646#include <iprt/err.h>
     47#include <iprt/file.h>
    4748#include <iprt/log.h>
    4849#include <iprt/mem.h>
     
    9394    /** Current tree depth in the structure block. */
    9495    uint32_t                cTreeDepth;
     96    /** The next free phandle value. */
     97    uint32_t                idPHandle;
    9598} RTFDTINT;
    9699/** Pointer to the internal Flattened Devicetree instance. */
     
    266269    pThis->u32CpuIdPhysBoot = 0;
    267270    pThis->cTreeDepth       = 0;
     271    pThis->idPHandle        = UINT32_MAX;
    268272    RTMemFree(pThis);
    269273}
     
    415419                        pThis->cbStruct         = DtbHdr.cbDtStruct;
    416420                        pThis->u32CpuIdPhysBoot = DtbHdr.u32CpuIdPhysBoot;
     421                        pThis->idPHandle        = UINT32_MAX; /** @todo Would need to parse the whole tree to find the next free handle. */
    417422
    418423                        /* Load the memory reservation block. */
     
    11931198
    11941199    uint32_t cbNew = RT_ALIGN_32(pThis->cbStruct + cbSpaceRequired, _1K);
     1200    Assert(cbNew > pThis->cbStructMax);
    11951201    void *pvStructNew = RTMemReallocZ(pThis->pbStruct, pThis->cbStructMax, cbNew);
    11961202    if (!pvStructNew)
     
    13011307    if (pThis)
    13021308    {
     1309        pThis->idPHandle = 1; /* 0 is invalid */
     1310
    13031311        /* Add the root node. */
    13041312        rc = RTFdtNodeAdd(pThis, "");
     
    13321340RTDECL(int) RTFdtCreateFromFile(PRTFDT phFdt, const char *pszFilename, RTFDTTYPE enmInType, PRTERRINFO pErrInfo)
    13331341{
    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;
    13361351}
    13371352
     
    13601375        return rc;
    13611376
    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    {
    13641380        *pu32++ = DTB_FDT_TOKEN_END_NODE_BE;
     1381        pThis->cTreeDepth--;
     1382    }
    13651383
    13661384    *pu32 = DTB_FDT_TOKEN_END_BE;
    13671385    pThis->cbStruct += cbStructSpace;
    13681386    return VINF_SUCCESS;
     1387}
     1388
     1389
     1390RTDECL(uint32_t) RTFdtPHandleAllocate(RTFDT hFdt)
     1391{
     1392    PRTFDTINT pThis = hFdt;
     1393    AssertPtrReturn(pThis, UINT32_MAX);
     1394
     1395    return pThis->idPHandle++;
    13691396}
    13701397
     
    13881415RTDECL(int) RTFdtDumpToFile(RTFDT hFdt, RTFDTTYPE enmOutType, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo)
    13891416{
    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;
    13921426}
    13931427
     
    14931527    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    14941528
    1495     RT_H2BE_U32(u32);
     1529    u32 = RT_H2BE_U32(u32);
    14961530    return rtFdtStructAppendProperty(pThis, pszProperty, &u32, sizeof(u32));
    14971531}
     
    15291563        return rc;
    15301564
    1531     uint32_t cbPropAligned = RT_ALIGN_32(cCells * sizeof(uint32_t) + 3 * sizeof(uint32_t), sizeof(uint32_t));
    1532 
    1533     rc = rtFdtStructEnsureSpace(pThis, cbPropAligned);
     1565    uint32_t cbProp = cCells * sizeof(uint32_t) + 3 * sizeof(uint32_t);
     1566
     1567    rc = rtFdtStructEnsureSpace(pThis, cbProp);
    15341568    if (RT_FAILURE(rc))
    15351569        return rc;
     
    15401574    *pu32++ = RT_H2BE_U32(offStr);
    15411575    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.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette