VirtualBox

Changeset 100023 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
May 31, 2023 8:50:11 AM (20 months ago)
Author:
vboxsync
Message:

Runtime/RTFdt: Implement parsing Devicetree blobs (DTB) and output a DTS, bugref:10401 [build fixes]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/fdt.cpp

    r100022 r100023  
    442442    pDump->pbStructs += sizeof(uint32_t);
    443443    pDump->cbLeft    -= sizeof(uint32_t);
    444     return u32Token;
    445 }
    446 
    447 
     444    return RT_H2BE_U32(u32Token);
     445}
     446
     447
     448#ifdef LOG_ENABLED
    448449/**
    449450 * Gets the offset inside the structs block given from the current pointer.
     
    453454 * @param   pDump           Pointer to the dump state.
    454455 */
    455 DECLINLINE(uint32_t) rtFdtStructsGetOffset(PRTFDTINT pThis, PCRTFDTDTBDUMP pDump)
     456DECLINLINE(size_t) rtFdtStructsGetOffset(PRTFDTINT pThis, PCRTFDTDTBDUMP pDump)
    456457{
    457458    return pThis->DtbHdr.cbDtStruct - pDump->cbLeft - sizeof(uint32_t);
    458459}
     460#endif
    459461
    460462
     
    619621
    620622/**
    621  * Dumps a <u32> cell property.
     623 * Dumps a u32 cell property.
    622624 *
    623625 * @returns IPRT status code.
     
    789791 *
    790792 * @returns IPRT status code.
    791  * @param   pThis           Pointer to the FDT instance.
    792793 * @param   hVfsIos         The VFS I/O stream handle to dump the DTS to.
    793794 * @param   pDump           The dump state.
     
    850851    /* Skip any NOP tokens. */
    851852    uint32_t u32Token = rtFdtStructsGetToken(&Dump);
    852     while (u32Token == DTB_FDT_TOKEN_NOP_BE)
     853    while (u32Token == DTB_FDT_TOKEN_NOP)
    853854        u32Token = rtFdtStructsGetToken(&Dump);
    854855
    855856    /* The root node starts with a BEGIN_NODE token. */
    856     if (u32Token != DTB_FDT_TOKEN_BEGIN_NODE_BE)
     857    if (u32Token != DTB_FDT_TOKEN_BEGIN_NODE)
    857858        return RTErrInfoSetF(pErrInfo, VERR_FDT_DTB_STRUCTS_BLOCK_TOKEN_INVALID, "The structs block doesn't start with the BEGIN_NODE token for the root node: %#RX32",
    858859                             RT_BE2H_U32(u32Token));
     
    874875    uint32_t uNdLvl = 1;
    875876    u32Token = rtFdtStructsGetToken(&Dump);
    876     while (u32Token != DTB_FDT_TOKEN_END_BE)
     877    while (u32Token != DTB_FDT_TOKEN_END)
    877878    {
    878         Log4(("rtFdtDumpAsDtsRoot: Token %#RX32 at offset %#RX32\n", RT_BE2H_U32(u32Token), rtFdtStructsGetOffset(pThis, &Dump)));
     879        Log4(("rtFdtDumpAsDtsRoot: Token %#RX32 at offset %#zx\n", RT_BE2H_U32(u32Token), rtFdtStructsGetOffset(pThis, &Dump)));
    879880
    880881        switch (u32Token)
    881882        {
    882             case DTB_FDT_TOKEN_BEGIN_NODE_BE:
    883                 Log3(("rtFdtDumpAsDtsRoot: BEGIN_NODE token at offset %#RX32\n", rtFdtStructsGetOffset(pThis, &Dump)));
     883            case DTB_FDT_TOKEN_BEGIN_NODE:
     884                Log3(("rtFdtDumpAsDtsRoot: BEGIN_NODE token at offset %#zx\n", rtFdtStructsGetOffset(pThis, &Dump)));
    884885                rc = rtFdtStructsDumpNodeAsDts(hVfsIos, &Dump, uNdLvl, pErrInfo);
    885886                if (RT_FAILURE(rc))
     
    888889                uNdLvl++;
    889890                break;
    890             case DTB_FDT_TOKEN_PROPERTY_BE:
    891                 Log3(("rtFdtDumpAsDtsRoot: PROP token at offset %#RX32\n", rtFdtStructsGetOffset(pThis, &Dump)));
     891            case DTB_FDT_TOKEN_PROPERTY:
     892                Log3(("rtFdtDumpAsDtsRoot: PROP token at offset %#zx\n", rtFdtStructsGetOffset(pThis, &Dump)));
    892893                rc = rtFdtStructsDumpPropertyAsDts(pThis, hVfsIos, &Dump, uNdLvl, pErrInfo);
    893894                if (RT_FAILURE(rc))
    894895                    return rc;
    895896                break;
    896             case DTB_FDT_TOKEN_NOP_BE:
    897                 Log3(("rtFdtDumpAsDtsRoot: NOP token at offset %#RX32\n", rtFdtStructsGetOffset(pThis, &Dump)));
     897            case DTB_FDT_TOKEN_NOP:
     898                Log3(("rtFdtDumpAsDtsRoot: NOP token at offset %#zx\n", rtFdtStructsGetOffset(pThis, &Dump)));
    898899                break;
    899             case DTB_FDT_TOKEN_END_NODE_BE:
    900                 Log3(("rtFdtDumpAsDtsRoot: END_NODE token at offset %#RX32\n", rtFdtStructsGetOffset(pThis, &Dump)));
     900            case DTB_FDT_TOKEN_END_NODE:
     901                Log3(("rtFdtDumpAsDtsRoot: END_NODE token at offset %#zx\n", rtFdtStructsGetOffset(pThis, &Dump)));
    901902                if (!uNdLvl)
    902903                    return RTErrInfoSetF(pErrInfo, VERR_FDT_DTB_STRUCTS_BLOCK_PREMATURE_END,
     
    916917
    917918        u32Token = rtFdtStructsGetToken(&Dump);
    918         if (u32Token == DTB_FDT_TOKEN_END_BE)
    919             Log3(("rtFdtDumpAsDtsRoot: END token at offset %#RX32\n", rtFdtStructsGetOffset(pThis, &Dump)));
     919        if (u32Token == DTB_FDT_TOKEN_END)
     920            Log3(("rtFdtDumpAsDtsRoot: END token at offset %#zx\n", rtFdtStructsGetOffset(pThis, &Dump)));
    920921    }
    921922
    922923    /* Need to end on an END token. */
    923     if (u32Token != DTB_FDT_TOKEN_END_BE)
     924    if (u32Token != DTB_FDT_TOKEN_END)
    924925        return RTErrInfoSetF(pErrInfo, VERR_FDT_DTB_STRUCTS_BLOCK_TOKEN_INVALID, "The structs block doesn't end with an END token (got %#RX32, expected %#RX32)",
    925926                             RT_BE2H_U32(u32Token), DTB_FDT_TOKEN_END);
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