oemcommands.cpp (39836ffadcce9706fe65f641ccfc7d74fe4c66c0) oemcommands.cpp (778147daaaa503172e8f35842de06bdd20edd67e)
1/*
2 * Copyright (c) 2018 Intel Corporation.
3 * Copyright (c) 2018-present Facebook.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *

--- 4 unchanged lines hidden (view full) ---

13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "xyz/openbmc_project/Common/error.hpp"
19#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
20#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
1/*
2 * Copyright (c) 2018 Intel Corporation.
3 * Copyright (c) 2018-present Facebook.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *

--- 4 unchanged lines hidden (view full) ---

13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "xyz/openbmc_project/Common/error.hpp"
19#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
20#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
21#include <xyz/openbmc_project/Control/Boot/Type/server.hpp>
21
22#include <ipmid/api.hpp>
23#include <ipmid/utils.hpp>
24#include <commandutils.hpp>
25#include <nlohmann/json.hpp>
26#include <oemcommands.hpp>
27#include <phosphor-logging/log.hpp>
28#include <sdbusplus/bus.hpp>

--- 126 unchanged lines hidden (view full) ---

155 {0x01, Source::Sources::Network},
156 {0x02, Source::Sources::Disk},
157 {0x03, Source::Sources::ExternalMedia},
158 {0x09, Source::Sources::Network}};
159
160std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
161 {0x06, Mode::Modes::Setup}, {0x00, Mode::Modes::Regular}};
162
22
23#include <ipmid/api.hpp>
24#include <ipmid/utils.hpp>
25#include <commandutils.hpp>
26#include <nlohmann/json.hpp>
27#include <oemcommands.hpp>
28#include <phosphor-logging/log.hpp>
29#include <sdbusplus/bus.hpp>

--- 126 unchanged lines hidden (view full) ---

156 {0x01, Source::Sources::Network},
157 {0x02, Source::Sources::Disk},
158 {0x03, Source::Sources::ExternalMedia},
159 {0x09, Source::Sources::Network}};
160
161std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
162 {0x06, Mode::Modes::Setup}, {0x00, Mode::Modes::Regular}};
163
164std::map<IpmiValue, Type::Types> typeIpmiToDbus = {{0x00, Type::Types::Legacy},
165 {0x01, Type::Types::EFI}};
166
163std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
164 {Source::Sources::Default, 0x0f},
165 {Source::Sources::RemovableMedia, 0x00},
166 {Source::Sources::Network, 0x01},
167 {Source::Sources::Disk, 0x02},
168 {Source::Sources::ExternalMedia, 0x03}};
169
170std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
171 {Mode::Modes::Setup, 0x06}, {Mode::Modes::Regular, 0x00}};
172
167std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
168 {Source::Sources::Default, 0x0f},
169 {Source::Sources::RemovableMedia, 0x00},
170 {Source::Sources::Network, 0x01},
171 {Source::Sources::Disk, 0x02},
172 {Source::Sources::ExternalMedia, 0x03}};
173
174std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
175 {Mode::Modes::Setup, 0x06}, {Mode::Modes::Regular, 0x00}};
176
177std::map<Type::Types, IpmiValue> typeDbusToIpmi = {{Type::Types::Legacy, 0x00},
178 {Type::Types::EFI, 0x01}};
179
173static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
174static constexpr auto bootSourceIntf =
175 "xyz.openbmc_project.Control.Boot.Source";
180static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
181static constexpr auto bootSourceIntf =
182 "xyz.openbmc_project.Control.Boot.Source";
183static constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
176static constexpr auto bootSourceProp = "BootSource";
177static constexpr auto bootModeProp = "BootMode";
184static constexpr auto bootSourceProp = "BootSource";
185static constexpr auto bootModeProp = "BootMode";
186static constexpr auto bootTypeProp = "BootType";
178
179auto instances(std::string s)
180{
181 std::string delimiter = " ";
182 size_t pos = 0;
183 std::string token;
184 std::vector<std::string> host;
185

--- 471 unchanged lines hidden (view full) ---

657/* Helper functions to set boot order */
658void setBootOrder(std::string bootObjPath, uint8_t* data,
659 std::string bootOrderKey)
660{
661
662 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
663
664 // SETTING BOOT MODE PROPERTY
187
188auto instances(std::string s)
189{
190 std::string delimiter = " ";
191 size_t pos = 0;
192 std::string token;
193 std::vector<std::string> host;
194

--- 471 unchanged lines hidden (view full) ---

666/* Helper functions to set boot order */
667void setBootOrder(std::string bootObjPath, uint8_t* data,
668 std::string bootOrderKey)
669{
670
671 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
672
673 // SETTING BOOT MODE PROPERTY
665 auto bootValue = ipmi::boot::modeIpmiToDbus.find((data[0]));
674 uint8_t bootModeBit = data[0] & 0x06;
675 auto bootValue = ipmi::boot::modeIpmiToDbus.find(bootModeBit);
676
666 std::string bootOption =
667 ipmi::boot::Mode::convertModesToString((bootValue->second));
668
669 std::string service =
670 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
671 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
672 ipmi::boot::bootModeProp, bootOption);
673
674 // SETTING BOOT SOURCE PROPERTY
675 auto bootOrder = ipmi::boot::sourceIpmiToDbus.find((data[1]));
676 std::string bootSource =
677 ipmi::boot::Source::convertSourcesToString((bootOrder->second));
678
679 service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
680 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
681 ipmi::boot::bootSourceProp, bootSource);
682
677 std::string bootOption =
678 ipmi::boot::Mode::convertModesToString((bootValue->second));
679
680 std::string service =
681 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
682 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
683 ipmi::boot::bootModeProp, bootOption);
684
685 // SETTING BOOT SOURCE PROPERTY
686 auto bootOrder = ipmi::boot::sourceIpmiToDbus.find((data[1]));
687 std::string bootSource =
688 ipmi::boot::Source::convertSourcesToString((bootOrder->second));
689
690 service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
691 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
692 ipmi::boot::bootSourceProp, bootSource);
693
694 // SETTING BOOT TYPE PROPERTY
695
696 uint8_t bootTypeBit = data[0] & 0x01;
697 auto bootTypeVal = ipmi::boot::typeIpmiToDbus.find(bootTypeBit);
698 std::string bootType =
699 ipmi::boot::Type::convertTypesToString((bootTypeVal->second));
700
701 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
702
703 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
704 ipmi::boot::bootTypeProp, bootType);
705
683 nlohmann::json bootMode;
684 uint8_t mode = data[0];
685 int i;
686
687 bootMode["UEFI"] = (mode & BOOT_MODE_UEFI ? true : false);
688 bootMode["CMOS_CLR"] = (mode & BOOT_MODE_CMOS_CLR ? true : false);
689 bootMode["FORCE_BOOT"] = (mode & BOOT_MODE_FORCE_BOOT ? true : false);
690 bootMode["BOOT_FLAG"] = (mode & BOOT_MODE_BOOT_FLAG ? true : false);

