[PATCH v1 1/8] cros: add common helpers for GPT flags

Quentin Schulz quentin.schulz at cherry.de
Fri Jun 26 18:09:22 CEST 2026


Hi Denis,

On 6/5/26 5:39 AM, dmukhin at ford.com wrote:
> From: Denis Mukhin <dmukhin at ford.com>
> 
> Add common helper to decode/encode ChromuimOS-style GPT attributes
> similarly to [1].
> 
> [1] https://chromium.googlesource.com/chromiumos/platform/vboot_reference/+/master/cgpt

Can you tell us *which* commit you used in the commit log. I'm assuming 
master is a moving branch so this makes it harder to look for future fixes.

> Signed-off-by: Denis Mukhin <dmukhin at ford.com>
> ---
>   include/cros_flags.h | 74 ++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 74 insertions(+)
>   create mode 100644 include/cros_flags.h
> 
> diff --git a/include/cros_flags.h b/include/cros_flags.h
> new file mode 100644
> index 000000000000..e9355fa5e908
> --- /dev/null
> +++ b/include/cros_flags.h
> @@ -0,0 +1,74 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Bit definitions and masks for GPT attributes for Chromium OS.
> + *
> + *  63-61  -- (reserved)
> + *     60  -- read-only
> + *  59-58  -- (reserved)
> + *     57  -- error counter
> + *     56  -- success
> + *  55-52  -- tries
> + *  51-48  -- priority
> + *   47-3  -- UEFI: reserved for future use
> + *      2  -- UEFI: Legacy BIOS bootable
> + *      1  -- UEFI: partition is not mapped
> + *      0  -- UEFI: partition is required
> + *
> + * Reference:
> + *   https://chromium.googlesource.com/chromiumos/platform/vboot_reference/+/master/cgpt

Possibly here as well so we don't get confused if this differs from 
master of vboot in years from now?

> + */
> +
> +#ifndef _CROS_FLAGS_H
> +#define _CROS_FLAGS_H
> +
> +#define CROS_FLAG_PRIORITY_MASK      0x000fU
> +#define CROS_FLAG_TRIES_MASK         0x00f0U
> +#define CROS_FLAG_SUCCESSFUL_MASK    0x0100U
> +
> +#define CROS_FLAG_PRIORITY_SHIFT     0U
> +#define CROS_FLAG_TRIES_SHIFT        4U
> +#define CROS_FLAG_SUCCESSFUL_SHIFT   8U
> +
> +static inline unsigned int
> +cros_flags_get_priority(unsigned int flags)
> +{
> +	return (flags & CROS_FLAG_PRIORITY_MASK) >> CROS_FLAG_PRIORITY_SHIFT;
> +}
> +
> +static inline unsigned int
> +cros_flags_set_priority(unsigned int flags, unsigned int priority)
> +{
> +	flags &= ~CROS_FLAG_PRIORITY_MASK;
> +	flags |= (priority & 0xf) << CROS_FLAG_PRIORITY_SHIFT;
> +	return flags;
> +}
> +
> +static inline unsigned int
> +cros_flags_get_tries(unsigned int flags)
> +{
> +	return (flags & CROS_FLAG_TRIES_MASK) >> CROS_FLAG_TRIES_SHIFT;
> +}
> +
> +static inline unsigned int
> +cros_flags_set_tries(unsigned int flags, unsigned int tries)
> +{
> +	flags &= ~CROS_FLAG_TRIES_MASK;
> +	flags |= (tries & 0xf) << CROS_FLAG_TRIES_SHIFT;
> +	return flags;
> +}
> +
> +static inline bool
> +cros_flags_get_successful(unsigned int flags)
> +{
> +	return (flags & CROS_FLAG_SUCCESSFUL_MASK) >> CROS_FLAG_SUCCESSFUL_SHIFT;
> +}
> +
> +static inline unsigned int
> +cros_flags_set_successful(unsigned int flags, bool ok)
> +{
> +	flags &= ~CROS_FLAG_SUCCESSFUL_MASK;
> +	flags |= ok << CROS_FLAG_SUCCESSFUL_SHIFT;
> +	return flags;
> +}
> +
> +#endif /* _CROS_FLAGS_H */

Would it make sense to use the nice GENMASK, FIELD_GET, FIELD_PREP 
macros from Linux for bitfield and masks?

Cheers,
Quentin


More information about the U-Boot mailing list