u-boot fdt功能和函数

1、接口功能

以下只简单说明几个接口的功能,没有深究到实现原理。先说明几个,后续继续补充。 
另外,用节点在dtb中的偏移地址来表示一个节点。也就是节点变量node中,存放的是节点的偏移地址

      • lib/fdtdec.c中

        • fdt_path_offset
          int fdt_path_offset(const void *fdt, const char *path) 
          eg:node = fdt_path_offset(gd->fdt_blob, “/aliases”); 
          功能:获得dtb下某个节点的路径path的偏移。这个偏移就代表了这个节点。

        • fdt_getprop
          const void *fdt_getprop(const void *fdt, int nodeoffset, const char *name, int *lenp) 
          eg: mac = fdt_getprop(gd->fdt_blob, node, “mac-address”, &len); 
          功能:获得节点node的某个字符串属性值。

        • fdtdec_get_int_array、fdtdec_get_byte_array
          int fdtdec_get_int_array(const void *blob, int node, const char *prop_name, u32 *array, int count) 
          eg: ret = fdtdec_get_int_array(blob, node, “interrupts”, cell, ARRAY_SIZE(cell)); 
          功能:获得节点node的某个整形数组属性值。

        • fdtdec_get_addr
          fdt_addr_t fdtdec_get_addr(const void *blob, int node, const char *prop_name) 
          eg:fdtdec_get_addr(blob, node, “reg”); 
          功能:获得节点node的地址属性值。

        • fdtdec_get_config_int、fdtdec_get_config_bool、fdtdec_get_config_string
          功能:获得config节点下的整形属性、bool属性、字符串等等。

        • fdtdec_get_chosen_node
          int fdtdec_get_chosen_node(const void *blob, const char *name) 
          功能:获得chosen下的name节点的偏移

        • fdtdec_get_chosen_prop
          const char *fdtdec_get_chosen_prop(const void *blob, const char *name) 
          功能:获得chosen下name属性的值

      • lib/fdtdec_common.c中

        • fdtdec_get_int
          int fdtdec_get_int(const void *blob, int node, const char *prop_name, int default_val) 
          eg: bus->udelay = fdtdec_get_int(blob, node, “i2c-gpio,delay-us”, DEFAULT_UDELAY); 
          功能:获得节点node的某个整形属性值。

        • fdtdec_get_uint
          功能:获得节点node的某个无符号整形属性值。

 

 lib/fdtdec.c中

#define COMPAT(id, name) name
static const char * const compat_names[COMPAT_COUNT] = {
    COMPAT(UNKNOWN, "<none>"),
    COMPAT(NVIDIA_TEGRA20_EMC, "nvidia,tegra20-emc"),
    COMPAT(NVIDIA_TEGRA20_EMC_TABLE, "nvidia,tegra20-emc-table"),
    COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"),
    COMPAT(NVIDIA_TEGRA124_XUSB_PADCTL, "nvidia,tegra124-xusb-padctl"),
    COMPAT(NVIDIA_TEGRA210_XUSB_PADCTL, "nvidia,tegra210-xusb-padctl"),
    COMPAT(SAMSUNG_EXYNOS_USB_PHY, "samsung,exynos-usb-phy"),
    COMPAT(SAMSUNG_EXYNOS5_USB3_PHY, "samsung,exynos5250-usb3-phy"),
    COMPAT(SAMSUNG_EXYNOS_TMU, "samsung,exynos-tmu"),
    COMPAT(SAMSUNG_EXYNOS_MIPI_DSI, "samsung,exynos-mipi-dsi"),
    COMPAT(SAMSUNG_EXYNOS_DWMMC, "samsung,exynos-dwmmc"),
    COMPAT(GENERIC_SPI_FLASH, "jedec,spi-nor"),
    COMPAT(SAMSUNG_EXYNOS_SYSMMU, "samsung,sysmmu-v3.3"),
    COMPAT(INTEL_MICROCODE, "intel,microcode"),
    COMPAT(INTEL_QRK_MRC, "intel,quark-mrc"),
    COMPAT(ALTERA_SOCFPGA_DWMAC, "altr,socfpga-stmmac"),
    COMPAT(ALTERA_SOCFPGA_DWMMC, "altr,socfpga-dw-mshc"),
    COMPAT(ALTERA_SOCFPGA_DWC2USB, "snps,dwc2"),
    COMPAT(INTEL_BAYTRAIL_FSP, "intel,baytrail-fsp"),
    COMPAT(INTEL_BAYTRAIL_FSP_MDP, "intel,baytrail-fsp-mdp"),
    COMPAT(INTEL_IVYBRIDGE_FSP, "intel,ivybridge-fsp"),
    COMPAT(COMPAT_SUNXI_NAND, "allwinner,sun4i-a10-nand"),
    COMPAT(ALTERA_SOCFPGA_CLK, "altr,clk-mgr"),
    COMPAT(ALTERA_SOCFPGA_PINCTRL_SINGLE, "pinctrl-single"),
    COMPAT(ALTERA_SOCFPGA_H2F_BRG, "altr,socfpga-hps2fpga-bridge"),
    COMPAT(ALTERA_SOCFPGA_LWH2F_BRG, "altr,socfpga-lwhps2fpga-bridge"),
    COMPAT(ALTERA_SOCFPGA_F2H_BRG, "altr,socfpga-fpga2hps-bridge"),
    COMPAT(ALTERA_SOCFPGA_F2SDR0, "altr,socfpga-fpga2sdram0-bridge"),
    COMPAT(ALTERA_SOCFPGA_F2SDR1, "altr,socfpga-fpga2sdram1-bridge"),
    COMPAT(ALTERA_SOCFPGA_F2SDR2, "altr,socfpga-fpga2sdram2-bridge"),
    COMPAT(ALTERA_SOCFPGA_FPGA0, "altr,socfpga-a10-fpga-mgr"),
    COMPAT(ALTERA_SOCFPGA_NOC, "altr,socfpga-a10-noc"),
    COMPAT(ALTERA_SOCFPGA_CLK_INIT, "altr,socfpga-a10-clk-init")
};

