已合并
【44bd0a9dc84204d2d211979601e1a004】feat(uart_connect):多芯片HAL层SOL驱动实现 #22
byosoft_zhoujiangkun创建于 3 天前
【44bd0a9dc84204d2d211979601e1a004】feat(uart_connect):多芯片HAL层SOL驱动实现 #22
已合并
共 6 个文件变更+612-2
| @@ -2,6 +2,10 @@ | |||
| 2 | 2 | ||
| 3 | All notable changes to this project will be documented in this file. | 3 | All notable changes to this project will be documented in this file. |
| 4 | 4 | ||
| 5 | +## [1.0.13] - 2026-11-26 | ||
| 6 | + | ||
| 7 | +- 支持 uart_connect 驱动接口 | ||
| 8 | + | ||
| 5 | ## [1.0.12] - 2026-11-26 | 9 | ## [1.0.12] - 2026-11-26 |
| 6 | 10 | ||
| 7 | - 支持 uart 驱动接口 | 11 | - 支持 uart 驱动接口 |
| @@ -9,3 +9,4 @@ subdir('jtag') | |||
| 9 | subdir('i2c') | 9 | subdir('i2c') |
| 10 | subdir('lpc_snoop') | 10 | subdir('lpc_snoop') |
| 11 | subdir('uart') | 11 | subdir('uart') |
| 12 | +subdir('uart_connect') | ||
| @@ -0,0 +1,11 @@ | |||
| 1 | +driver_name = 'uart_connect' | ||
| 2 | + | ||
| 3 | +sources = files('uart_connect.cpp') | ||
| 4 | + | ||
| 5 | +uart_connect_lib = shared_library(driver_name, | ||
| 6 | + sources, | ||
| 7 | + dependencies: [bcal_dep], | ||
| 8 | + cpp_args: ['-fvisibility=hidden', '-fvisibility-inlines-hidden'], | ||
| 9 | + install: true, | ||
| 10 | + install_dir: driver_install_dir | ||
| 11 | +) | ||
| @@ -0,0 +1,593 @@ | |||
| 1 | +/* Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 2 | + * openUBMC is licensed under Mulan PSL v2. | ||
| 3 | + * You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
| 4 | + * You may obtain a copy of Mulan PSL v2 at: | ||
| 5 | + * http://license.coscl.org.cn/MulanPSL2 | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
| 7 | + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||
| 8 | + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
| 9 | + * See the Mulan PSL v2 for more details. | ||
| 10 | + */ | ||
| 11 | + | ||
| 12 | +#include <bcal/uart.h> | ||
| 13 | + | ||
| 14 | +#include <algorithm> | ||
| 15 | +#include <cerrno> | ||
| 16 | +#include <cstdint> | ||
| 17 | +#include <cstdio> | ||
| 18 | +#include <cstring> | ||
| 19 | +#include <fcntl.h> | ||
| 20 | +#include <glob.h> | ||
| 21 | +#include <mutex> | ||
| 22 | +#include <sstream> | ||
| 23 | +#include <stdexcept> | ||
| 24 | +#include <string> | ||
| 25 | +#include <system_error> | ||
| 26 | +#include <thread> | ||
| 27 | +#include <unistd.h> | ||
| 28 | +#include <vector> | ||
| 29 | + | ||
| 30 | +namespace BCAL_UART_CONNECT_ASPEED { | ||
| 31 | +using namespace bcal; | ||
| 32 | +using namespace BCAL_DRIVER_UART; | ||
| 33 | + | ||
| 34 | +/* 回滚失败:source 已改成 target,恢复原值失败。单独的类型便于调用方按类型区分; | ||
| 35 | + * 前向错误、回滚错误与残留状态都在 what() 中。 */ | ||
| 36 | +class RouteRollbackError : public std::runtime_error { | ||
| 37 | +public: | ||
| 38 | + explicit RouteRollbackError(const std::string& message) : std::runtime_error(message) {} | ||
| 39 | +}; | ||
| 40 | + | ||
| 41 | +namespace { | ||
| 42 | + | ||
| 43 | +constexpr const char* DRIVER_VERSION = "bcal_uart_connect_aspeed v1.1.0 (aspeed-uart-routing)"; | ||
| 44 | +constexpr const char* ROUTING_GLOB = "/sys/bus/platform/drivers/aspeed-uart-routing/*.uart-routing"; | ||
| 45 | +constexpr size_t MAX_ATTR_LEN = 4096; /* 单属性值上限,超出视为异常 */ | ||
| 46 | + | ||
| 47 | +/* strerror 返回共享静态缓冲区,多线程不安全;message() 每次返回独立 string。 */ | ||
| 48 | +std::string error_text(int error) | ||
| 49 | +{ | ||
| 50 | + return std::generic_category().message(error); | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +/* fd RAII:异常路径(如 bad_alloc)也保证关闭 */ | ||
| 54 | +class FdGuard { | ||
| 55 | +public: | ||
| 56 | + explicit FdGuard(int fd) : m_fd(fd) {} | ||
| 57 | + ~FdGuard() | ||
| 58 | + { | ||
| 59 | + if (m_fd >= 0) { | ||
| 60 | + ::close(m_fd); | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + FdGuard(const FdGuard&) = delete; | ||
| 64 | + FdGuard& operator=(const FdGuard&) = delete; | ||
| 65 | + | ||
| 66 | +private: | ||
| 67 | + int m_fd; | ||
| 68 | +}; | ||
| 69 | + | ||
| 70 | +std::string read_file(const std::string& path) | ||
| 71 | +{ | ||
| 72 | + const int fd = ::open(path.c_str(), O_RDONLY | O_CLOEXEC); | ||
| 73 | + if (fd < 0) { | ||
| 74 | + const int error = errno; | ||
| 75 | + throw std::runtime_error("open " + path + " failed: " + error_text(error)); | ||
| 76 | + } | ||
| 77 | + FdGuard guard(fd); | ||
| 78 | + std::string value; | ||
| 79 | + char buffer[256]; | ||
| 80 | + for (;;) { | ||
| 81 | + const ssize_t count = ::read(fd, buffer, sizeof(buffer)); | ||
| 82 | + if (count < 0) { | ||
| 83 | + if (errno == EINTR) { | ||
| 84 | + continue; | ||
| 85 | + } | ||
| 86 | + const int error = errno; | ||
| 87 | + throw std::runtime_error("read " + path + " failed: " + error_text(error)); | ||
| 88 | + } | ||
| 89 | + if (count == 0) { | ||
| 90 | + break; | ||
| 91 | + } | ||
| 92 | + value.append(buffer, static_cast<size_t>(count)); | ||
| 93 | + if (value.size() > MAX_ATTR_LEN) { | ||
| 94 | + throw std::runtime_error("routing attribute " + path + " is unexpectedly large"); | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + while (!value.empty() && (value.back() == '\n' || value.back() == '\r' || value.back() == ' ')) { | ||
| 99 | + value.pop_back(); | ||
| 100 | + } | ||
| @@ -2,14 +2,14 @@ | |||
| 2 | "name": "libsoc_adapter_aspeed", | 2 | "name": "libsoc_adapter_aspeed", |
| 3 | "type": "application", | 3 | "type": "application", |
| 4 | "deployConfig": "", | 4 | "deployConfig": "", |
| 5 | - "version": "1.0.12", | 5 | + "version": "1.0.13", |
| 6 | "license": "Mulan PSL v2", | 6 | "license": "Mulan PSL v2", |
| 7 | "description": "BMC chip adapter for Aspeed.", | 7 | "description": "BMC chip adapter for Aspeed.", |
| 8 | "dependencies": { | 8 | "dependencies": { |
| 9 | "test": [], | 9 | "test": [], |
| 10 | "build": [ | 10 | "build": [ |
| 11 | { | 11 | { |
| 12 | - "conan": "bcal/[>=0.0.12]" | 12 | + "conan": "bcal/[>=0.0.13]" |
| 13 | } | 13 | } |
| 14 | ] | 14 | ] |
| 15 | }, | 15 | }, |
| @@ -17,3 +17,4 @@ opt/bmc/bcal/libjtag.so f 550 0 0 | |||
| 17 | opt/bmc/bcal/libi2c.so f 550 0 0 | 17 | opt/bmc/bcal/libi2c.so f 550 0 0 |
| 18 | opt/bmc/bcal/liblpc_snoop.so f 550 0 0 | 18 | opt/bmc/bcal/liblpc_snoop.so f 550 0 0 |
| 19 | opt/bmc/bcal/libuart.so f 550 0 0 | 19 | opt/bmc/bcal/libuart.so f 550 0 0 |
| 20 | +opt/bmc/bcal/libuart_connect.so f 550 0 0 | ||