--- 46 unchanged lines hidden (view full) ---

737}
738
739//----------------------------------------------------------------------
740// Get Boot Order (CMD_OEM_GET_BOOT_ORDER)
741//----------------------------------------------------------------------
742ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
743 ipmiOemGetBootOrder(ipmi::Context::ptr ctx)
744{
706 nlohmann::json bootMode;
707 uint8_t mode = data[0];
708 int i;
709
710 bootMode["UEFI"] = (mode & BOOT_MODE_UEFI ? true : false);
711 bootMode["CMOS_CLR"] = (mode & BOOT_MODE_CMOS_CLR ? true : false);
712 bootMode["FORCE_BOOT"] = (mode & BOOT_MODE_FORCE_BOOT ? true : false);
713 bootMode["BOOT_FLAG"] = (mode & BOOT_MODE_BOOT_FLAG ? true : false);

--- 46 unchanged lines hidden (view full) ---

760}
761
762//----------------------------------------------------------------------
763// Get Boot Order (CMD_OEM_GET_BOOT_ORDER)
764//----------------------------------------------------------------------
765ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
766 ipmiOemGetBootOrder(ipmi::Context::ptr ctx)
767{
745 uint8_t bootOption, bootOrder;
746 uint8_t bootSeq[SIZE_BOOT_ORDER];
747 uint8_t mode = 0;
748
749 std::optional<size_t> hostId = ipmi::boot::findHost(ctx->hostIdx);
750
751 if (!hostId)
752 {
753 phosphor::logging::log<phosphor::logging::level::ERR>(

--- 10 unchanged lines hidden (view full) ---

764 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
765 Value variant =
766 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
767 ipmi::boot::bootModeProp);
768
769 auto bootMode = ipmi::boot::Mode::convertModesFromString(
770 std::get<std::string>(variant));
771
768 uint8_t bootSeq[SIZE_BOOT_ORDER];
769 uint8_t mode = 0;
770
771 std::optional<size_t> hostId = ipmi::boot::findHost(ctx->hostIdx);
772
773 if (!hostId)
774 {
775 phosphor::logging::log<phosphor::logging::level::ERR>(

--- 10 unchanged lines hidden (view full) ---

786 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
787 Value variant =
788 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
789 ipmi::boot::bootModeProp);
790
791 auto bootMode = ipmi::boot::Mode::convertModesFromString(
792 std::get<std::string>(variant));
793
772 bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode);
794 uint8_t bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode);
773
774 // GETTING PROPERTY OF SOURCE INTERFACE
775
776 service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
777 variant =
778 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
779 ipmi::boot::bootSourceProp);
780 auto bootSource = ipmi::boot::Source::convertSourcesFromString(
781 std::get<std::string>(variant));
782
795
796 // GETTING PROPERTY OF SOURCE INTERFACE
797
798 service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
799 variant =
800 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
801 ipmi::boot::bootSourceProp);
802 auto bootSource = ipmi::boot::Source::convertSourcesFromString(
803 std::get<std::string>(variant));
804
783 bootOrder = ipmi::boot::sourceDbusToIpmi.at(bootSource);
805 uint8_t bootOrder = ipmi::boot::sourceDbusToIpmi.at(bootSource);
784
806
807 // GETTING PROPERTY OF TYPE INTERFACE
808
809 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
810 variant =
811 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
812 ipmi::boot::bootTypeProp);
813 auto bootType = ipmi::boot::Type::convertTypesFromString(
814 std::get<std::string>(variant));
815
816 uint8_t bootTypeVal = ipmi::boot::typeDbusToIpmi.at(bootType);
817
818 uint8_t bootVal = bootOption | bootTypeVal;
819
785 if (oemData.find(hostName) == oemData.end())
786 {
787 /* Return default boot order 0100090203ff */
788 uint8_t defaultBoot[SIZE_BOOT_ORDER] = {
789 BOOT_MODE_UEFI, bootMap["USB_DEV"], bootMap["NET_IPV6"],
790 bootMap["SATA_HDD"], bootMap["SATA_CD"], 0xff};
791
792 memcpy(bootSeq, defaultBoot, SIZE_BOOT_ORDER);

--- 18 unchanged lines hidden (view full) ---

811 std::string seqStr = oemData[hostName][KEY_BOOT_SEQ][i - 1];
812 if (bootMap.find(seqStr) != bootMap.end())
813 bootSeq[i] = bootMap[seqStr];
814 else
815 bootSeq[i] = 0xff;
816 }
817 }
818
820 if (oemData.find(hostName) == oemData.end())
821 {
822 /* Return default boot order 0100090203ff */
823 uint8_t defaultBoot[SIZE_BOOT_ORDER] = {
824 BOOT_MODE_UEFI, bootMap["USB_DEV"], bootMap["NET_IPV6"],
825 bootMap["SATA_HDD"], bootMap["SATA_CD"], 0xff};
826
827 memcpy(bootSeq, defaultBoot, SIZE_BOOT_ORDER);

--- 18 unchanged lines hidden (view full) ---

846 std::string seqStr = oemData[hostName][KEY_BOOT_SEQ][i - 1];
847 if (bootMap.find(seqStr) != bootMap.end())
848 bootSeq[i] = bootMap[seqStr];
849 else
850 bootSeq[i] = 0xff;
851 }
852 }
853
819 return ipmi::responseSuccess(bootOption, bootOrder, bootSeq[2], bootSeq[3],
854 return ipmi::responseSuccess(bootVal, bootOrder, bootSeq[2], bootSeq[3],
820 bootSeq[4], bootSeq[5]);
821}
822// Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO)
823//----------------------------------------------------------------------
824ipmi_ret_t ipmiOemSetMachineCfgInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
825 ipmi_request_t request,
826 ipmi_response_t response,
827 ipmi_data_len_t data_len,

--- 1105 unchanged lines hidden ---
855 bootSeq[4], bootSeq[5]);
856}
857// Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO)
858//----------------------------------------------------------------------
859ipmi_ret_t ipmiOemSetMachineCfgInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
860 ipmi_request_t request,
861 ipmi_response_t response,
862 ipmi_data_len_t data_len,

--- 1105 unchanged lines hidden ---