const char *fdtdec_get_compatible(enum fdt_compat_id id)


fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node,
                      const char *prop_name, int index, int na,
                      int ns, fdt_size_t *sizep,
                      bool translate)


fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent,
                        int node, const char *prop_name,
                        int index, fdt_size_t *sizep,
                        bool translate)


fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node,
                          const char *prop_name, int index,
                          fdt_size_t *sizep,
                          bool translate)


fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
                const char *prop_name, fdt_size_t *sizep)


fdt_addr_t fdtdec_get_addr(const void *blob, int node, const char *prop_name)
int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device)
int fdtdec_get_pci_bar32(const struct udevice *dev, struct fdt_pci_addr *addr,
             u32 *bar)
int fdtdec_get_pci_bus_range(const void *blob, int node,
                 struct fdt_resource *res)


uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name,
               uint64_t default_val)
int fdtdec_get_is_enabled(const void *blob, int node)
enum fdt_compat_id fdtdec_lookup(const void *blob, int node)
int fdtdec_next_compatible(const void *blob, int node, enum fdt_compat_id id)
int fdtdec_next_compatible_subnode(const void *blob, int node,
                   enum fdt_compat_id id, int *depthp)
int fdtdec_next_alias(const void *blob, const char *name, enum fdt_compat_id id,
              int *upto)
int fdtdec_find_aliases_for_id(const void *blob, const char *name,
                   enum fdt_compat_id id, int *node_list,
                   int maxcount)

int fdtdec_add_aliases_for_id(const void *blob, const char *name,
                  enum fdt_compat_id id, int *node_list,
                  int maxcount)
int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
             int *seqp)
int fdtdec_get_alias_highest_id(const void *blob, const char *base)
const char *fdtdec_get_chosen_prop(const void *blob, const char *name)
int fdtdec_get_chosen_node(const void *blob, const char *name)
int fdtdec_check_fdt(void)

int fdtdec_prepare_fdt(void)
int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name)

static const void *get_prop_check_min_len(const void *blob, int node,
                      const char *prop_name, int min_len,
                      int *err)
int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
             u32 *array, int count)
int fdtdec_get_int_array_count(const void *blob, int node,
                   const char *prop_name, u32 *array, int count)
const u32 *fdtdec_locate_array(const void *blob, int node,
                   const char *prop_name, int count)
int fdtdec_get_bool(const void *blob, int node, const char *prop_name)
int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
                   const char *list_name,
                   const char *cells_name,
                   int cell_count, int index,
                   struct fdtdec_phandle_args *out_args)
int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
              u8 *array, int count)
const u8 *fdtdec_locate_byte_array(const void *blob, int node,
                   const char *prop_name, int count)
int fdtdec_get_config_int(const void *blob, const char *prop_name,
              int default_val)
int fdtdec_get_config_bool(const void *blob, const char *prop_name)
char *fdtdec_get_config_string(const void *blob, const char *prop_name)


u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells)
int fdt_get_resource(const void *fdt, int node, const char *property,
             unsigned int index, struct fdt_resource *res)
int fdt_get_named_resource(const void *fdt, int node, const char *property,
               const char *prop_names, const char *name,
               struct fdt_resource *res)
