当前位置:   article > 正文

openbmc 开发四(ast2500) 适配power status_openbmc power on

openbmc power on

1.适配原因

如果使用ipmitool发送命令:

# ipmitool -U root -P 0penBmc -H 10.245.27.93 -I lanplus -C 17 chassis power status 
Get Chassis Power Status failed: Unspecified error
  • 1
  • 2

在这里插入图片描述
BMC端可以在串口下使用journalctl -p err看到打印:
在这里插入图片描述
尝试修改build/ast2500-default/workspace/sources/phosphor-ipmi-host/chassishandler.cpp代码:
在这里插入图片描述
然后使用ipmitool命令,可以获取到返回。

# ipmitool -U root -P 0penBmc -H 10.245.27.22 -I lanplus -C 17 chassis power status 
Chassis Power is on
  • 1
  • 2

因此,目前对于power的控制是不支持的。

2.busctl的使用

参考链接: https://www.freedesktop.org/software/systemd/man/latest/busctl.html

2.1 命令简单使用

  • 1.查看sensor的信息,使用命令:busctl | grep Sensor
    在这里插入图片描述
  • 2.使用命令busctl tree xyz.openbmc_project.ADCSensor
    在这里插入图片描述
  • 3.使用命令:busctl introspect xyz.openbmc_project.ADCSensor

在这里插入图片描述
可以看到interfaces有如下:

在这里插入图片描述

2.2 busctl从代码端分析

在文件:build/ast2500-default/workspace/sources/phosphor-ipmi-host/chassishandler.cpp中,可以看到如下代码:

std::optional<bool> getPowerStatus()
{
    bool powerGood = false;
    std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
    try
    {
        constexpr const char* chassisStatePath =
            "/xyz/openbmc_project/state/chassis0";
        constexpr const char* chassisStateIntf =
            "xyz.openbmc_project.State.Chassis";
        auto service =
            ipmi::getService(*busp, chassisStateIntf, chassisStatePath);

        ipmi::Value powerState =
            ipmi::getDbusProperty(*busp, service, chassisStatePath,
                                  chassisStateIntf, "CurrentPowerState");
        powerGood = std::get<std::string>(powerState) ==
                    "xyz.openbmc_project.State.Chassis.PowerState.On";
    }
    catch (const std::exception& e)
    {
        try
        {
            // FIXME: some legacy modules use the older path; try that next
            constexpr const char* legacyPwrCtrlObj =
                "/org/openbmc/control/power0";
            constexpr const char* legacyPwrCtrlIntf =
                "org.openbmc.control.Power";
            auto service =
                ipmi::getService(*busp, legacyPwrCtrlIntf, legacyPwrCtrlObj);

            ipmi::Value variant = ipmi::getDbusProperty(
                *busp, service, legacyPwrCtrlObj, legacyPwrCtrlIntf, "pgood");
            powerGood = static_cast<bool>(std::get<int>(variant));
        }
        catch (const std::exception& e)
        {
            log<level::ERR>("Failed to fetch pgood property",
                            entry("ERROR=%s", e.what()));
            return std::nullopt;
        }
    }
    return std::make_optional(powerGood);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

当前使用的sdbus结构非legacy模式,因此,需要查询"xyz.openbmc_project.State.Chassis"是否存在。
在这里插入图片描述
可以发现,我们并未注册该service到系统中。

3.代码修改

  • 1.修改文件:meta-aspeed-sdk/meta-ast2500-sdk/conf/machine/ast2500-default.conf中的内容:
require conf/machine/include/ast2500-sdk.inc
require conf/machine/include/obmc-bsp-common.inc

# Overwrite flash layout
FLASH_SIZE = "65535"
FLASH_UBOOT_OFFSET = "0"
FLASH_KERNEL_OFFSET = "1024"
FLASH_ROFS_OFFSET = "10240"
FLASH_RWFS_OFFSET = "47104"
RWFS_SIZE = "18874368"

# U-Boot Build Settings
UBOOT_MACHINE = "evb-ast2500_defconfig"
UBOOT_DEVICETREE = "ast2500-evb"

# Kernel Build Settings
KERNEL_DEVICETREE = "aspeed-ast2500-evb.dtb"
KBUILD_DEFCONFIG = "aspeed_g5_defconfig"

# MACHINE_FEATURES += "\
#         obmc-phosphor-fan-mgmt \
#         obmc-phosphor-chassis-mgmt \
#         obmc-phosphor-flash-mgmt \
#         obmc-host-ipmi \
#         obmc-host-state-mgmt \
#         obmc-chassis-state-mgmt \
#         obmc-bmc-state-mgmt \
#         "
MACHINE_FEATURES += "\
        obmc-phosphor-fan-mgmt \
        obmc-phosphor-flash-mgmt \
        obmc-host-ipmi \
        "

PREFERRED_PROVIDER_virtual/obmc-system-mgmt = "packagegroup-aspeed-obmc"
PREFERRED_PROVIDER_virtual/obmc-host-ipmi-hw = "phosphor-ipmi-kcs"
VIRTUAL-RUNTIME_obmc-host-state-manager ?= "x86-power-control"
VIRTUAL-RUNTIME_obmc-chassis-state-manager ?= "x86-power-control"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

使用以上的配置后,编译系统,烧录程序:
使用busctl查看系统State service,可以看到(注意需要修改json文件和x86-power-control代码以及相关文件,后面的内容有简单说明):
在这里插入图片描述
如此也不会再报错了,只是返回错误的系统状态,这需要具体函数里面添加GPIO的适配即可:
在这里插入图片描述

注意:
x86-power-controlphosphor-state-manager是不能共存的,可以看到它们有相同的service.

  • 2.修改内容:build/ast2500-default/workspace/sources/phosphor-gpio-monitor/phosphor-multi-gpio-monitor.json
    中的io配置。

可以查看链接: https://github.com/openbmc/phosphor-gpio-monitor/blob/master/README.md
与链接: https://gitee.com/mirrors_openbmc/x86-power-control

相关文件:

meta-phosphor/conf/distro/include/phosphor-defaults.inc
meta-aspeed-sdk/meta-ast2500-sdk/conf/machine/ast2500-default.conf
meta-phosphor/conf/distro/openbmc-phosphor.conf
  • 1
  • 2
  • 3

需要修改: meta-phosphor/conf/distro/include/phosphor-defaults.inc文件,选择:x86-power-controlphosphor-state-manager的一个包。
将:aspeed/openbmc/meta-phosphor/conf/distro/include/phosphor-defaults.inc中注释掉内容:

#VIRTUAL-RUNTIME_obmc-chassis-state-manager ?= "phosphor-state-manager-chassis"
#VIRTUAL-RUNTIME_obmc-host-state-manager ?= "phosphor-state-manager-host"
  • 1
  • 2

添加包:x86-power-control之后,可以从BMC端看到如下内容(前提是修改好json文件和x86-power-control的代码):
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

修改文件:build/ast2500-default/workspace/sources/x86-power-control/config/power-config-host0.json中的内容:

{
    "gpio_configs": [
        {
            "Name": "IdButton",
            "LineName": "ID_BUTTON",
            "Type": "GPIO",
            "Polarity": "ActiveLow"
        },
        {
            "Name": "PowerOut",
            "LineName": "POWER_BUTTON",
            "Type": "GPIO",
            "Polarity": "ActiveLow"
        },
        {
            "Name": "PowerOk",
            "LineName": "PS_PWROK",
            "Type": "GPIO",
            "Polarity": "ActiveLow"
        }
    ],
    "timing_configs": {
        "PowerPulseMs": 1000,
        "ForceOffPulseMs": 15000,
        "ResetPulseMs": 500,
        "PowerCycleMs": 5000,
        "SioPowerGoodWatchdogMs": 1000,
        "PsPowerOKWatchdogMs": 8000,
        "GracefulPowerOffS": 300,
        "WarmResetCheckMs": 500,
        "PowerOffSaveMs": 7000
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

实际上x86-power-control中将Button类认为GPIO是输入的。
配置:build/ast2500-default/workspace/sources/linux-aspeed/arch/arm/boot/dts/aspeed-ast2500-evb.dts内容:

&gpio {
	gpio-line-names = 
	/*A0~A7*/"A0","A1","A2","","","","","",
	/*B0~B7*/"B0","B1","B2","","","","","ID_BUTTON",
	/*C0~C7*/"C0","C1","C2","","","","","",
	/*D0~D7*/"D0","D1","D2","","","","","",
	/*E0~E7*/"E0","E1","E2","","","","","",
	/*F0~F7*/"F0","F1","F2","","","","","",
	/*G0~G7*/"G0","G1","G2","","","","","",
	/*H0~H7*/"H0","H1","H2","","","","","PS_PWROK",
	/*I0~I7*/"I0","POWER_BUTTON","I2","","","","","",
	/*J0~J7*/"J0","J1","RESET_BUTTON","","","","","";
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

实际上,只需要关注:PS_PWROKPOWER_BUTTON

如此,可以执行开关机动作后,能使用ipmitool查看到当前os的开机状态。

在这里插入图片描述

本节暂不说如何修改:x86-power-control的代码。

总之:
openbmc的代码整体架构还是比较清晰的。 从新手来的角度来说,架构清晰基本上功能的添加还是没有什么太大的难度的。 后面需要的是继续深挖dbusc++语言的知识了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/959997
推荐阅读
相关标签
  

闽ICP备14008679号