Blog Detail
  • Downloads
  • Development
  • Docs
  • Learning
  • Support
  • Community
  • What's New
Repositories
Repositories
AI-Powered R&D: Rapid NCSI Protocol Command Parsing in openUBMC

AI-Powered R&D: Rapid NCSI Protocol Command Parsing in openUBMC

技术干货

2025/08/07
钱昱霏

AI-Powered R&D: Rapid NCSI Protocol Command Parsing in openUBMC

Background: Repetitive Work in Protocol Command Development

NCSI (Network Controller Sideband Interface) is a critical protocol enabling communications between the baseboard management controller (BMC) and the network controller. During the development of the openUBMC 25.06 version, I encountered several bottlenecks:

  • High code duplication: Except for the request/response payload structure, the code logic for different NCSI commands was nearly identical, leading to extensive boilerplate.
  • Manual generation of test data: Binary test data had to be calculated and written manually. This process was complex and highly prone to error.
  • Dense and vague documentation: The NCSI protocol specification is English-only and technically dense, requiring significant effort to read and often leading to misinterpretation of certain sections.

To ensure a high-quality delivery, I turned to the cutting-edge capabilities of AI-assisted coding, hoping to harness the power of LLMs to streamline this development work.

Pattern Analysis: Identifying the "Automatable" Core

Blindly relying on AI to write code independently can be counterproductive, as current AI tools cannot fully replace human expertise. The first step was to analyze the code structure and functional modules to identify areas where the AI could be most effective.

1. Protocol Documentation Understanding and Command Extraction

Modern LLMs excel at natural language understanding, especially with English documentation. This strength was used to extract the request and response packet formats for each NCSI command directly from the protocol specification.

images

2. Writing Command Handler Functions

To guide the LLM and prevent unnecessary deviation, I pre-defined the function signatures for the protocol request and response handlers. Existing openUBMC code was provided as context to ensure the generated code adhered to the community's coding style.

BMC-specific requirements, such as logging operational history, were also provided as templates, instructing the LLM to include operation log recording in all setter-type command functions.

3. Generating Test Cases for Protocol Compliance

To guarantee the quality of the generated code, openUBMC's Unit Test (UT) framework was used for rapid verification. Crucially, the test code itself was also generated using the LLM.

Leveraging the LLM's understanding of the NCSI binary protocol, it could quickly derive the necessary test data, eliminating the tedious, error-prone process of manually crafting binary packets.

Coding in Practice: Practical Prompt Templates

I utilized a combination of GPT-4.1 and Cursor for the toolset. Through iterative practice, I summarized a set of high-efficiency prompt templates, which are shared below.

Key Results:

  • 80+ functions and corresponding test cases generated automatically, with the accuracy exceeding 90% and the UT coverage above 86%.
  • Overall development efficiency increased by 65%, saving an estimated 30+ person-days.
  • Code style was consistent with community standards, leading to a smooth review by the SIG Committer.

Knowledge Background Setup

Thanks to Cursor's powerful context awareness, existing code files in the repository were automatically included in the LLM's analysis (for example, Lua syntax and style). However, the NCSI protocol document was external.

Crucially, Cursor supports integrating the full protocol document as a knowledge base. I imported the public NCSI specification into Cursor, providing the AI with a solid theoretical foundation for the command parsing work.

images

Template Breakdown

I broke the task into three steps, using an iterative generation and Q&A approach to further boost code accuracy, and wrote corresponding prompts:

  1. Generate NCSI command response and parsing functions.
  2. Generate corresponding UT functions and test data for the created functions.
  3. Optimize all newly added code.

Prompt Example 1: Generating New Functions

Based on the existing code pattern below, generate the corresponding function for the new NCSI command [COMMAND_NAME]:
Reference Header File Definitions:
Command type macros: Refer to command constants in header files under test-main/ncsi path.
Packet structure definitions: Refer to request/response structs in the header file.
Length macros: Refer to *_REQ_LEN, *_RSP_LEN, *_PAD_LEN, etc. in the header file.

Existing Pattern:
function ncsi_cmd.ncsi_enable_channel(package_id, channel_id, eth_name)

Requirements:
1. Function name must be ncsi_[COMMAND_NAME].
2. Parameters must be package_id, channel_id, eth_name.
3. Must include the same parameter validation logic.
4. Must call the corresponding module function.
5. Must return the same error codes.

Please generate the complete function code.

images

Prompt Example 2: Generating Test Cases

Based on the testing pattern below, generate a complete test case file for the [MODULE_NAME] module:

Existing Testing Pattern:
function TestNCSIBroadcastFilter:test_enable_broadcast_filter()

Requirements:
1. Create a test class TestNCSI[MODULE_NAME] for [MODULE_NAME].
2. Include setUp and tearDown methods.
3. Generate a test case for every public function.
4. Include both success and failure scenario tests.
5. Validate the request packet format.
6. Include boundary condition tests.

Please generate the complete test file.

images

Prompt Example 3: Code Optimization

Code Optimization Suggestions

Analyze the code under the src/lualib/ncsi/ncsi_protocol/ directory.
Identify repetitive patterns that can be further optimized.

Currently optimized patterns:
1. Using the handle_channel_operation generic function.
2. Using ncsi_utils.create_custom_cmd_table.
3. Using the command table pattern.

Analyze what other repetitive code can be further optimized and provide specific optimization plans and code implementations.

images

Conclusion and Outlook

While the dream of "one-click complete code generation" isn't fully realized yet, the practical value of LLMs in R&D assistance is exceptionally high. This new development paradigm is poised to disrupt traditional workflows, bringing a revolutionary experience to the BMC and firmware fields.

I look forward to seeing more AI-assisted coding practices within the openUBMC community to spark further innovation. Developers are welcome to share their experiences and insights as we collectively explore the boundless possibilities of AI-assisted coding!

Welcome to follow us!

openUBMC official website: https://www.openubmc.cn

Code repository: https://gitcode.com/openUBMC/network_adapter

【版权声明】Copyright © 2026 openUBMC Community。本文由openUBMC社区首发,欢迎遵照CC-BY-SA 4.0协议规定转载。转载时敬请在正文注明并保留原文链接和作者信息。

【免责声明】本文仅代表作者本人观点,与本网站无关。本网站对文中陈述、观点判断保持中立,不对所包含内容的准确性、可靠性或完整性提供任何明示或暗示的保证。本文仅供读者参考,由此产生的所有法律责任均由读者本人承担。

关于作者

钱昱霏

BMC developer, specializing in software development and improving automation efficiency, with unique insights into AI-assisted R&D.