static int decode_timing_property(const void *blob, int node, const char *name,
                  struct timing_entry *result)
int fdtdec_decode_display_timing(const void *blob, int parent, int index,
                 struct display_timing *dt)
int fdtdec_setup_mem_size_base(void)


ofnode get_next_memory_node(ofnode mem)
int fdtdec_setup_memory_banksize(void)
int fdtdec_setup_mem_size_base_lowest(void)
static int uncompress_blob(const void *src, ulong sz_src, void **dstp)

static int uncompress_blob(const void *src, ulong sz_src, void **dstp)



__weak void *board_fdt_blob_setup(void)


int fdtdec_set_ethernet_mac_address(void *fdt, const u8 *mac, size_t size)
static int fdtdec_init_reserved_memory(void *blob)
int fdtdec_add_reserved_memory(void *blob, const char *basename,
                   const struct fdt_memory *carveout,
                   uint32_t *phandlep, bool no_map)
int fdtdec_get_carveout(const void *blob, const char *node, const char *name,
            unsigned int index, struct fdt_memory *carveout)
int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name,
            unsigned int index, const char *name,
            const struct fdt_memory *carveout)


__weak int fdtdec_board_setup(const void *fdt_blob)
int fdtdec_setup(void)

int fdtdec_resetup(int *rescan)


int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
               phys_addr_t *basep, phys_size_t *sizep,
               struct bd_info *bd)
#endif /* !USE_HOSTCC */

 

lib/fdtdec_common.c中

int fdtdec_get_int(const void *blob, int node, const char *prop_name,
        int default_val)


unsigned int fdtdec_get_uint(const void *blob, int node, const char *prop_name,
            unsigned int default_val)
int fdtdec_get_child_count(const void *blob, int node)

 

 

 


DECLARE_GLOBAL_DATA_PTR;

struct uclass *uclass_find(enum uclass_id key)

static int uclass_add(enum uclass_id id, struct uclass **ucp)
int uclass_destroy(struct uclass *uc)
int uclass_get(enum uclass_id id, struct uclass **ucp)
const char *uclass_get_name(enum uclass_id id)
void *uclass_get_priv(const struct uclass *uc)
void uclass_set_priv(struct uclass *uc, void *priv)
enum uclass_id uclass_get_by_name(const char *name)
int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp)
int uclass_find_device(enum uclass_id id, int index, struct udevice **devp)
int uclass_find_first_device(enum uclass_id id, struct udevice **devp)
int uclass_find_next_device(struct udevice **devp)
int uclass_find_device_by_name(enum uclass_id id, const char *name,
                   struct udevice **devp)
int uclass_find_next_free_seq(struct uclass *uc)
int uclass_find_device_by_seq(enum uclass_id id, int seq, struct udevice **devp)
int uclass_find_device_by_of_offset(enum uclass_id id, int node,
                    struct udevice **devp)
int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node,
                 struct udevice **devp)

int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
                  const char *name, struct udevice **devp)


int uclass_get_device_by_driver(enum uclass_id id,
                const struct driver *find_drv,
                struct udevice **devp)
int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp)
int uclass_get_device(enum uclass_id id, int index, struct udevice **devp)
int uclass_get_device_by_name(enum uclass_id id, const char *name,
                  struct udevice **devp)
int uclass_get_device_by_seq(enum uclass_id id, int seq, struct udevice **devp)
int uclass_get_device_by_of_offset(enum uclass_id id, int node,
                   struct udevice **devp)
int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node,
                struct udevice **devp)

int uclass_get_device_by_phandle_id(enum uclass_id id, uint phandle_id,
                    struct udevice **devp)
int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
                 const char *name, struct udevice **devp)


int uclass_first_device(enum uclass_id id, struct udevice **devp)
int uclass_first_device_err(enum uclass_id id, struct udevice **devp)
int uclass_next_device(struct udevice **devp)
int uclass_next_device_err(struct udevice **devp)
int uclass_first_device_check(enum uclass_id id, struct udevice **devp)
int uclass_next_device_check(struct udevice **devp)
int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data,
                struct udevice **devp)
int uclass_bind_device(struct udevice *dev)

int uclass_unbind_device(struct udevice *dev)


int uclass_pre_probe_device(struct udevice *dev)
int uclass_post_probe_device(struct udevice *dev)

int uclass_pre_remove_device(struct udevice *dev)


int uclass_probe_all(enum uclass_id id)


UCLASS_DRIVER(nop) = {
    .id        = UCLASS_NOP,
    .name        = "nop",
};

 

 

 



