Add support for device-tree-based drivers.

This commit is contained in:
Vladimir Serbinenko 2017-05-08 21:19:59 +02:00 committed by Vincent Batts
parent aa7585d04b
commit 1895c3806b
13 changed files with 519 additions and 52 deletions

View file

@ -20,6 +20,7 @@
#define GRUB_FDT_HEADER 1
#include <grub/types.h>
#include <grub/symbol.h>
#define FDT_MAGIC 0xD00DFEED
@ -95,16 +96,22 @@ struct grub_fdt_empty_tree {
#define grub_fdt_set_size_dt_struct(fdt, value) \
grub_fdt_set_header(fdt, size_dt_struct, value)
int grub_fdt_create_empty_tree (void *fdt, unsigned int size);
int grub_fdt_check_header (void *fdt, unsigned int size);
int grub_fdt_check_header_nosize (void *fdt);
int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset,
const char *name);
int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset,
int EXPORT_FUNC(grub_fdt_create_empty_tree) (void *fdt, unsigned int size);
int EXPORT_FUNC(grub_fdt_check_header) (const void *fdt, unsigned int size);
int EXPORT_FUNC(grub_fdt_check_header_nosize) (const void *fdt);
int EXPORT_FUNC(grub_fdt_find_subnode) (const void *fdt, unsigned int parentoffset,
const char *name);
int EXPORT_FUNC(grub_fdt_first_node) (const void *fdt, unsigned int parentoffset);
int EXPORT_FUNC(grub_fdt_next_node) (const void *fdt, unsigned int currentoffset);
int EXPORT_FUNC(grub_fdt_add_subnode) (void *fdt, unsigned int parentoffset,
const char *name);
const char *
EXPORT_FUNC(grub_fdt_get_nodename) (const void *fdt, unsigned int nodeoffset);
const void *EXPORT_FUNC(grub_fdt_get_prop) (const void *fdt, unsigned int nodeoffset, const char *name,
grub_uint32_t *len);
int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name,
const void *val, grub_uint32_t len);
int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const char *name,
const void *val, grub_uint32_t len);
#define grub_fdt_set_prop32(fdt, nodeoffset, name, val) \
({ \
grub_uint32_t _val = grub_cpu_to_be32(val); \

73
include/grub/fdtbus.h Normal file
View file

@ -0,0 +1,73 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2016 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_FDTBUS_HEADER
#define GRUB_FDTBUS_HEADER 1
#include <grub/fdt.h>
#include <grub/err.h>
struct grub_fdtbus_dev;
struct grub_fdtbus_driver
{
struct grub_fdtbus_driver *next;
struct grub_fdtbus_driver **prev;
const char *compatible;
grub_err_t (*attach) (const struct grub_fdtbus_dev *dev);
void (*detach) (const struct grub_fdtbus_dev *dev);
};
extern char EXPORT_VAR(grub_fdtbus_invalid_mapping)[1];
static inline int
grub_fdtbus_is_mapping_valid (volatile void *m)
{
return m != grub_fdtbus_invalid_mapping;
}
volatile void *
EXPORT_FUNC(grub_fdtbus_map_reg) (const struct grub_fdtbus_dev *dev, int reg, grub_size_t *size);
const void *
EXPORT_FUNC(grub_fdtbus_get_fdt) (void);
const char *
EXPORT_FUNC(grub_fdtbus_get_name) (const struct grub_fdtbus_dev *dev);
const void *
EXPORT_FUNC(grub_fdtbus_get_prop) (const struct grub_fdtbus_dev *dev,
const char *name,
grub_uint32_t *len);
void
EXPORT_FUNC(grub_fdtbus_register) (struct grub_fdtbus_driver *driver);
void
EXPORT_FUNC(grub_fdtbus_unregister) (struct grub_fdtbus_driver *driver);
/* Must be called before any register(). */
/* dtb is assumed to be unfreeable and must remain
valid for lifetime of GRUB.
*/
void
grub_fdtbus_init (const void *dtb, grub_size_t size);
#endif

View file

@ -28,7 +28,8 @@ enum
OBJ_TYPE_MEMDISK,
OBJ_TYPE_CONFIG,
OBJ_TYPE_PREFIX,
OBJ_TYPE_PUBKEY
OBJ_TYPE_PUBKEY,
OBJ_TYPE_DTB
};
/* The module header. */

View file

@ -176,7 +176,7 @@ grub_install_generate_image (const char *dir, const char *prefix,
char *config_path,
const struct grub_install_image_target_desc *image_target,
int note,
grub_compression_t comp);
grub_compression_t comp, const char *dtb_file);
const struct grub_install_image_target_desc *
grub_install_get_image_target (const char *arg);