blob: f2fb5f55faab97a60dc02a39a47f20f5e9b69724 [file] [log] [blame]
Simon Glass08ad13e2022-04-24 23:31:06 -06001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Standard U-Boot boot framework
4 *
5 * Copyright 2021 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#ifndef __bootstd_h
10#define __bootstd_h
11
Simon Glass199f5882024-11-15 16:19:12 -070012#include <alist.h>
Simon Glassd92bcc42023-01-06 08:52:42 -060013#include <dm/ofnode_decl.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060014#include <linux/types.h>
Simon Glassd92bcc42023-01-06 08:52:42 -060015
Simon Glass08ad13e2022-04-24 23:31:06 -060016struct udevice;
17
18/**
19 * struct bootstd_priv - priv data for the bootstd driver
20 *
21 * This is attached to the (only) bootstd device, so there is only one instance
22 * of this struct. It provides overall information about bootdevs and bootflows.
23 *
Simon Glass60d3c512025-03-15 14:25:59 +000024 * TODO(sjg@chromium.org): Convert prefixes, bootdev_order and env_order to use
25 * alist
26 *
Simon Glass08ad13e2022-04-24 23:31:06 -060027 * @prefixes: NULL-terminated list of prefixes to use for bootflow filenames,
28 * e.g. "/", "/boot/"; NULL if none
29 * @bootdev_order: Order to use for bootdevs (or NULL if none), with each item
Simon Glassa1bcafb2023-01-17 10:47:15 -070030 * being a bootdev label, e.g. "mmc2", "mmc1" (NULL terminated)
31 * @env_order: Order as specified by the boot_targets env var (or NULL if none),
32 * with each item being a bootdev label, e.g. "mmc2", "mmc1" (NULL
33 * terminated)
Simon Glass08ad13e2022-04-24 23:31:06 -060034 * @cur_bootdev: Currently selected bootdev (for commands)
35 * @cur_bootflow: Currently selected bootflow (for commands)
Simon Glass199f5882024-11-15 16:19:12 -070036 * @bootflows: (struct bootflow) Global list of all bootflows across all
37 * bootdevs
Simon Glass08ad13e2022-04-24 23:31:06 -060038 * @bootmeth_count: Number of bootmeth devices in @bootmeth_order
39 * @bootmeth_order: List of bootmeth devices to use, in order, NULL-terminated
Simon Glass0a9f4262022-07-30 15:52:32 -060040 * @vbe_bootmeth: Currently selected VBE bootmeth, NULL if none
Simon Glassd92bcc42023-01-06 08:52:42 -060041 * @theme: Node containing the theme information
Simon Glass5acb97a2023-01-17 10:47:33 -070042 * @hunters_used: Bitmask of used hunters, indexed by their position in the
43 * linker list. The bit is set if the hunter has been used already
Simon Glass08ad13e2022-04-24 23:31:06 -060044 */
45struct bootstd_priv {
46 const char **prefixes;
47 const char **bootdev_order;
Simon Glassa1bcafb2023-01-17 10:47:15 -070048 const char **env_order;
Simon Glass08ad13e2022-04-24 23:31:06 -060049 struct udevice *cur_bootdev;
50 struct bootflow *cur_bootflow;
Simon Glass199f5882024-11-15 16:19:12 -070051 struct alist bootflows;
Simon Glass08ad13e2022-04-24 23:31:06 -060052 int bootmeth_count;
53 struct udevice **bootmeth_order;
Simon Glass0a9f4262022-07-30 15:52:32 -060054 struct udevice *vbe_bootmeth;
Simon Glassd92bcc42023-01-06 08:52:42 -060055 ofnode theme;
Simon Glass5acb97a2023-01-17 10:47:33 -070056 uint hunters_used;
Simon Glass08ad13e2022-04-24 23:31:06 -060057};
58
59/**
60 * bootstd_get_bootdev_order() - Get the boot-order list
61 *
62 * This reads the boot order, e.g. {"mmc0", "mmc2", NULL}
63 *
64 * The list is alloced by the bootstd driver so should not be freed. That is the
65 * reason for all the const stuff in the function signature
66 *
Simon Glassa1bcafb2023-01-17 10:47:15 -070067 * @dev: bootstd device
68 * @okp: returns true if OK, false if out of memory
69 * Return: list of string pointers, terminated by NULL; or NULL if no boot
70 * order. Note that this returns NULL in the case of an empty list
Simon Glass08ad13e2022-04-24 23:31:06 -060071 */
Simon Glassa1bcafb2023-01-17 10:47:15 -070072const char *const *const bootstd_get_bootdev_order(struct udevice *dev,
73 bool *okp);
Simon Glass08ad13e2022-04-24 23:31:06 -060074
75/**
76 * bootstd_get_prefixes() - Get the filename-prefixes list
77 *
Julien Delbergueb5fb4802023-07-13 11:53:09 +020078 * This reads the prefixes, e.g. {"/", "/boot", NULL}
Simon Glass08ad13e2022-04-24 23:31:06 -060079 *
80 * The list is alloced by the bootstd driver so should not be freed. That is the
81 * reason for all the const stuff in the function signature
82 *
83 * Return: list of string points, terminated by NULL; or NULL if no boot order
84 */
85const char *const *const bootstd_get_prefixes(struct udevice *dev);
86
87/**
88 * bootstd_get_priv() - Get the (single) state for the bootstd system
89 *
90 * The state holds a global list of all bootflows that have been found.
91 *
92 * Return: 0 if OK, -ve if the uclass does not exist
93 */
94int bootstd_get_priv(struct bootstd_priv **stdp);
95
96/**
Simon Glass2bcd9ea2024-11-15 16:19:10 -070097 * bootstd_try_priv() - Try to get the (single) state for the bootstd system
98 *
99 * The state holds a global list of all bootflows that have been found. This
100 * function returns the state if available, but takes care not to create the
101 * device (or uclass) if it doesn't exist.
102 *
103 * This function is safe to use in the 'unbind' path. It will always return NULL
104 * unless the bootstd device is probed and ready, e.g. bootstd_get_priv() has
105 * previously been called.
106 *
107 * TODO(sjg@chromium.org): Consider adding a bootstd pointer to global_data
108 *
109 * Return: pointer if the device exists, else NULL
110 */
111struct bootstd_priv *bootstd_try_priv(void);
112
113/**
Simon Glass08ad13e2022-04-24 23:31:06 -0600114 * bootstd_clear_glob() - Clear the global list of bootflows
115 *
116 * This removes all bootflows globally and across all bootdevs.
117 */
118void bootstd_clear_glob(void);
119
Simon Glass92368522023-11-18 14:05:19 -0700120/**
121 * bootstd_prog_boot() - Run standard boot in a fully programmatic mode
122 *
123 * Attempts to boot without making any use of U-Boot commands
124 *
125 * Returns: -ve error value (does not return except on failure to boot)
126 */
127int bootstd_prog_boot(void);
128
Simon Glassc01d83f2024-11-15 16:19:08 -0700129/**
Simon Glass1d8f8642024-11-15 16:19:11 -0700130 * bootstd_add_bootflow() - Add a bootflow to the global list
Simon Glassc01d83f2024-11-15 16:19:08 -0700131 *
132 * All fields in @bflow must be set up. Note that @bflow->dev is used to add the
133 * bootflow to that device.
134 *
135 * The bootflow is also added to the global list of all bootflows
136 *
137 * @dev: Bootdev device to add to
138 * @bflow: Bootflow to add. Note that fields within bflow must be allocated
139 * since this function takes over ownership of these. This functions makes
140 * a copy of @bflow itself (without allocating its fields again), so the
141 * caller must dispose of the memory used by the @bflow pointer itself
Simon Glass199f5882024-11-15 16:19:12 -0700142 * Return: element number in the list, if OK, -ENOMEM if out of memory
Simon Glassc01d83f2024-11-15 16:19:08 -0700143 */
144int bootstd_add_bootflow(struct bootflow *bflow);
145
Simon Glass346ab5d2024-11-15 16:19:09 -0700146/**
147 * bootstd_clear_bootflows_for_bootdev() - Clear bootflows from a bootdev
148 *
149 * Each bootdev maintains a list of discovered bootflows. This provides a
150 * way to clear it. These bootflows are removed from the global list too.
151 *
152 * @dev: bootdev device to update
153 */
154int bootstd_clear_bootflows_for_bootdev(struct udevice *dev);
155
Simon Glass08ad13e2022-04-24 23:31:06 -0600156#endif