DECLARE_GLOBAL_DATA_PTR;

static int device_bind_common(struct udevice *parent, const struct driver *drv,
                  const char *name, void *plat,
                  ulong driver_data, ofnode node,
                  uint of_plat_size, struct udevice **devp)
int device_bind_with_driver_data(struct udevice *parent,
                 const struct driver *drv, const char *name,
                 ulong driver_data, ofnode node,
                 struct udevice **devp)
int device_bind(struct udevice *parent, const struct driver *drv,
        const char *name, void *plat, ofnode node,
        struct udevice **devp)
int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
            const struct driver_info *info, struct udevice **devp)
int device_reparent(struct udevice *dev, struct udevice *new_parent)
static void *alloc_priv(int size, uint flags)

static int device_alloc_priv(struct udevice *dev)
int device_of_to_plat(struct udevice *dev)

static int device_get_dma_constraints(struct udevice *dev)
int device_probe(struct udevice *dev)
void *dev_get_plat(const struct udevice *dev)
void *dev_get_parent_plat(const struct udevice *dev)
void *dev_get_uclass_plat(const struct udevice *dev)
void *dev_get_priv(const struct udevice *dev)
void *dev_get_uclass_priv(const struct udevice *dev)
void *dev_get_parent_priv(const struct udevice *dev)
static int device_get_device_tail(struct udevice *dev, int ret,
                  struct udevice **devp)

static int device_find_by_ofnode(ofnode node, struct udevice **devp)


int device_get_child(const struct udevice *parent, int index,
             struct udevice **devp)
int device_get_child_count(const struct udevice *parent)
int device_find_child_by_seq(const struct udevice *parent, int seq,
                 struct udevice **devp)
int device_get_child_by_seq(const struct udevice *parent, int seq,
                struct udevice **devp)
int device_find_child_by_of_offset(const struct udevice *parent, int of_offset,
                   struct udevice **devp)
int device_get_child_by_of_offset(const struct udevice *parent, int node,
                  struct udevice **devp)
static struct udevice *_device_find_global_by_ofnode(struct udevice *parent,
                             ofnode ofnode)
int device_find_global_by_ofnode(ofnode ofnode, struct udevice **devp)
int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp)

int device_get_by_ofplat_idx(uint idx, struct udevice **devp)


int device_find_first_child(const struct udevice *parent, struct udevice **devp)
int device_find_next_child(struct udevice **devp)
int device_find_first_inactive_child(const struct udevice *parent,
                     enum uclass_id uclass_id,
                     struct udevice **devp)
int device_find_first_child_by_uclass(const struct udevice *parent,
                      enum uclass_id uclass_id,
                      struct udevice **devp)
int device_find_child_by_name(const struct udevice *parent, const char *name,
                  struct udevice **devp)
int device_first_child_err(struct udevice *parent, struct udevice **devp)
int device_next_child_err(struct udevice **devp)
int device_first_child_ofdata_err(struct udevice *parent, struct udevice **devp)
int device_next_child_ofdata_err(struct udevice **devp)
struct udevice *dev_get_parent(const struct udevice *child)
ulong dev_get_driver_data(const struct udevice *dev)
const void *dev_get_driver_ops(const struct udevice *dev)
enum uclass_id device_get_uclass_id(const struct udevice *dev)
const char *dev_get_uclass_name(const struct udevice *dev)
bool device_has_children(const struct udevice *dev)
bool device_has_active_children(const struct udevice *dev)
bool device_is_last_sibling(const struct udevice *dev)
void device_set_name_alloced(struct udevice *dev)


int device_set_name(struct udevice *dev, const char *name)
void dev_set_priv(struct udevice *dev, void *priv)
void dev_set_parent_priv(struct udevice *dev, void *parent_priv)
void dev_set_uclass_priv(struct udevice *dev, void *uclass_priv)
void dev_set_plat(struct udevice *dev, void *plat)
void dev_set_parent_plat(struct udevice *dev, void *parent_plat)
void dev_set_uclass_plat(struct udevice *dev, void *uclass_plat)
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
bool device_is_compatible(const struct udevice *dev, const char *compat)
bool of_machine_is_compatible(const char *compat)
int dev_disable_by_path(const char *path)
int dev_enable_by_path(const char *path)

static struct udevice_rt *dev_get_rt(const struct udevice *dev)


u32 dev_get_flags(const struct udevice *dev)
void dev_or_flags(const struct udevice *dev, u32 or)
void dev_bic_flags(const struct udevice *dev, u32 bic)

 

 

 

 

posted @ 2022-02-13 10:56  liujunhuasd  阅读(1979)  评论(0编辑  收藏  举报