|
| 1 | +@page page_bsp_contribution_guide_en BSP Contribution Guide |
| 2 | + |
| 3 | +# BSP Contribution Guide |
| 4 | + |
| 5 | +This document describes the directory hierarchy requirements for adding or |
| 6 | +updating BSPs, so board-level, chip-level, and architecture-level code stay in |
| 7 | +clear layers. |
| 8 | + |
| 9 | +## BSP Directory Hierarchy |
| 10 | + |
| 11 | +BSP directories usually fall into two hierarchy styles depending on where shared |
| 12 | +code is kept: vendor-level sharing, and vendor + series-level sharing. In either |
| 13 | +case, follow these principles: |
| 14 | + |
| 15 | +- `board/` contains board initialization, pin settings, clock settings, linker |
| 16 | + scripts, and other files that only belong to the current board. |
| 17 | +- The upper or sibling shared `libraries/` directory contains chip libraries, |
| 18 | + HAL, CMSIS, SDK, drivers, and driver adaptation code shared by BSPs from the |
| 19 | + same vendor or series. Driver directories should also be placed under |
| 20 | + `libraries/`. |
| 21 | +- The sibling `tools/` directory contains helper scripts shared by BSPs from the |
| 22 | + same vendor or series. |
| 23 | + |
| 24 | +If multiple BSPs share the same package or SDK, do not maintain duplicate copies |
| 25 | +under each BSP. Put the shared source in the common layer or use the package |
| 26 | +mechanism, then reference it from the BSP build scripts. When adding a BSP, do |
| 27 | +not create extra directory levels without a clear need, and do not place BSP |
| 28 | +code under non-BSP directories such as `components/`, `src/`, or `include/`. |
| 29 | +Abstract driver frameworks belong in `components/drivers/`, and shared chip or |
| 30 | +CPU architecture porting code belongs in `libcpu/`. |
| 31 | + |
| 32 | +### Vendor-Level Shared Layout (STM32 Example) |
| 33 | + |
| 34 | +STM32 BSPs are usually placed directly under `bsp/stm32/<board>`. Driver |
| 35 | +adaptation code, templates, tools, and package selections shared by STM32 BSPs |
| 36 | +are kept under `bsp/stm32/libraries/` and `bsp/stm32/tools/`: |
| 37 | + |
| 38 | +```text |
| 39 | +bsp/stm32/ |
| 40 | +├── libraries/ |
| 41 | +│ ├── HAL_Drivers/ # Driver adaptation shared by STM32 BSPs |
| 42 | +│ ├── drivers/ # Drivers shared by multiple STM32 BSPs, if any |
| 43 | +│ ├── templates/ # Reference templates for new BSPs |
| 44 | +│ └── Kconfig # Vendor HAL/CMSIS package selections |
| 45 | +├── tools/ # Vendor-level helper scripts |
| 46 | +├── stm32f407-atk-explorer/ |
| 47 | +│ ├── board/ # Board-only initialization, pins, clocks, linker scripts |
| 48 | +│ ├── Kconfig |
| 49 | +│ ├── SConscript |
| 50 | +│ └── SConstruct |
| 51 | +└── stm32f429-atk-apollo/ |
| 52 | + ├── board/ |
| 53 | + ├── Kconfig |
| 54 | + ├── SConscript |
| 55 | + └── SConstruct |
| 56 | +``` |
| 57 | + |
| 58 | +### Vendor + Series-Level Shared Layout (NXP Example) |
| 59 | + |
| 60 | +NXP-style BSPs are usually split first by vendor, product line, or chip series. |
| 61 | +Driver adaptation code, templates, tools, and package selections shared by a |
| 62 | +series are kept under that series directory. For example, i.MX RT uses |
| 63 | +`bsp/nxp/imx/imxrt/libraries/`, LPC55S uses |
| 64 | +`bsp/nxp/lpc/lpc55sxx/libraries/`, and MCX keeps separate `libraries/` |
| 65 | +directories under series such as `mcxa`, `mcxc`, `mcxe`, and `mcxn`. |
| 66 | + |
| 67 | +The NXP tree also contains historical BSP layouts, such as single-BSP LPC |
| 68 | +directories like `lpc176x`, and a few older directories named `Libraries/`. |
| 69 | +Do not extend those legacy layouts when adding or restructuring BSPs. If |
| 70 | +drivers, SDK code, or templates are reused by multiple BSPs, move or place them |
| 71 | +under the corresponding series-level `libraries/` and `tools/` layer. |
| 72 | + |
| 73 | +```text |
| 74 | +bsp/nxp/ |
| 75 | +├── imx/ |
| 76 | +│ └── imxrt/ |
| 77 | +│ ├── libraries/ |
| 78 | +│ │ ├── drivers/ # Drivers and driver adaptation shared by i.MX RT BSPs |
| 79 | +│ │ ├── templates/ # Reference templates for new BSPs |
| 80 | +│ │ └── Kconfig # NXP i.MX RT SDK package selections |
| 81 | +│ ├── tools/ # Helper scripts shared by this series |
| 82 | +│ └── imxrt1052-nxp-evk/ |
| 83 | +│ ├── board/ # Board-only initialization, pins, clocks, linker scripts |
| 84 | +│ ├── Kconfig |
| 85 | +│ ├── SConscript |
| 86 | +│ └── SConstruct |
| 87 | +├── lpc/ |
| 88 | +│ └── lpc55sxx/ |
| 89 | +│ ├── libraries/ # Driver adaptation, templates, and package selections shared by LPC55S BSPs |
| 90 | +│ ├── tools/ |
| 91 | +│ └── lpc55s69_nxp_evk/ |
| 92 | +│ ├── board/ |
| 93 | +│ ├── Kconfig |
| 94 | +│ ├── SConscript |
| 95 | +│ └── SConstruct |
| 96 | +└── mcx/ |
| 97 | + ├── tools/ # Helper tools shared by MCX series |
| 98 | + └── mcxn/ |
| 99 | + ├── libraries/ # CMSIS, series drivers, and package selections shared by MCXN BSPs |
| 100 | + └── frdm-mcxn947/ |
| 101 | + ├── board/ |
| 102 | + ├── Kconfig |
| 103 | + ├── SConscript |
| 104 | + └── SConstruct |
| 105 | +``` |
| 106 | + |
| 107 | +### Vendor HAL/SDK Packages |
| 108 | + |
| 109 | +If the vendor HAL, CMSIS, or SDK is already provided as an RT-Thread package, |
| 110 | +the BSP should not submit or maintain another full copy of the same source code. |
| 111 | +The BSP should select the corresponding `PKG_USING_*` package in `Kconfig` and |
| 112 | +reference package contents from `SConscript` according to the enabled |
| 113 | +configuration. `pkgs --update` is responsible for downloading package sources. |
| 114 | + |
| 115 | +In this case, `libraries/` mainly keeps driver adaptation code, reusable |
| 116 | +drivers, templates, helper scripts, and package selection logic. Do not commit |
| 117 | +package directories downloaded by `pkgs --update` as BSP source, and do not let |
| 118 | +`scons --dist` include packages or libraries that are not enabled by the current |
| 119 | +BSP. |
| 120 | + |
| 121 | +## Submission Requirements |
| 122 | + |
| 123 | +- Keep the BSP hierarchy clear and only submit board-level files required by the |
| 124 | + current board. |
| 125 | +- Libraries, driver adaptation code, reusable drivers, templates, and scripts |
| 126 | + shared by BSPs from the same vendor or series should be placed in the shared |
| 127 | + `libraries/` or `tools/` layer to avoid duplicate copies across BSPs. |
| 128 | +- Driver adaptation code and reusable drivers should be placed under |
| 129 | + `libraries/`, not under a single board directory. |
| 130 | +- If the vendor HAL, CMSIS, or SDK has been packaged, prefer the package |
| 131 | + mechanism and do not submit duplicate package source code under the BSP. |
| 132 | +- Build scripts should reference common code from the shared layer, and |
| 133 | + `scons --dist` should not include packages or libraries that are not required |
| 134 | + by the current BSP. |
0 commit comments