emdbg.patch.set
1# Copyright (c) 2023, Auterion AG 2# SPDX-License-Identifier: BSD-3-Clause 3 4from __future__ import annotations 5from pathlib import Path 6from .operation import CopyOperation, PatchOperation, PatchManager 7 8def _data(file: str) -> Path: 9 return Path(__file__).parent / "data" / file 10 11 12def semaphore_boostlog(px4_root: Path) -> PatchManager: 13 """ 14 Enable runtime logging of task priority boosting through semaphores. 15 This adds a lock-free 32 slot buffer containing task and priority information 16 that is written from inside the kernel and read in the PX4 logger module, 17 which logs it out to the NSH. 18 """ 19 operations = [ 20 PatchOperation(px4_root, _data("semaphore_boostlog.patch")), 21 CopyOperation(_data("sem_boostlog.c"), 22 px4_root / "platforms/nuttx/NuttX/nuttx/sched/semaphore/sem_boostlog.c"), 23 CopyOperation(_data("semaphore_boostlog.h"), 24 px4_root / "platforms/nuttx/NuttX/nuttx/include/semaphore_boostlog.h"), 25 ] 26 return PatchManager("Logging of Task Priority Inheritance by Semaphores", operations) 27 28 29def reduce_firmware_size_v5x(px4_root: Path) -> PatchManager: 30 """ 31 Disables UAVCAN and a few drivers to make the binary size fit on the FMUv5x. 32 """ 33 operations = [ 34 PatchOperation(px4_root, _data("disable_uavcan_v5x.patch")), 35 ] 36 return PatchManager("Make the Firmware fit on the FMUv5x Flash", operations) 37 38 39def _nuttx_tracing_itm(px4_root: Path) -> list: 40 operations = [ 41 CopyOperation(_data("itm.h"), 42 px4_root / "platforms/nuttx/NuttX/nuttx/include/nuttx/itm/itm.h"), 43 CopyOperation(_data("itm_Make.defs"), 44 px4_root / "platforms/nuttx/NuttX/nuttx/drivers/itm/Make.defs"), 45 PatchOperation(px4_root, _data("itm_nuttx_Makefile.patch")), 46 PatchOperation(px4_root, _data("nuttx_tracing_itm.patch")), 47 ] 48 return operations 49 50def nuttx_tracing_itm_v10(px4_root: Path) -> PatchManager: 51 """ 52 Adds scheduler and heap instrumentation to NuttX v10 via ITM. 53 """ 54 operations = _nuttx_tracing_itm(px4_root) + [ 55 PatchOperation(px4_root, _data("nuttx_tracing_itm_v10.patch")), 56 ] 57 return PatchManager("Add tracing support to NuttX v10 via ITM", operations) 58 59def nuttx_tracing_itm_v11(px4_root: Path) -> PatchManager: 60 """ 61 Adds scheduler and heap instrumentation to NuttX v11 via ITM. 62 """ 63 operations = _nuttx_tracing_itm(px4_root) + [ 64 PatchOperation(px4_root, _data("nuttx_tracing_itm_v11.patch")), 65 ] 66 return PatchManager("Add tracing support to NuttX v11 via ITM", operations) 67 68 69def nuttx_tracing_itm_uart4(px4_root: Path) -> PatchManager: 70 """ 71 Trace data reception errors on UART4. 72 """ 73 operations = [ 74 PatchOperation(px4_root, _data("nuttx_tracing_itm_uart4.patch")), 75 ] 76 return PatchManager("Trace data transmit/receive errors on UART4", operations) 77 78 79def nuttx_sdmmc_reg_access(px4_root: Path) -> PatchManager: 80 """ 81 Un-inlines the `sdmmc_putreg32`, `sdmmc_getreg32`, and `sdmmc_modifyreg32` 82 functions, so that breakpoints can be set on them. 83 """ 84 operations = [ 85 PatchOperation(px4_root, _data("sdmmc_no_inline.patch")), 86 ] 87 return PatchManager("Un-inline SDMMC register access", operations) 88 89 90def malloc_return_null(px4_root: Path) -> PatchManager: 91 """ 92 Instruments the mm_malloc in NuttX to fail if call count equals global 93 `emdbg_malloc_count_null` variable, which is placed in `.noinit` section. 94 You can use this to find code that doesn't check the malloc return value for 95 NULL or see how the error handling performs. 96 """ 97 operations = [ 98 PatchOperation(px4_root, _data("malloc_return_null.patch")), 99 ] 100 return PatchManager("Make the n-th malloc call return NULL", operations)
13def semaphore_boostlog(px4_root: Path) -> PatchManager: 14 """ 15 Enable runtime logging of task priority boosting through semaphores. 16 This adds a lock-free 32 slot buffer containing task and priority information 17 that is written from inside the kernel and read in the PX4 logger module, 18 which logs it out to the NSH. 19 """ 20 operations = [ 21 PatchOperation(px4_root, _data("semaphore_boostlog.patch")), 22 CopyOperation(_data("sem_boostlog.c"), 23 px4_root / "platforms/nuttx/NuttX/nuttx/sched/semaphore/sem_boostlog.c"), 24 CopyOperation(_data("semaphore_boostlog.h"), 25 px4_root / "platforms/nuttx/NuttX/nuttx/include/semaphore_boostlog.h"), 26 ] 27 return PatchManager("Logging of Task Priority Inheritance by Semaphores", operations)
Enable runtime logging of task priority boosting through semaphores. This adds a lock-free 32 slot buffer containing task and priority information that is written from inside the kernel and read in the PX4 logger module, which logs it out to the NSH.
30def reduce_firmware_size_v5x(px4_root: Path) -> PatchManager: 31 """ 32 Disables UAVCAN and a few drivers to make the binary size fit on the FMUv5x. 33 """ 34 operations = [ 35 PatchOperation(px4_root, _data("disable_uavcan_v5x.patch")), 36 ] 37 return PatchManager("Make the Firmware fit on the FMUv5x Flash", operations)
Disables UAVCAN and a few drivers to make the binary size fit on the FMUv5x.
51def nuttx_tracing_itm_v10(px4_root: Path) -> PatchManager: 52 """ 53 Adds scheduler and heap instrumentation to NuttX v10 via ITM. 54 """ 55 operations = _nuttx_tracing_itm(px4_root) + [ 56 PatchOperation(px4_root, _data("nuttx_tracing_itm_v10.patch")), 57 ] 58 return PatchManager("Add tracing support to NuttX v10 via ITM", operations)
Adds scheduler and heap instrumentation to NuttX v10 via ITM.
60def nuttx_tracing_itm_v11(px4_root: Path) -> PatchManager: 61 """ 62 Adds scheduler and heap instrumentation to NuttX v11 via ITM. 63 """ 64 operations = _nuttx_tracing_itm(px4_root) + [ 65 PatchOperation(px4_root, _data("nuttx_tracing_itm_v11.patch")), 66 ] 67 return PatchManager("Add tracing support to NuttX v11 via ITM", operations)
Adds scheduler and heap instrumentation to NuttX v11 via ITM.
70def nuttx_tracing_itm_uart4(px4_root: Path) -> PatchManager: 71 """ 72 Trace data reception errors on UART4. 73 """ 74 operations = [ 75 PatchOperation(px4_root, _data("nuttx_tracing_itm_uart4.patch")), 76 ] 77 return PatchManager("Trace data transmit/receive errors on UART4", operations)
Trace data reception errors on UART4.
80def nuttx_sdmmc_reg_access(px4_root: Path) -> PatchManager: 81 """ 82 Un-inlines the `sdmmc_putreg32`, `sdmmc_getreg32`, and `sdmmc_modifyreg32` 83 functions, so that breakpoints can be set on them. 84 """ 85 operations = [ 86 PatchOperation(px4_root, _data("sdmmc_no_inline.patch")), 87 ] 88 return PatchManager("Un-inline SDMMC register access", operations)
Un-inlines the sdmmc_putreg32
, sdmmc_getreg32
, and sdmmc_modifyreg32
functions, so that breakpoints can be set on them.
91def malloc_return_null(px4_root: Path) -> PatchManager: 92 """ 93 Instruments the mm_malloc in NuttX to fail if call count equals global 94 `emdbg_malloc_count_null` variable, which is placed in `.noinit` section. 95 You can use this to find code that doesn't check the malloc return value for 96 NULL or see how the error handling performs. 97 """ 98 operations = [ 99 PatchOperation(px4_root, _data("malloc_return_null.patch")), 100 ] 101 return PatchManager("Make the n-th malloc call return NULL", operations)
Instruments the mm_malloc in NuttX to fail if call count equals global
emdbg_malloc_count_null
variable, which is placed in .noinit
section.
You can use this to find code that doesn't check the malloc return value for
NULL or see how the error handling performs.