# How to Add a New Configuration File (New Board)

Before starting, download the K230 SDK. Refer to [How to Build Firmware](../userguide/how_to_build.md) for the download path.

The following walkthrough uses the 01Studio board as an example and explains how to add a new configuration based on the board's hardware. The directories involved in the changes are listed below; each step corresponds to modifications in the relevant directory.

| Module | Source path | Description |
| ----------- | ---------------------------------------------- | ---------------------------------------------------------------------------------------- |
| Global | `./boards/Kconfig` | Global configuration file managing the overall system configuration |
| Global | `./boards/` | Board packaging files containing board-related resources and configurations |
| Global | `./config/` | Per-board defconfig files |
| canmv | `./src/canmv/port/boards` | Board configuration for CanMV software adaptation |
| boot | `./src/uboot/uboot/arch/riscv` | Directory for adding board information in U-Boot |
| boot | `./src/uboot/uboot/board/kendryte` | U-Boot configuration files |
| boot | `./src/uboot/uboot/arch/riscv/dts` | Board hardware configuration (power, GPIO, etc.) |
| boot | `./src/uboot/uboot/config` | U-Boot menuconfig configuration |
| rtsmart | `./src/rtsmart/rtsmart/kernel/bsp/maix3/configs` | RT-Smart menuconfig configuration |

## Step 1: Edit the Kconfig File to Add the Board Definition

In `./boards/Kconfig`, add a new configuration entry:

```c
        config BOARD_K230_CANMV_LCKFB
            bool "K230 CanMV LCKFB, Onboard 1GiB LPDDR4"

      + config BOARD_K230_CANMV_01STUDIO
      +     bool "K230 CanMV 01 Studio, Onboard 1GiB LPDDR4"

        config BOARD_K230D_CANMV_BPI_ZERO
            bool "K230D CanMV BPI-Zero, SiP 128MiB LPDDR4"
```

```c
    default "k230_canmv_lckfb" if BOARD_K230_CANMV_LCKFB
  + default "k230_canmv_01studio" if BOARD_K230_CANMV_01STUDIO
    default "k230d_canmv_bpi_zero" if BOARD_K230D_CANMV_BPI_ZERO
```

```c
config BOARD_NAME
        string "Board Generate Image Name"
        default "CanMV_K230_V1P0_P1" if BOARD_K230_CANMV
        default "CanMV_K230_V3P0" if BOARD_K230_CANMV_V3P0
        default "CanMV_K230_LCKFB" if BOARD_K230_CANMV_LCKFB
      + default "CanMV_K230_01Studio" if BOARD_K230_CANMV_01STUDIO
        default "CanMV_K230D_Zero" if BOARD_K230D_CANMV_BPI_ZERO
```

```c
    source "$(SDK_BOARDS_DIR)/k230_canmv_lckfb/Kconfig"
  + source "$(SDK_BOARDS_DIR)/k230_canmv_01studio/Kconfig"
    source "$(SDK_BOARDS_DIR)/k230d_canmv_bpi_zero/Kconfig"
```

## Step 2: Add a New Board Directory Under `boards/`

The new directory path must match the path defined in the `source` line above:

```shell
cp ./k230_canmv_dongshanpi ./k230_canmv_01studio -rf
cd k230_canmv_01studio && ls
# Kconfig  default.env  genimage-sdcard-kdimg.cfg  genimage-sdcard-rtos.cfg  genimage-sdcard.cfg
```

This directory contains five files:

| File | Description |
| --- | --- |
| `Kconfig` | Required by `make menuconfig`; defines board-specific options |
| `default.env` | Defines U-Boot boot parameters |
| `genimage-sdcard-kdimg.cfg` | Sectioned packaging file for kdimg format |
| `genimage-sdcard-rtos.cfg` | RT-Smart packaging file |
| `genimage-sdcard.cfg` | MicroPython packaging file |

Edit the new `Kconfig` file. The `BOARD` symbol must match what was defined in Step 1:

```makefile
if BOARD_K230_CANMV_01STUDIO

endif
```

## Step 3: Add a defconfig File Under `configs/`

Copy an existing defconfig and rename it:

```shell
cp k230_canmv_dongshanpi_defconfig k230_canmv_01studio_defconfig
```

Then edit the new file, checking that all options match your hardware requirements:

```makefile
# Change CONFIG_BOARD_K230_CANMV_DONGSHANPAI to CONFIG_BOARD_K230_CANMV_01STUDIO
CONFIG_BOARD_K230_CANMV_01STUDIO=y
# Update CONFIG_BOARD_CONFIG_NAME
CONFIG_BOARD_CONFIG_NAME="k230_canmv_01studio_defconfig"
CONFIG_MPP_DEFAULT_SENSOR_CSI_2=y
```

