Beispiel #1
0
int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
{
	struct fdt_property *prop;
	int len;

	prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
	if (! prop)
		return len;

	_fdt_nop_region(prop, len + sizeof(*prop));

	return 0;
}
Beispiel #2
0
STATIC
EFI_STATUS
DelPhyhandleUpdateMacAddress(IN VOID* Fdt)
{
    UINT8               port;
    INTN                ethernetnode;
    INTN			    node;
    INTN                Error;
    struct              fdt_property *m_prop;
    int                 m_oldlen;
    EFI_STATUS          Status = EFI_SUCCESS;
    
    node = fdt_subnode_offset(Fdt, 0, "soc");
    if (node < 0) 
    {
        DEBUG ((EFI_D_ERROR, "can not find soc root node\n"));
        return EFI_INVALID_PARAMETER;
    }
    else
    {
        for( port=0; port<8; port++ )
        {
            (VOID) GetMacAddress(port);
            ethernetnode=fdt_subnode_offset(Fdt, node,EthName[port]);
            if (ethernetnode < 0) 
            {
                DEBUG ((EFI_D_ERROR, "can not find ethernet@ %d node\n",port));
            }
            m_prop = fdt_get_property_w(Fdt, ethernetnode, "local-mac-address", &m_oldlen);
            if(m_prop)
            {
                Error = fdt_delprop(Fdt, ethernetnode, "local-mac-address");
                if (Error) 
                {
                    DEBUG ((EFI_D_ERROR, "ERROR:fdt_delprop() Local-mac-address: %a\n", fdt_strerror (Error)));
                    Status = EFI_INVALID_PARAMETER;
                } 
                Error = fdt_setprop(Fdt, ethernetnode, "local-mac-address",gMacAddress,sizeof(MAC_ADDRESS));
                if (Error) 
                {
                    DEBUG ((EFI_D_ERROR, "ERROR:fdt_setprop():local-mac-address %a\n", fdt_strerror (Error)));
                    Status = EFI_INVALID_PARAMETER;
                } 
            }
        }
    }
    return Status;
}
Beispiel #3
0
static int fdtloader_appendprop_string(void *fdt, int nodeoffset, const char *name, const char *str)
{
    int err, oldlen;
    struct fdt_property *prop;

    // get property
    prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);

    // append string
    err = fdt_appendprop_string(fdt, nodeoffset, name, str);
    if (err)
        return err;

    if (prop) {
        // Add space to separate the appended strings
        prop->data[oldlen-1] = 0x20;
    }

    return 0;
}
Beispiel #4
0
EFI_STATUS UpdateMemoryNode(VOID* Fdt)
{
    INTN                Error = 0;
    EFI_STATUS          Status = EFI_SUCCESS;
    UINT32              Index = 0;
    UINT32              MemIndex;
    INTN			    node;
    struct              fdt_property *m_prop;
    int                 m_oldlen;
    EFI_MEMORY_DESCRIPTOR *MemoryMap;
    EFI_MEMORY_DESCRIPTOR *MemoryMapPtr;
    EFI_MEMORY_DESCRIPTOR *MemoryMapPtrCurrent;
    UINTN                 MemoryMapSize;
    UINTN                 Pages0 = 0;
    UINTN                 Pages1 = 0;
    UINTN                 MapKey;
    UINTN                 DescriptorSize;
    UINT32                DescriptorVersion;
    PHY_MEM_REGION        *mRegion;
    UINTN                 MemoryMapLastEndAddress ;
    UINTN                 MemoryMapcontinuousStartAddress ;
    UINTN                 MemoryMapCurrentStartAddress;
    BOOLEAN               FindMemoryRegionFlag = FALSE;
    node = fdt_subnode_offset(Fdt, 0, "memory");
    if (node < 0) 
    {
        // Create the memory node
        node = fdt_add_subnode(Fdt, 0, "memory");
        if(node < 0)
        {
          DEBUG((EFI_D_INFO, "[%a]:[%dL] fdt add subnode error\n", __FUNCTION__, __LINE__));
        }
    }
    //find the memory node property  
    m_prop = fdt_get_property_w(Fdt, node, "memory", &m_oldlen);
    if(m_prop)
        Error=fdt_delprop(Fdt, node, "reg");
    if (Error) 
    {
        DEBUG ((EFI_D_ERROR, "ERROR:fdt_delprop(): %a\n", fdt_strerror (Error)));
        Status = EFI_INVALID_PARAMETER;
        return Status;
    } 

    MemoryMap = NULL;
    MemoryMapSize = 0;
    MemIndex = 0;
 
    Status = gBS->GetMemoryMap (&MemoryMapSize, MemoryMap, &MapKey, &DescriptorSize, &DescriptorVersion);
    if (Status == EFI_BUFFER_TOO_SMALL)
    {
        // The UEFI specification advises to allocate more memory for the MemoryMap buffer between successive
        // calls to GetMemoryMap(), since allocation of the new buffer may potentially increase memory map size.
        //DEBUG ((EFI_D_ERROR, "MemoryMapsize: 0x%lx\n",MemoryMapSize));
        Pages0 = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1;
        MemoryMap = AllocatePages (Pages0);
        if (MemoryMap == NULL)
        {
            Status = EFI_OUT_OF_RESOURCES;
            return Status;
        }
        Status = gBS->GetMemoryMap (&MemoryMapSize, MemoryMap, &MapKey, &DescriptorSize, &DescriptorVersion);
    }

    if(MemoryMap == NULL)
    {
        Status = EFI_OUT_OF_RESOURCES;
        //goto EXIT;
        return Status;
    }

    mRegion = NULL;
    Pages1 = EFI_SIZE_TO_PAGES (sizeof(PHY_MEM_REGION) *( MemoryMapSize / DescriptorSize));
    mRegion = (PHY_MEM_REGION*)AllocatePages(Pages1);
    if (mRegion == NULL)
    {
      Status = EFI_OUT_OF_RESOURCES;
      return Status;
    }
	
    if (!EFI_ERROR(Status))
    {
        MemoryMapPtr = MemoryMap;
        MemoryMapPtrCurrent = MemoryMapPtr;
        MemoryMapLastEndAddress = 0;
        MemoryMapcontinuousStartAddress = 0;
        MemoryMapCurrentStartAddress = 0;
        for ( Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++)
        {
            MemoryMapPtrCurrent = (EFI_MEMORY_DESCRIPTOR*)((UINTN)MemoryMapPtr + Index*DescriptorSize);
            MemoryMapCurrentStartAddress = (UINTN)MemoryMapPtrCurrent->PhysicalStart;
       
            if (!IsMemMapRegion ((EFI_MEMORY_TYPE)MemoryMapPtrCurrent->Type))
            {
                continue;
            }
            else 
            {
                FindMemoryRegionFlag = TRUE;
                if(MemoryMapCurrentStartAddress != MemoryMapLastEndAddress)
                {
                    mRegion[MemIndex].BaseHigh= cpu_to_fdt32(MemoryMapcontinuousStartAddress>>32);
	                mRegion[MemIndex].BaseLow=cpu_to_fdt32(MemoryMapcontinuousStartAddress);
                    mRegion[MemIndex].LengthHigh= cpu_to_fdt32((MemoryMapLastEndAddress-MemoryMapcontinuousStartAddress)>>32);
	                mRegion[MemIndex].LengthLow=cpu_to_fdt32(MemoryMapLastEndAddress-MemoryMapcontinuousStartAddress);
                    MemIndex+=1;
                    MemoryMapcontinuousStartAddress=MemoryMapCurrentStartAddress;
                }
            }
            MemoryMapLastEndAddress = (UINTN)(MemoryMapPtrCurrent->PhysicalStart + MemoryMapPtrCurrent->NumberOfPages * EFI_PAGE_SIZE);
        }