From dfc0acd0cc3cd14f64cb6850465ade98ea84b366 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 22 Aug 2024 07:54:56 -0600 Subject: log: Avoid including function names by default Unless function names are requested, the logging system should not compile these into the code. Adjust the macros to handle this. This means that turning on function names at runtime won't work unless CONFIG_LOGF_FUNC is enabled. We could perhaps split this into a separate option if that is a problem. Enable CONFIG_LOGF_FUNC logging for sandbox since the tests expect the function names to be included. Fix up the pinmux test which checks a logging statement. Signed-off-by: Simon Glass Reviewed-by: Quentin Schulz --- include/log.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/log.h b/include/log.h index fc0d5984472..69dcb339543 100644 --- a/include/log.h +++ b/include/log.h @@ -125,7 +125,7 @@ static inline int log_uc_cat(enum uclass_id id) * @level: Level of log record (indicating its severity) * @file: File name of file where log record was generated * @line: Line number in file where log record was generated - * @func: Function where log record was generated + * @func: Function where log record was generated, NULL if not known * @fmt: printf() format string for log record * @...: Optional parameters, according to the format string @fmt * Return: 0 if log record was emitted, -ve on error @@ -141,7 +141,7 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, * @level: Level of log record (indicating its severity) * @file: File name of file where log record was generated * @line: Line number in file where log record was generated - * @func: Function where log record was generated + * @func: Function where log record was generated, NULL if not known * @addr: Starting address to display at start of line * @data: pointer to data buffer * @width: data value width. May be 1, 2, or 4. @@ -193,6 +193,12 @@ int _log_buffer(enum log_category_t cat, enum log_level_t level, #define _LOG_DEBUG 0 #endif +#ifdef CONFIG_LOGF_FUNC +#define _log_func __func__ +#else +#define _log_func NULL +#endif + #if CONFIG_IS_ENABLED(LOG) /* Emit a log record if the level is less that the maximum */ @@ -201,7 +207,7 @@ int _log_buffer(enum log_category_t cat, enum log_level_t level, if (_LOG_DEBUG != 0 || _l <= _LOG_MAX_LEVEL) \ _log((enum log_category_t)(_cat), \ (enum log_level_t)(_l | _LOG_DEBUG), __FILE__, \ - __LINE__, __func__, \ + __LINE__, _log_func, \ pr_fmt(_fmt), ##_args); \ }) @@ -211,7 +217,7 @@ int _log_buffer(enum log_category_t cat, enum log_level_t level, if (_LOG_DEBUG != 0 || _l <= _LOG_MAX_LEVEL) \ _log_buffer((enum log_category_t)(_cat), \ (enum log_level_t)(_l | _LOG_DEBUG), __FILE__, \ - __LINE__, __func__, _addr, _data, \ + __LINE__, _log_func, _addr, _data, \ _width, _count, _linelen); \ }) #else @@ -314,7 +320,7 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line, #define assert_noisy(x) \ ({ bool _val = (x); \ if (!_val) \ - __assert_fail(#x, "?", __LINE__, __func__); \ + __assert_fail(#x, "?", __LINE__, _log_func); \ _val; \ }) -- cgit v1.2.3 From 50a1ed4335045c57d9073a3fcd265edd89da924a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 22 Aug 2024 07:55:01 -0600 Subject: spl: Use unified inline functions for spl_load_info Rather than declaring completely separate functions, put the code for each case into the same function. This makes it easier to read. Signed-off-by: Simon Glass Reviewed-by: Sean Anderson Reviewed-by: Quentin Schulz --- include/spl.h | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/spl.h b/include/spl.h index f92089b69ea..fb26e3f5537 100644 --- a/include/spl.h +++ b/include/spl.h @@ -306,31 +306,27 @@ struct spl_load_info { void *buf); #if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK) int bl_len; +#endif }; static inline int spl_get_bl_len(struct spl_load_info *info) { +#if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK) return info->bl_len; -} - -static inline void spl_set_bl_len(struct spl_load_info *info, int bl_len) -{ - info->bl_len = bl_len; -} #else -}; - -static inline int spl_get_bl_len(struct spl_load_info *info) -{ return 1; +#endif } static inline void spl_set_bl_len(struct spl_load_info *info, int bl_len) { +#if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK) + info->bl_len = bl_len; +#else if (bl_len != 1) panic("CONFIG_SPL_LOAD_BLOCK not enabled"); -} #endif +} /* * We need to know the position of U-Boot in memory so we can jump to it. We -- cgit v1.2.3 From 3fd11278ff43a5039e33a8cf04dc822711ea9694 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 22 Aug 2024 07:55:02 -0600 Subject: spl: Create a function to init spl_load_info Rather than having every caller set this up individually, create a common init function. This allows new fields to be added without the risk of them being left uninited. Signed-off-by: Simon Glass Reviewed-by: Michael Trimarchi --- include/spl.h | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/spl.h b/include/spl.h index fb26e3f5537..de808ccd413 100644 --- a/include/spl.h +++ b/include/spl.h @@ -282,28 +282,32 @@ static inline void *spl_image_fdt_addr(struct spl_image_info *info) #endif } +struct spl_load_info; + +/** + * spl_load_reader() - Read from device + * + * @load: Information about the load state + * @offset: Offset to read from in bytes. This must be a multiple of + * @load->bl_len. + * @count: Number of bytes to read. This must be a multiple of + * @load->bl_len. + * @buf: Buffer to read into + * @return number of bytes read, 0 on error + */ +typedef ulong (*spl_load_reader)(struct spl_load_info *load, ulong sector, + ulong count, void *buf); + /** * Information required to load data from a device * + * @read: Function to call to read from the device * @priv: Private data for the device * @bl_len: Block length for reading in bytes - * @read: Function to call to read from the device */ struct spl_load_info { + spl_load_reader read; void *priv; - /** - * read() - Read from device - * - * @load: Information about the load state - * @offset: Offset to read from in bytes. This must be a multiple of - * @load->bl_len. - * @count: Number of bytes to read. This must be a multiple of - * @load->bl_len. - * @buf: Buffer to read into - * @return number of bytes read, 0 on error - */ - ulong (*read)(struct spl_load_info *load, ulong sector, ulong count, - void *buf); #if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK) int bl_len; #endif @@ -328,6 +332,18 @@ static inline void spl_set_bl_len(struct spl_load_info *info, int bl_len) #endif } +/** + * spl_load_init() - Set up a new spl_load_info structure + */ +static inline void spl_load_init(struct spl_load_info *load, + spl_load_reader h_read, void *priv, + uint bl_len) +{ + load->read = h_read; + load->priv = priv; + spl_set_bl_len(load, bl_len); +} + /* * We need to know the position of U-Boot in memory so we can jump to it. We * allow any U-Boot binary to be used (u-boot.bin, u-boot-nodtb.bin, -- cgit v1.2.3 From d938743d15a9bbe46353d15f16fb4b764e1462b7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 22 Aug 2024 07:55:03 -0600 Subject: blk: Correct comment for blk_get_devnum_by_uclass_idname() Update the comment to match the function. Fix the indentation while we are here. Signed-off-by: Simon Glass Reviewed-by: Sean Anderson Reviewed-by: Quentin Schulz --- include/blk.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/blk.h b/include/blk.h index 7c7cf7f2b10..1fc9a5b8471 100644 --- a/include/blk.h +++ b/include/blk.h @@ -650,7 +650,7 @@ struct blk_driver *blk_driver_lookup_type(int uclass_id); struct blk_desc *blk_get_devnum_by_uclass_id(enum uclass_id uclass_id, int devnum); /** - * blk_get_devnum_by_uclass_id() - Get a block device by type name, and number + * blk_get_devnum_by_uclass_idname() - Get block device by type name and number * * This looks up the block device type based on @uclass_idname, then calls * blk_get_devnum_by_uclass_id(). @@ -660,7 +660,7 @@ struct blk_desc *blk_get_devnum_by_uclass_id(enum uclass_id uclass_id, int devnu * Return: point to block device descriptor, or NULL if not found */ struct blk_desc *blk_get_devnum_by_uclass_idname(const char *uclass_idname, - int devnum); + int devnum); /** * blk_dselect_hwpart() - select a hardware partition -- cgit v1.2.3