[PATCH 00/12] event: Add support for events/hooks

Simon Glass sjg at chromium.org
Tue Dec 28 09:28:42 CET 2021


It is a common need in U-Boot to have one subsystem notify another
when something happens. An example is reading a partition table when a
new block device is set up.

It is also common to add weak functions and 'hook' functions to modify
how U-Boot works. See for example ft_board_setup() and the like.

U-Boot would benefit from a generic mechanism to handle these cases,
with the ability to hook into various 'events' in a
subsystem-independent and transparent way.

This series provides a way to create and dispatch events, with a way of
registering a 'spy' which watches for events of different types. This
allows 'hook' functions to be created in a generic way.

It also includes a script to list the hooks in an image, which is a bit
easier to debug than weak functions, as well as an 'event' command to
do the same from within U-Boot.

These 'static' events can be used to replace hooks like misc_init_f(),
for example. Also included is basic support for 'dynamic' events, where
a spy can be registered at runtime. The need for this is still being
figured out.

Enabling events uses a little over 200 bytes of extra code space, on
32-bit machines, a one-off cost.


Simon Glass (12):
  Makefile: Keep symbols in u-boot-init with LTO
  sandbox: start: Sort the header files
  binman: Expand elf support a little
  event: Add basic support for events
  event: Add a simple test
  event: Set up the event system on start-up
  event: Add events for device probe/remove
  event: Convert misc_init_f() to use events
  event: Convert arch_cpu_init_dm() to use events
  event: Add a command
  event: Add a script to decode the event-spy list
  event: Add documentation

 MAINTAINERS                           |  10 ++
 Makefile                              |   2 +-
 arch/Kconfig                          |   3 +
 arch/arm/Kconfig                      |   3 +
 arch/arm/include/asm/omap_common.h    |   2 +
 arch/arm/mach-imx/imx8m/soc.c         |   4 +-
 arch/arm/mach-imx/imx8ulp/soc.c       |   4 +-
 arch/arm/mach-omap2/am33xx/board.c    |  10 +-
 arch/arm/mach-omap2/hwinit-common.c   |   5 +-
 arch/mips/Kconfig                     |   1 +
 arch/mips/mach-pic32/cpu.c            |   4 +-
 arch/nios2/cpu/cpu.c                  |   4 +-
 arch/riscv/cpu/cpu.c                  |   5 +-
 arch/riscv/include/asm/system.h       |   5 +
 arch/riscv/lib/spl.c                  |   3 +-
 arch/sandbox/cpu/start.c              |   8 +-
 arch/x86/cpu/baytrail/cpu.c           |   4 +-
 arch/x86/cpu/broadwell/cpu.c          |   4 +-
 arch/x86/cpu/ivybridge/cpu.c          |   4 +-
 arch/x86/cpu/quark/quark.c            |   4 +-
 arch/x86/include/asm/fsp2/fsp_api.h   |   8 ++
 arch/x86/lib/fsp2/fsp_init.c          |   4 +-
 arch/x86/lib/spl.c                    |  12 --
 arch/x86/lib/tpl.c                    |  10 --
 board/google/chromebook_coral/coral.c |   6 +-
 board/keymile/kmcent2/kmcent2.c       |   5 +-
 cmd/Kconfig                           |   8 ++
 cmd/Makefile                          |   1 +
 cmd/event.c                           |  27 ++++
 common/Kconfig                        |  37 ++++-
 common/Makefile                       |   2 +
 common/board_f.c                      |  13 +-
 common/board_r.c                      |   1 +
 common/event.c                        | 196 ++++++++++++++++++++++++++
 common/log.c                          |   1 +
 configs/chromebook_coral_defconfig    |   1 +
 configs/galileo_defconfig             |   1 +
 configs/kmcent2_defconfig             |   2 +-
 configs/sandbox64_defconfig           |   1 -
 configs/sandbox_defconfig             |   1 -
 configs/sandbox_flattree_defconfig    |   1 -
 configs/sandbox_spl_defconfig         |   1 -
 configs/tools-only_defconfig          |   1 -
 doc/develop/event.rst                 | 100 +++++++++++++
 doc/develop/index.rst                 |   1 +
 doc/usage/event.rst                   |  49 +++++++
 doc/usage/index.rst                   |   1 +
 drivers/core/Kconfig                  |  10 ++
 drivers/core/device-remove.c          |   8 ++
 drivers/core/device.c                 |   9 ++
 drivers/core/root.c                   |   5 +
 include/asm-generic/global_data.h     |  13 ++
 include/dm/device-internal.h          |  10 ++
 include/event.h                       | 182 ++++++++++++++++++++++++
 include/event_internal.h              |  35 +++++
 include/init.h                        |  12 --
 include/log.h                         |   2 +
 scripts/event_dump.py                 | 117 +++++++++++++++
 test/common/Makefile                  |   1 +
 test/common/event.c                   |  85 +++++++++++
 test/py/tests/test_event_dump.py      |  19 +++
 test/test-main.c                      |   4 +
 tools/binman/elf.py                   |  58 +++++++-
 63 files changed, 1067 insertions(+), 83 deletions(-)
 create mode 100644 cmd/event.c
 create mode 100644 common/event.c
 create mode 100644 doc/develop/event.rst
 create mode 100644 doc/usage/event.rst
 create mode 100644 include/event.h
 create mode 100644 include/event_internal.h
 create mode 100755 scripts/event_dump.py
 create mode 100644 test/common/event.c
 create mode 100644 test/py/tests/test_event_dump.py

-- 
2.34.1.448.ga2b2bfdf31-goog



More information about the U-Boot mailing list