## Step 4: Add Board Configuration Under `./src/canmv/port/boards/`

```shell
cp -rf ./k230_canmv_dongshanpi/ ./k230_canmv_01studio
cd k230_canmv_01studio && ls
# manifest.py  mpconfigboard.h
```

| File | Description |
| --- | --- |
| `manifest.py` | MicroPython configuration file |
| `mpconfigboard.h` | MicroPython board header |

Edit `mpconfigboard.h`:

```cpp
// Select K230 or K230D based on the chip in use
#define MICROPY_HW_MCU_NAME                 "K230"
#define OMV_ARCH_STR                        ""
// Update OMV_BOARD_TYPE
#define OMV_BOARD_TYPE                      "CanMV K230 01Studio - %d%c"
```

## Step 5: Edit the Kconfig File Under `./src/uboot/uboot/arch/riscv/`

```cpp
+ config TARGET_K230_CANMV_01STUDIO
+ bool "Support k230_CANMV(01STUDIO)"
+ select SYS_CACHE_SHIFT_6

  source "board/kendryte/k230_canmv/Kconfig"
+ source "board/kendryte/k230_canmv_01studio/Kconfig"
  source "board/kendryte/k230d_canmv_bpi_zero/Kconfig"
```

## Step 6: Add a New Board Directory Under `./src/uboot/uboot/board/kendryte/`

The directory and file names must match the `source` path from Step 5, and internal files should be renamed to `01studio`:

```shell
cp -rf ./k230_canmv_dongshanpi ./k230_canmv_01studio
cd k230_canmv_01studio
mv canmv_dongshanpi_lpddr3_init_2133.c canmv_01studio_lpddr3_init_2133.c
# (rename all other lpddr files similarly)
ls
# Kconfig  Makefile  board.c  canmv_01studio_lpddr*.c
```

| File | Description |
| --- | --- |
| `Makefile` | Compilation rules; update for new file names |
| `Kconfig` | Board-specific Kconfig |
| `board.c` | Power and GPIO pin settings; update for actual hardware |
| `canmv_01studio_lpddr*.c` | DDR initialization; reuse reference board values |

Edit `Kconfig`:

```text
+  if TARGET_K230_CANMV_01STUDIO

  config SYS_CPU
    default "k230"

  config SYS_VENDOR
    default "kendryte"

  config SYS_BOARD
+        default "k230_canmv_01studio"

  config SYS_CONFIG_NAME
+        default "k230_common"

  config BOARD_SPECIFIC_OPTIONS
    def_bool y
    select KENDRYTE_K230

  choice
    prompt "DDR Type And Frequency"
+        default CANMV_01STUDIO_LPDDR4_2667

+        config CANMV_01STUDIO_LPDDR3_2133
      bool "LPDDR3@2133"
+        config CANMV_01STUDIO_LPDDR3_1600
      bool "LPDDR3@1600"
+        config CANMV_01STUDIO_LPDDR3_800
      bool "LPDDR3@800"
+        config CANMV_01STUDIO_LPDDR4_2667
      bool "LPDDR4@2667"
+        config CANMV_01STUDIO_LPDDR4_3200
      bool "LPDDR4@3200"
  endchoice

endif
```

## Step 7: Set Hardware Configuration in `./src/uboot/uboot/arch/riscv/dts/`

```shell
cp k230_canmv_dongshanpi.dts k230_canmv_01studio.dts
```

Canaan provides an automated configuration tool: [IOMAX Generation Tool](https://www.kendryte.com/zh/tools/dts_config_generation_tool).

## Step 8: Add a U-Boot defconfig Under `./src/uboot/uboot/configs/`

```shell
cp k230_canmv_dongshanpi_defconfig k230_canmv_01studio_defconfig
```

Then modify:

- Change `CONFIG_DEFAULT_DEVICE_TREE` to `"k230_canmv_01studio"`
- Replace `CONFIG_TARGET_K230_CANMV_DONGSHANPAI` with `CONFIG_K230_CANMV_01STUDIO`

## Step 9: Add an RT-Smart menuconfig File Under `./src/rtsmart/rtsmart/kernel/bsp/maix3/configs/`

```shell
cp k230_canmv_dongshanpi_defconfig k230_canmv_01studio_defconfig
```

Adjust the config file to match your hardware.

## Build and Run

After completing all steps, build the firmware:

```shell
make list-def
# Available configs:
# [ ] k230_canmv_01studio_defconfig
# ...

make k230_canmv_01studio_defconfig
make
# Wait for the .img file to be generated

cd output/k230_canmv_01studio_defconfig/
ls
# CanMV_K230_01Studio_micropython_local_nncase_v2.9.0.img  ...
```

Copy the generated `*.img` file and flash it to the device.
