[{"data":1,"prerenderedAt":768},["ShallowReactive",2],{"\u002Fzh\u002Fblogs\u002F202508072":3,"content-doc-\u002Fen\u002Fblogs\u002F202508072":422,"surround-\u002Fen\u002Fblogs\u002F202508072":766},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":11,"author":12,"body":16,"_type":414,"_id":415,"_source":416,"_file":417,"_stem":418,"_extension":419,"coverImage":133,"plainText":420,"authorNames":421},"\u002Fzh\u002Fblogs\u002F202508072","blogs",false,"","利用大模型AI辅助研发快速实现openUBMC的NCSI协议命令字解析","NCSI是一种用于 BMC 与网络控制器通信的协议。在openUBMC 25.06版本项目开发过程中，我面临着以下几方面的挑战：","2025\u002F08\u002F07","essentials",[13],{"name":14,"description":15},"钱昱霏","进入BMC领域4个月的BMC开发者，专注于软件开发与自动化效率提升，在AI辅助研发有独特的见解。",{"type":17,"children":18,"toc":395},"root",[19,27,34,49,95,100,106,111,121,126,135,144,149,154,163,168,173,179,184,192,210,218,223,228,235,243,248,253,258,263,268,274,284,291,297,305,312,318,326,333,339,344,351,356,361,366,371,384],{"type":20,"tag":21,"props":22,"children":24},"element","h1",{"id":23},"利用大模型ai辅助研发快速实现openubmc的ncsi协议命令字解析",[25],{"type":26,"value":8},"text",{"type":20,"tag":28,"props":29,"children":31},"h2",{"id":30},"背景协议命令字开发遭遇重复劳动难题",[32],{"type":26,"value":33},"背景：协议命令字开发遭遇重复劳动难题",{"type":20,"tag":35,"props":36,"children":37},"p",{},[38,40,47],{"type":26,"value":39},"NCSI",{"type":20,"tag":41,"props":42,"children":44},"font",{"color":43},"#b0b0b0",[45],{"type":26,"value":46},"（Network Controller Sideband Interface，网络控制器边带接口）",{"type":26,"value":48},"是一种用于 BMC 与网络控制器通信的协议。在openUBMC 25.06版本项目开发过程中，我面临着以下几方面的挑战：",{"type":20,"tag":50,"props":51,"children":52},"ul",{},[53,69,82],{"type":20,"tag":54,"props":55,"children":56},"li",{},[57,63,67],{"type":20,"tag":58,"props":59,"children":60},"strong",{},[61],{"type":26,"value":62},"模块代码重复率高：",{"type":20,"tag":64,"props":65,"children":66},"br",{},[],{"type":26,"value":68},"不同命令之间，除了命令字的请求响应体存在差异外，其他代码的重复度极高。",{"type":20,"tag":54,"props":70,"children":71},{},[72,77,80],{"type":20,"tag":58,"props":73,"children":74},{},[75],{"type":26,"value":76},"测试数据需手动编写：",{"type":20,"tag":64,"props":78,"children":79},{},[],{"type":26,"value":81},"需要自己手动计算二进制测试数据，过程复杂且极易出错。",{"type":20,"tag":54,"props":83,"children":84},{},[85,90,93],{"type":20,"tag":58,"props":86,"children":87},{},[88],{"type":26,"value":89},"文档晦涩难懂：",{"type":20,"tag":64,"props":91,"children":92},{},[],{"type":26,"value":94},"NCSI 协议文档仅有英文版本，阅读需耗费大量精力，且容易对部分章节产生误解。",{"type":20,"tag":35,"props":96,"children":97},{},[98],{"type":26,"value":99},"为保证高质量交付，我将目光投向了当下热门的 AI 辅助编码能力，期望借助大模型的力量辅助完成这项开发工作。",{"type":20,"tag":28,"props":101,"children":103},{"id":102},"重复模式分析抓住可自动化的核心",[104],{"type":26,"value":105},"重复模式分析：抓住“可自动化”的核心",{"type":20,"tag":35,"props":107,"children":108},{},[109],{"type":26,"value":110},"当前 AI 辅助编码能力尚未能完全替代人工手写，盲目让 AI 独立编写代码只会适得其反。因此，首要任务是对代码结构与功能模块进行分析，识别出适合 AI 发挥作用的场景。",{"type":20,"tag":112,"props":113,"children":115},"h3",{"id":114},"_1-协议文档理解和命令字提取",[116],{"type":20,"tag":58,"props":117,"children":118},{},[119],{"type":26,"value":120},"1. 协议文档理解和命令字提取",{"type":20,"tag":35,"props":122,"children":123},{},[124],{"type":26,"value":125},"经过多年迭代优化，当前大模型对自然语言的理解效率极高，尤其在英文文档理解方面表现突出，因此可通过大模型提取 NCSI 命令字的请求体和响应体封装格式。",{"type":20,"tag":35,"props":127,"children":128},{},[129],{"type":20,"tag":130,"props":131,"children":134},"img",{"alt":132,"src":133},"images","\u002Fcategory\u002Fblog\u002F20250807\u002Fimg07.webp",[],{"type":20,"tag":112,"props":136,"children":138},{"id":137},"_2-编写命令处理函数",[139],{"type":20,"tag":58,"props":140,"children":141},{},[142],{"type":26,"value":143},"2. 编写命令处理函数",{"type":20,"tag":35,"props":145,"children":146},{},[147],{"type":26,"value":148},"为避免大模型自由发挥，预设协议请求和响应体函数格式能更有效地引导其生成所需代码。同时，为与 openUBMC 社区编码风格保持一致，可将已有代码作为上下文传递给大模型作为参考。",{"type":20,"tag":35,"props":150,"children":151},{},[152],{"type":26,"value":153},"对于操作日志记录等 BMC 专有的要求，也可通过模板提供给大模型，要求其在所有设置类命令字函数中添加操作日志记录。",{"type":20,"tag":112,"props":155,"children":157},{"id":156},"_3-编写测试用例保证生成代码符合协议要求",[158],{"type":20,"tag":58,"props":159,"children":160},{},[161],{"type":26,"value":162},"3. 编写测试用例，保证生成代码符合协议要求",{"type":20,"tag":35,"props":164,"children":165},{},[166],{"type":26,"value":167},"为了保证生成代码的质量，利用openUBMC社区UT框架可以快速验证生成代码是否正确。同样，测试代码也可以利用大模型生成。",{"type":20,"tag":35,"props":169,"children":170},{},[171],{"type":26,"value":172},"由于 NCSI 通讯采用二进制格式，利用大模型对协议的理解能力，可快速推导所需测试数据，省去手动编写二进制数据的繁琐过程。",{"type":20,"tag":28,"props":174,"children":176},{"id":175},"编码实战prompt模板实用技巧",[177],{"type":26,"value":178},"编码实战：Prompt模板实用技巧",{"type":20,"tag":35,"props":180,"children":181},{},[182],{"type":26,"value":183},"在工具选型上，采用 GPT-4.1 与 Cursor 组合。经过多轮实践，总结出一套高效 Prompt 模板，现分享如下。",{"type":20,"tag":35,"props":185,"children":186},{},[187],{"type":20,"tag":58,"props":188,"children":189},{},[190],{"type":26,"value":191},"实战成果：",{"type":20,"tag":50,"props":193,"children":194},{},[195,200,205],{"type":20,"tag":54,"props":196,"children":197},{},[198],{"type":26,"value":199},"自动生成80+个函数与测试用例，准确率超90%，UT覆盖率达86%以上。",{"type":20,"tag":54,"props":201,"children":202},{},[203],{"type":26,"value":204},"整体开发效率提升65%，累计节省30+人天。",{"type":20,"tag":54,"props":206,"children":207},{},[208],{"type":26,"value":209},"代码风格与社区通用规范一致，顺利通过 SIG Committer 审核。",{"type":20,"tag":35,"props":211,"children":212},{},[213],{"type":20,"tag":58,"props":214,"children":215},{},[216],{"type":26,"value":217},"知识背景设置：",{"type":20,"tag":35,"props":219,"children":220},{},[221],{"type":26,"value":222},"得益于 Cursor 强大的上下文感知机制，同一仓库内的代码文件会被自动纳入大模型的分析范围，开发者无需额外配置 Lua 语法和编码风格。不过，由于 NCSI 协议文档不属于仓库内置文件，需单独处理。",{"type":20,"tag":35,"props":224,"children":225},{},[226],{"type":26,"value":227},"值得一提的是，Cursor 支持将完整协议文档作为知识库集成到上下文环境中。笔者已将公开的 NCSI 协议文档导入 Cursor，为后续命令字解析工作提供了坚实的理论依据。",{"type":20,"tag":35,"props":229,"children":230},{},[231],{"type":20,"tag":130,"props":232,"children":234},{"alt":132,"src":233},"\u002Fcategory\u002Fblog\u002F20250807\u002Fimg08.webp",[],{"type":20,"tag":35,"props":236,"children":237},{},[238],{"type":20,"tag":58,"props":239,"children":240},{},[241],{"type":26,"value":242},"模板编写：",{"type":20,"tag":35,"props":244,"children":245},{},[246],{"type":26,"value":247},"将任务拆解为多步骤，通过迭代式生成与问答交互，可进一步提升代码生成准确性。",{"type":20,"tag":35,"props":249,"children":250},{},[251],{"type":26,"value":252},"我将任务分成三步，并编写了对应的Prompt：",{"type":20,"tag":35,"props":254,"children":255},{},[256],{"type":26,"value":257},"1.生成NCSI命令字的响应和解析函数。",{"type":20,"tag":35,"props":259,"children":260},{},[261],{"type":26,"value":262},"2.针对生成的函数，生成对应的UT函数和测试数据。",{"type":20,"tag":35,"props":264,"children":265},{},[266],{"type":26,"value":267},"3.优化所有新增代码。",{"type":20,"tag":112,"props":269,"children":271},{"id":270},"prompt示例1生成新函数",[272],{"type":26,"value":273},"Prompt示例1：生成新函数",{"type":20,"tag":275,"props":276,"children":278},"pre",{"code":277},"请基于以下现有代码模式，为新的NCSI命令 [COMMAND_NAME] 生成相应的函数：\n参考的头文件定义：\n命令类型宏定义：参考 test-main\u002Fncsi 路径下头文件中的命令常量\n包结构定义：参考头文件中的请求\u002F响应结构体定义\n长度宏定义：参考头文件中的 *_REQ_LEN、*_RSP_LEN、*_PAD_LEN 等宏\n现有模式：\nfunction ncsi_cmd.ncsi_enable_channel(package_id, channel_id, eth_name)\n要求：\n1. 函数名为 ncsi_[COMMAND_NAME]\n2. 参数为 package_id, channel_id, eth_name\n3. 包含相同的参数验证逻辑\n4. 调用对应的模块函数\n5. 返回相同的错误码\n请生成完整的函数代码。\n",[279],{"type":20,"tag":280,"props":281,"children":282},"code",{"__ignoreMap":7},[283],{"type":26,"value":277},{"type":20,"tag":35,"props":285,"children":286},{},[287],{"type":20,"tag":130,"props":288,"children":290},{"alt":132,"src":289},"\u002Fcategory\u002Fblog\u002F20250807\u002Fimg09.webp",[],{"type":20,"tag":112,"props":292,"children":294},{"id":293},"prompt示例2-测试用例生成",[295],{"type":26,"value":296},"Prompt示例2: 测试用例生成",{"type":20,"tag":275,"props":298,"children":300},{"code":299},"请基于以下测试模式，为 [MODULE_NAME] 模块生成完整的测试用例：\n现有测试模式：\nfunction TestNCSIBroadcastFilter:test_enable_broadcast_filter()\n要求：\n1. 为 [MODULE_NAME] 创建测试类 TestNCSI[MODULE_NAME]\n2. 包含 setUp 和 tearDown 方法\n3. 为每个公共函数生成测试用例\n4. 包含成功和失败场景测试\n5. 验证请求报文格式\n6. 包含边界条件测试\n请生成完整的测试文件。\n",[301],{"type":20,"tag":280,"props":302,"children":303},{"__ignoreMap":7},[304],{"type":26,"value":299},{"type":20,"tag":35,"props":306,"children":307},{},[308],{"type":20,"tag":130,"props":309,"children":311},{"alt":132,"src":310},"\u002Fcategory\u002Fblog\u002F20250807\u002Fimg10.webp",[],{"type":20,"tag":112,"props":313,"children":315},{"id":314},"prompt示例3-代码优化",[316],{"type":26,"value":317},"Prompt示例3: 代码优化",{"type":20,"tag":275,"props":319,"children":321},{"code":320},"代码优化建议\n分析 src\u002Flualib\u002Fncsi\u002Fncsi_protocol\u002F 目录下的代码，\n识别可以进一步优化的重复模式。\n\n当前已优化的模式：\n1. 使用 handle_channel_operation 通用函数\n2. 使用 ncsi_utils.create_custom_cmd_table\n3. 使用命令表模式\n\n请分析还有哪些重复代码可以进一步优化，\n并提供具体的优化方案和代码实现。\n",[322],{"type":20,"tag":280,"props":323,"children":324},{"__ignoreMap":7},[325],{"type":26,"value":320},{"type":20,"tag":35,"props":327,"children":328},{},[329],{"type":20,"tag":130,"props":330,"children":332},{"alt":132,"src":331},"\u002Fcategory\u002Fblog\u002F20250807\u002Fimg11.webp",[],{"type":20,"tag":28,"props":334,"children":336},{"id":335},"高效-prompt-编写技巧总结",[337],{"type":26,"value":338},"高效 Prompt 编写技巧总结",{"type":20,"tag":35,"props":340,"children":341},{},[342],{"type":26,"value":343},"最后，给大家分享一些我自己总结的有效Prompt编写技巧：",{"type":20,"tag":35,"props":345,"children":346},{},[347],{"type":20,"tag":130,"props":348,"children":350},{"alt":132,"src":349},"\u002Fcategory\u002Fblog\u002F20250807\u002Fimg12.webp",[],{"type":20,"tag":28,"props":352,"children":354},{"id":353},"总结",[355],{"type":26,"value":353},{"type":20,"tag":35,"props":357,"children":358},{},[359],{"type":26,"value":360},"尽管目前无法实现 “一键生成完整代码”，但大模型在研发辅助中仍具较高实用价值。这种新型开发模式有望颠覆传统开发流程，为 BMC、固件领域带来革新性体验。",{"type":20,"tag":35,"props":362,"children":363},{},[364],{"type":26,"value":365},"期待在 openUBMC 社区看到更多 AI 辅助编码实践，激发更多创新思路。欢迎开发者分享经验、交流见解，共同探索 AI 辅助编码的无限可能。",{"type":20,"tag":28,"props":367,"children":369},{"id":368},"欢迎关注我们",[370],{"type":26,"value":368},{"type":20,"tag":35,"props":372,"children":373},{},[374,376],{"type":26,"value":375},"社区官网：",{"type":20,"tag":377,"props":378,"children":382},"a",{"href":379,"rel":380},"https:\u002F\u002Fwww.openubmc.cn",[381],"nofollow",[383],{"type":26,"value":379},{"type":20,"tag":35,"props":385,"children":386},{},[387,389],{"type":26,"value":388},"代码仓地址：",{"type":20,"tag":377,"props":390,"children":393},{"href":391,"rel":392},"https:\u002F\u002Fgitcode.com\u002FopenUBMC\u002Fnetwork_adapter",[381],[394],{"type":26,"value":391},{"title":7,"searchDepth":396,"depth":396,"links":397},4,[398,400,406,411,412,413],{"id":30,"depth":399,"text":33},2,{"id":102,"depth":399,"text":105,"children":401},[402,404,405],{"id":114,"depth":403,"text":120},3,{"id":137,"depth":403,"text":143},{"id":156,"depth":403,"text":162},{"id":175,"depth":399,"text":178,"children":407},[408,409,410],{"id":270,"depth":403,"text":273},{"id":293,"depth":403,"text":296},{"id":314,"depth":403,"text":317},{"id":335,"depth":399,"text":338},{"id":353,"depth":399,"text":353},{"id":368,"depth":399,"text":368},"markdown","content:zh:blogs:202508072.md","content","zh\u002Fblogs\u002F202508072.md","zh\u002Fblogs\u002F202508072","md","利用大模型AI辅助研发快速实现openUBMC的NCSI协议命令字解析 背景：协议命令字开发遭遇重复劳动难题 NCSI （Network Controller Sideband Interface，网络控制器边带接口） 是一种用于 BMC 与网络控制器通信的协议。在openUBMC 25.06版本项目开发过程中，我面临着以下几方面的挑战： 模块代码重复率高：  不同命令之间，除了命令字的请求响应体存在差异外，其他代码的重复度极高。 测试数据需手动编写：  需要自己手动计算二进制测试数据，过程复杂且极易出错。 文档晦涩难懂：  NCSI 协议文档仅有英文版本，阅读需耗费大量精力，且容易对部分章节产生误解。 为保证高质量交付，我将目光投向了当下热门的 AI 辅助编码能力，期望借助大模型的力量辅助完成这项开发工作。 重复模式分析：抓住“可自动化”的核心 当前 AI 辅助编码能力尚未能完全替代人工手写，盲目让 AI 独立编写代码只会适得其反。因此，首要任务是对代码结构与功能模块进行分析，识别出适合 AI 发挥作用的场景。 1. 协议文档理解和命令字提取 经过多年迭代优化，当前大模型对自然语言的理解效率极高，尤其在英文文档理解方面表现突出，因此可通过大模型提取 NCSI 命令字的请求体和响应体封装格式。  2. 编写命令处理函数 为避免大模型自由发挥，预设协议请求和响应体函数格式能更有效地引导其生成所需代码。同时，为与 openUBMC 社区编码风格保持一致，可将已有代码作为上下文传递给大模型作为参考。 对于操作日志记录等 BMC 专有的要求，也可通过模板提供给大模型，要求其在所有设置类命令字函数中添加操作日志记录。 3. 编写测试用例，保证生成代码符合协议要求 为了保证生成代码的质量，利用openUBMC社区UT框架可以快速验证生成代码是否正确。同样，测试代码也可以利用大模型生成。 由于 NCSI 通讯采用二进制格式，利用大模型对协议的理解能力，可快速推导所需测试数据，省去手动编写二进制数据的繁琐过程。 编码实战：Prompt模板实用技巧 在工具选型上，采用 GPT-4.1 与 Cursor 组合。经过多轮实践，总结出一套高效 Prompt 模板，现分享如下。 实战成果： 自动生成80+个函数与测试用例，准确率超90%，UT覆盖率达86%以上。 整体开发效率提升65%，累计节省30+人天。 代码风格与社区通用规范一致，顺利通过 SIG Committer 审核。 知识背景设置： 得益于 Cursor 强大的上下文感知机制，同一仓库内的代码文件会被自动纳入大模型的分析范围，开发者无需额外配置 Lua 语法和编码风格。不过，由于 NCSI 协议文档不属于仓库内置文件，需单独处理。 值得一提的是，Cursor 支持将完整协议文档作为知识库集成到上下文环境中。笔者已将公开的 NCSI 协议文档导入 Cursor，为后续命令字解析工作提供了坚实的理论依据。  模板编写： 将任务拆解为多步骤，通过迭代式生成与问答交互，可进一步提升代码生成准确性。 我将任务分成三步，并编写了对应的Prompt： 1.生成NCSI命令字的响应和解析函数。 2.针对生成的函数，生成对应的UT函数和测试数据。 3.优化所有新增代码。 Prompt示例1：生成新函数 请基于以下现有代码模式，为新的NCSI命令 [COMMAND_NAME] 生成相应的函数：\n参考的头文件定义：\n命令类型宏定义：参考 test-main\u002Fncsi 路径下头文件中的命令常量\n包结构定义：参考头文件中的请求\u002F响应结构体定义\n长度宏定义：参考头文件中的 *_REQ_LEN、*_RSP_LEN、*_PAD_LEN 等宏\n现有模式：\nfunction ncsi_cmd.ncsi_enable_channel(package_id, channel_id, eth_name)\n要求：\n1. 函数名为 ncsi_[COMMAND_NAME]\n2. 参数为 package_id, channel_id, eth_name\n3. 包含相同的参数验证逻辑\n4. 调用对应的模块函数\n5. 返回相同的错误码\n请生成完整的函数代码。\n  Prompt示例2: 测试用例生成 请基于以下测试模式，为 [MODULE_NAME] 模块生成完整的测试用例：\n现有测试模式：\nfunction TestNCSIBroadcastFilter:test_enable_broadcast_filter()\n要求：\n1. 为 [MODULE_NAME] 创建测试类 TestNCSI[MODULE_NAME]\n2. 包含 setUp 和 tearDown 方法\n3. 为每个公共函数生成测试用例\n4. 包含成功和失败场景测试\n5. 验证请求报文格式\n6. 包含边界条件测试\n请生成完整的测试文件。\n  Prompt示例3: 代码优化 代码优化建议\n分析 src\u002Flualib\u002Fncsi\u002Fncsi_protocol\u002F 目录下的代码，\n识别可以进一步优化的重复模式。\n\n当前已优化的模式：\n1. 使用 handle_channel_operation 通用函数\n2. 使用 ncsi_utils.create_custom_cmd_table\n3. 使用命令表模式\n\n请分析还有哪些重复代码可以进一步优化，\n并提供具体的优化方案和代码实现。\n  高效 Prompt 编写技巧总结 最后，给大家分享一些我自己总结的有效Prompt编写技巧：  总结 尽管目前无法实现 “一键生成完整代码”，但大模型在研发辅助中仍具较高实用价值。这种新型开发模式有望颠覆传统开发流程，为 BMC、固件领域带来革新性体验。 期待在 openUBMC 社区看到更多 AI 辅助编码实践，激发更多创新思路。欢迎开发者分享经验、交流见解，共同探索 AI 辅助编码的无限可能。 欢迎关注我们 社区官网： https:\u002F\u002Fwww.openubmc.cn 代码仓地址： https:\u002F\u002Fgitcode.com\u002FopenUBMC\u002Fnetwork_adapter",[14],{"_path":423,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":424,"description":425,"date":10,"category":11,"author":426,"body":429,"_type":414,"_id":761,"_source":416,"_file":762,"_stem":763,"_extension":419,"coverImage":133,"plainText":764,"authorNames":765},"\u002Fen\u002Fblogs\u002F202508072","AI-Powered R&D: Rapid NCSI Protocol Command Parsing in openUBMC","NCSIis 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:",[427],{"name":14,"description":428},"BMC developer, specializing in software development and improving automation efficiency, with unique insights into AI-assisted R&D.",{"type":17,"children":430,"toc":746},[431,436,442,453,486,491,497,502,508,513,519,525,530,535,541,546,551,557,562,570,588,596,601,606,612,620,625,644,650,658,664,670,678,684,690,698,704,710,715,720,726,736],{"type":20,"tag":21,"props":432,"children":434},{"id":433},"ai-powered-rd-rapid-ncsi-protocol-command-parsing-in-openubmc",[435],{"type":26,"value":424},{"type":20,"tag":28,"props":437,"children":439},{"id":438},"background-repetitive-work-in-protocol-command-development",[440],{"type":26,"value":441},"Background: Repetitive Work in Protocol Command Development",{"type":20,"tag":35,"props":443,"children":444},{},[445,446,451],{"type":26,"value":39},{"type":20,"tag":41,"props":447,"children":448},{"color":43},[449],{"type":26,"value":450}," (Network Controller Sideband Interface) ",{"type":26,"value":452},"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:",{"type":20,"tag":50,"props":454,"children":455},{},[456,466,476],{"type":20,"tag":54,"props":457,"children":458},{},[459,464],{"type":20,"tag":58,"props":460,"children":461},{},[462],{"type":26,"value":463},"High code duplication",{"type":26,"value":465},": Except for the request\u002Fresponse payload structure, the code logic for different NCSI commands was nearly identical, leading to extensive boilerplate.",{"type":20,"tag":54,"props":467,"children":468},{},[469,474],{"type":20,"tag":58,"props":470,"children":471},{},[472],{"type":26,"value":473},"Manual generation of test data",{"type":26,"value":475},": Binary test data had to be calculated and written manually. This process was complex and highly prone to error.",{"type":20,"tag":54,"props":477,"children":478},{},[479,484],{"type":20,"tag":58,"props":480,"children":481},{},[482],{"type":26,"value":483},"Dense and vague documentation",{"type":26,"value":485},": The NCSI protocol specification is English-only and technically dense, requiring significant effort to read and often leading to misinterpretation of certain sections.",{"type":20,"tag":35,"props":487,"children":488},{},[489],{"type":26,"value":490},"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.",{"type":20,"tag":28,"props":492,"children":494},{"id":493},"pattern-analysis-identifying-the-automatable-core",[495],{"type":26,"value":496},"Pattern Analysis: Identifying the \"Automatable\" Core",{"type":20,"tag":35,"props":498,"children":499},{},[500],{"type":26,"value":501},"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.",{"type":20,"tag":112,"props":503,"children":505},{"id":504},"_1-protocol-documentation-understanding-and-command-extraction",[506],{"type":26,"value":507},"1. Protocol Documentation Understanding and Command Extraction",{"type":20,"tag":35,"props":509,"children":510},{},[511],{"type":26,"value":512},"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.",{"type":20,"tag":35,"props":514,"children":515},{},[516],{"type":20,"tag":130,"props":517,"children":518},{"alt":132,"src":133},[],{"type":20,"tag":112,"props":520,"children":522},{"id":521},"_2-writing-command-handler-functions",[523],{"type":26,"value":524},"2. Writing Command Handler Functions",{"type":20,"tag":35,"props":526,"children":527},{},[528],{"type":26,"value":529},"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.",{"type":20,"tag":35,"props":531,"children":532},{},[533],{"type":26,"value":534},"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.",{"type":20,"tag":112,"props":536,"children":538},{"id":537},"_3-generating-test-cases-for-protocol-compliance",[539],{"type":26,"value":540},"3. Generating Test Cases for Protocol Compliance",{"type":20,"tag":35,"props":542,"children":543},{},[544],{"type":26,"value":545},"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.",{"type":20,"tag":35,"props":547,"children":548},{},[549],{"type":26,"value":550},"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.",{"type":20,"tag":28,"props":552,"children":554},{"id":553},"coding-in-practice-practical-prompt-templates",[555],{"type":26,"value":556},"Coding in Practice: Practical Prompt Templates",{"type":20,"tag":35,"props":558,"children":559},{},[560],{"type":26,"value":561},"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.",{"type":20,"tag":35,"props":563,"children":564},{},[565],{"type":20,"tag":58,"props":566,"children":567},{},[568],{"type":26,"value":569},"Key Results:",{"type":20,"tag":50,"props":571,"children":572},{},[573,578,583],{"type":20,"tag":54,"props":574,"children":575},{},[576],{"type":26,"value":577},"80+ functions and corresponding test cases generated automatically, with the accuracy exceeding 90% and the UT coverage above 86%.",{"type":20,"tag":54,"props":579,"children":580},{},[581],{"type":26,"value":582},"Overall development efficiency increased by 65%, saving an estimated 30+ person-days.",{"type":20,"tag":54,"props":584,"children":585},{},[586],{"type":26,"value":587},"Code style was consistent with community standards, leading to a smooth review by the SIG Committer.",{"type":20,"tag":35,"props":589,"children":590},{},[591],{"type":20,"tag":58,"props":592,"children":593},{},[594],{"type":26,"value":595},"Knowledge Background Setup",{"type":20,"tag":35,"props":597,"children":598},{},[599],{"type":26,"value":600},"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.",{"type":20,"tag":35,"props":602,"children":603},{},[604],{"type":26,"value":605},"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.",{"type":20,"tag":35,"props":607,"children":608},{},[609],{"type":20,"tag":130,"props":610,"children":611},{"alt":132,"src":233},[],{"type":20,"tag":35,"props":613,"children":614},{},[615],{"type":20,"tag":58,"props":616,"children":617},{},[618],{"type":26,"value":619},"Template Breakdown",{"type":20,"tag":35,"props":621,"children":622},{},[623],{"type":26,"value":624},"I broke the task into three steps, using an iterative generation and Q&A approach to further boost code accuracy, and wrote corresponding prompts:",{"type":20,"tag":626,"props":627,"children":628},"ol",{},[629,634,639],{"type":20,"tag":54,"props":630,"children":631},{},[632],{"type":26,"value":633},"Generate NCSI command response and parsing functions.",{"type":20,"tag":54,"props":635,"children":636},{},[637],{"type":26,"value":638},"Generate corresponding UT functions and test data for the created functions.",{"type":20,"tag":54,"props":640,"children":641},{},[642],{"type":26,"value":643},"Optimize all newly added code.",{"type":20,"tag":112,"props":645,"children":647},{"id":646},"prompt-example-1-generating-new-functions",[648],{"type":26,"value":649},"Prompt Example 1: Generating New Functions",{"type":20,"tag":275,"props":651,"children":653},{"code":652},"Based on the existing code pattern below, generate the corresponding function for the new NCSI command [COMMAND_NAME]:\nReference Header File Definitions:\nCommand type macros: Refer to command constants in header files under test-main\u002Fncsi path.\nPacket structure definitions: Refer to request\u002Fresponse structs in the header file.\nLength macros: Refer to *_REQ_LEN, *_RSP_LEN, *_PAD_LEN, etc. in the header file.\n\nExisting Pattern:\nfunction ncsi_cmd.ncsi_enable_channel(package_id, channel_id, eth_name)\n\nRequirements:\n1. Function name must be ncsi_[COMMAND_NAME].\n2. Parameters must be package_id, channel_id, eth_name.\n3. Must include the same parameter validation logic.\n4. Must call the corresponding module function.\n5. Must return the same error codes.\n\nPlease generate the complete function code.\n",[654],{"type":20,"tag":280,"props":655,"children":656},{"__ignoreMap":7},[657],{"type":26,"value":652},{"type":20,"tag":35,"props":659,"children":660},{},[661],{"type":20,"tag":130,"props":662,"children":663},{"alt":132,"src":289},[],{"type":20,"tag":112,"props":665,"children":667},{"id":666},"prompt-example-2-generating-test-cases",[668],{"type":26,"value":669},"Prompt Example 2: Generating Test Cases",{"type":20,"tag":275,"props":671,"children":673},{"code":672},"Based on the testing pattern below, generate a complete test case file for the [MODULE_NAME] module:\n\nExisting Testing Pattern:\nfunction TestNCSIBroadcastFilter:test_enable_broadcast_filter()\n\nRequirements:\n1. Create a test class TestNCSI[MODULE_NAME] for [MODULE_NAME].\n2. Include setUp and tearDown methods.\n3. Generate a test case for every public function.\n4. Include both success and failure scenario tests.\n5. Validate the request packet format.\n6. Include boundary condition tests.\n\nPlease generate the complete test file.\n",[674],{"type":20,"tag":280,"props":675,"children":676},{"__ignoreMap":7},[677],{"type":26,"value":672},{"type":20,"tag":35,"props":679,"children":680},{},[681],{"type":20,"tag":130,"props":682,"children":683},{"alt":132,"src":310},[],{"type":20,"tag":112,"props":685,"children":687},{"id":686},"prompt-example-3-code-optimization",[688],{"type":26,"value":689},"Prompt Example 3: Code Optimization",{"type":20,"tag":275,"props":691,"children":693},{"code":692},"Code Optimization Suggestions\n\nAnalyze the code under the src\u002Flualib\u002Fncsi\u002Fncsi_protocol\u002F directory.\nIdentify repetitive patterns that can be further optimized.\n\nCurrently optimized patterns:\n1. Using the handle_channel_operation generic function.\n2. Using ncsi_utils.create_custom_cmd_table.\n3. Using the command table pattern.\n\nAnalyze what other repetitive code can be further optimized and provide specific optimization plans and code implementations.\n",[694],{"type":20,"tag":280,"props":695,"children":696},{"__ignoreMap":7},[697],{"type":26,"value":692},{"type":20,"tag":35,"props":699,"children":700},{},[701],{"type":20,"tag":130,"props":702,"children":703},{"alt":132,"src":331},[],{"type":20,"tag":28,"props":705,"children":707},{"id":706},"conclusion-and-outlook",[708],{"type":26,"value":709},"Conclusion and Outlook",{"type":20,"tag":35,"props":711,"children":712},{},[713],{"type":26,"value":714},"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.",{"type":20,"tag":35,"props":716,"children":717},{},[718],{"type":26,"value":719},"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!",{"type":20,"tag":28,"props":721,"children":723},{"id":722},"welcome-to-follow-us",[724],{"type":26,"value":725},"Welcome to follow us!",{"type":20,"tag":35,"props":727,"children":728},{},[729,731],{"type":26,"value":730},"openUBMC official website: ",{"type":20,"tag":377,"props":732,"children":734},{"href":379,"rel":733},[381],[735],{"type":26,"value":379},{"type":20,"tag":35,"props":737,"children":738},{},[739,741],{"type":26,"value":740},"Code repository: ",{"type":20,"tag":377,"props":742,"children":744},{"href":391,"rel":743},[381],[745],{"type":26,"value":391},{"title":7,"searchDepth":396,"depth":396,"links":747},[748,749,754,759,760],{"id":438,"depth":399,"text":441},{"id":493,"depth":399,"text":496,"children":750},[751,752,753],{"id":504,"depth":403,"text":507},{"id":521,"depth":403,"text":524},{"id":537,"depth":403,"text":540},{"id":553,"depth":399,"text":556,"children":755},[756,757,758],{"id":646,"depth":403,"text":649},{"id":666,"depth":403,"text":669},{"id":686,"depth":403,"text":689},{"id":706,"depth":399,"text":709},{"id":722,"depth":399,"text":725},"content:en:blogs:202508072.md","en\u002Fblogs\u002F202508072.md","en\u002Fblogs\u002F202508072","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\u002Fresponse 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.  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.  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: Generate NCSI command response and parsing functions. Generate corresponding UT functions and test data for the created functions. 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]:\nReference Header File Definitions:\nCommand type macros: Refer to command constants in header files under test-main\u002Fncsi path.\nPacket structure definitions: Refer to request\u002Fresponse structs in the header file.\nLength macros: Refer to *_REQ_LEN, *_RSP_LEN, *_PAD_LEN, etc. in the header file.\n\nExisting Pattern:\nfunction ncsi_cmd.ncsi_enable_channel(package_id, channel_id, eth_name)\n\nRequirements:\n1. Function name must be ncsi_[COMMAND_NAME].\n2. Parameters must be package_id, channel_id, eth_name.\n3. Must include the same parameter validation logic.\n4. Must call the corresponding module function.\n5. Must return the same error codes.\n\nPlease generate the complete function code.\n  Prompt Example 2: Generating Test Cases Based on the testing pattern below, generate a complete test case file for the [MODULE_NAME] module:\n\nExisting Testing Pattern:\nfunction TestNCSIBroadcastFilter:test_enable_broadcast_filter()\n\nRequirements:\n1. Create a test class TestNCSI[MODULE_NAME] for [MODULE_NAME].\n2. Include setUp and tearDown methods.\n3. Generate a test case for every public function.\n4. Include both success and failure scenario tests.\n5. Validate the request packet format.\n6. Include boundary condition tests.\n\nPlease generate the complete test file.\n  Prompt Example 3: Code Optimization Code Optimization Suggestions\n\nAnalyze the code under the src\u002Flualib\u002Fncsi\u002Fncsi_protocol\u002F directory.\nIdentify repetitive patterns that can be further optimized.\n\nCurrently optimized patterns:\n1. Using the handle_channel_operation generic function.\n2. Using ncsi_utils.create_custom_cmd_table.\n3. Using the command table pattern.\n\nAnalyze what other repetitive code can be further optimized and provide specific optimization plans and code implementations.\n  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:\u002F\u002Fwww.openubmc.cn Code repository:  https:\u002F\u002Fgitcode.com\u002FopenUBMC\u002Fnetwork_adapter",[14],[767,767],null,1784971460885]