Skip to content

Commit 30ec2f3

Browse files
Merge branch '1050' of github.com:Patel-Kamalkumar/pldm into AIO
2 parents 3434379 + 3602a53 commit 30ec2f3

File tree

1 file changed

+64
-148
lines changed

1 file changed

+64
-148
lines changed

oem/ibm/libpldmresponder/inband_code_update.cpp

+64-148
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,15 @@ auto updateDirPath = fs::path(LID_STAGING_DIR) / "update";
3333
/** @brief The file name of the code update tarball */
3434
constexpr auto tarImageName = "image.tar";
3535

36-
/** @brief The file name of the hostfw image */
37-
constexpr auto hostfwImageName = "image-hostfw";
36+
/** @brief The path to the code update tarball file */
37+
auto tarImagePath = fs::path(imageDirPath) / tarImageName;
3838

3939
/** @brief The filename of the file where bootside data will be saved */
4040
constexpr auto bootSideFileName = "bootSide";
4141

4242
constexpr auto bootSideAttrName = "fw_boot_side_current";
4343
constexpr auto bootNextSideAttrName = "fw_boot_side";
4444

45-
/** @brief The path to the code update tarball file */
46-
auto tarImagePath = fs::path(imageDirPath) / tarImageName;
47-
48-
/** @brief The path to the hostfw image */
49-
auto hostfwImagePath = fs::path(imageDirPath) / hostfwImageName;
50-
51-
/** @brief The path to the tarball file expected by the phosphor software
52-
* manager */
53-
auto updateImagePath = fs::path("/tmp/images") / tarImageName;
54-
5545
/** @brief The filepath of file where bootside data will be saved */
5646
auto bootSideDirPath = fs::path("/var/lib/pldm/") / bootSideFileName;
5747

@@ -328,6 +318,47 @@ void CodeUpdate::setVersions()
328318
"xyz.openbmc_project.Software.Activation";
329319
auto imageObjPath = path.str.c_str();
330320

321+
// If the version interface is added with the Activation
322+
// value as Invalid, it is considered as assemble code
323+
// update image failure.
324+
// Failure is occured while assembling
325+
// lid files or while creating a tar ball.
326+
327+
try
328+
{
329+
auto propVal =
330+
pldm::utils::DBusHandler().getDbusPropertyVariant(
331+
imageObjPath, "Activation", imageInterface);
332+
const auto& activation = std::get<std::string>(propVal);
333+
334+
if (activation ==
335+
"xyz.openbmc_project.Software.Activation.Activations.Invalid")
336+
{
337+
if (isCodeUpdateInProgress())
338+
{
339+
std::cerr
340+
<< "InbandCodeUpdate Failed: Received Invalid Signal, Sending "
341+
<< "Error on End update sensor event "
342+
<< "to PHYP\n";
343+
setCodeUpdateProgress(false);
344+
auto sensorId = getFirmwareUpdateSensor();
345+
sendStateSensorEvent(
346+
sensorId, PLDM_STATE_SENSOR_STATE, 0,
347+
uint8_t(CodeUpdateState::FAIL),
348+
uint8_t(CodeUpdateState::START));
349+
break;
350+
}
351+
}
352+
}
353+
catch (const std::exception& e)
354+
{
355+
std::cerr
356+
<< "Code Update: Error getting Activation property, PATH="
357+
<< imageObjPath << "INTERFACE=" << imageInterface
358+
<< "PROPERTY="
359+
<< "Activation"
360+
<< "ERROR=" << e.what() << "\n";
361+
}
331362
try
332363
{
333364
nonRunningVersion = path.str;
@@ -758,148 +789,33 @@ int processCodeUpdateLid(const std::string& filePath)
758789

759790
int CodeUpdate::assembleCodeUpdateImage()
760791
{
761-
pid_t pid = fork();
762-
763-
if (pid == 0)
764-
{
765-
pid_t nextPid = fork();
766-
if (nextPid == 0)
767-
{
768-
auto rc = 0;
769-
// Create the hostfw squashfs image from the LID files without
770-
// header
771-
try
772-
{
773-
rc = executeCmd("/usr/sbin/mksquashfs", lidDirPath.c_str(),
774-
hostfwImagePath.c_str(), "-all-root",
775-
"-no-recovery", "-no-xattrs", "-noI",
776-
"-mkfs-time", "0", "-all-time", "0");
777-
if (rc < 0)
778-
{
779-
std::cerr << "Error occurred during the mksqusquashfs call"
780-
<< std::endl;
781-
setCodeUpdateProgress(false);
782-
auto sensorId = getFirmwareUpdateSensor();
783-
sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0,
784-
uint8_t(CodeUpdateState::FAIL),
785-
uint8_t(CodeUpdateState::START));
786-
exit(EXIT_FAILURE);
787-
}
788-
}
789-
catch (const std::exception& e)
790-
{
791-
std::cerr << "Failed during the mksqusquashfs call, "
792-
"ERROR="
793-
<< e.what() << "\n";
794-
return PLDM_ERROR;
795-
}
796-
797-
fs::create_directories(updateDirPath);
798-
799-
// Extract the BMC tarball content
800-
try
801-
{
802-
rc = executeCmd("/bin/tar", "-xf", tarImagePath.c_str(), "-C",
803-
updateDirPath);
804-
if (rc < 0)
805-
{
806-
setCodeUpdateProgress(false);
807-
auto sensorId = getFirmwareUpdateSensor();
808-
sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0,
809-
uint8_t(CodeUpdateState::FAIL),
810-
uint8_t(CodeUpdateState::START));
811-
exit(EXIT_FAILURE);
812-
}
813-
}
814-
catch (const std::exception& e)
815-
{
816-
std::cerr << "Failed to Extract the BMC tarball content, "
817-
"ERROR="
818-
<< e.what() << "\n";
819-
return PLDM_ERROR;
820-
}
821-
822-
// Add the hostfw image to the directory where the contents were
823-
// extracted
824-
fs::copy_file(hostfwImagePath,
825-
fs::path(updateDirPath) / hostfwImageName,
826-
fs::copy_options::overwrite_existing);
827-
828-
// Remove the tarball file, then re-generate it with so that the
829-
// hostfw image becomes part of the tarball
830-
fs::remove(tarImagePath);
831-
try
832-
{
833-
rc = executeCmd("/bin/tar", "-cf", tarImagePath, ".", "-C",
834-
updateDirPath);
835-
if (rc < 0)
836-
{
837-
std::cerr
838-
<< "Error occurred during the generation of the tarball"
839-
<< std::endl;
840-
setCodeUpdateProgress(false);
841-
auto sensorId = getFirmwareUpdateSensor();
842-
sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0,
843-
uint8_t(CodeUpdateState::FAIL),
844-
uint8_t(CodeUpdateState::START));
845-
exit(EXIT_FAILURE);
846-
}
847-
}
848-
catch (const std::exception& e)
849-
{
850-
std::cerr
851-
<< "Failed to Remove the tarball file, then re-generate it, "
852-
"ERROR="
853-
<< e.what() << "\n";
854-
return PLDM_ERROR;
855-
}
856-
857-
// Copy the tarball to the update directory to trigger the
858-
// phosphor software manager to create a version interface
859-
fs::copy_file(tarImagePath, updateImagePath,
860-
fs::copy_options::overwrite_existing);
861-
862-
// Cleanup
863-
fs::remove_all(updateDirPath);
864-
fs::remove_all(lidDirPath);
865-
fs::remove_all(imageDirPath);
792+
static constexpr auto UPDATER_SERVICE =
793+
"xyz.openbmc_project.Software.BMC.Updater";
794+
static constexpr auto SOFTWARE_PATH = "/xyz/openbmc_project/software";
795+
static constexpr auto LID_INTERFACE = "xyz.openbmc_project.Software.LID";
866796

867-
exit(EXIT_SUCCESS);
868-
}
869-
else if (nextPid < 0)
870-
{
871-
std::cerr << "Error occurred during fork. ERROR=" << errno
872-
<< std::endl;
873-
exit(EXIT_FAILURE);
874-
}
797+
auto& bus = dBusIntf->getBus();
875798

876-
// Do nothing as parent. When parent exits, child will be reparented
877-
// under init and be reaped properly.
878-
exit(0);
879-
}
880-
else if (pid > 0)
799+
try
881800
{
882-
int status;
883-
if (waitpid(pid, &status, 0) < 0)
884-
{
885-
std::cerr << "Error occurred during waitpid. ERROR=" << errno
886-
<< std::endl;
887-
return PLDM_ERROR;
888-
}
889-
else if (WEXITSTATUS(status) != 0)
890-
{
891-
std::cerr
892-
<< "Failed to execute the assembling of the image. STATUS="
893-
<< status << std::endl;
894-
return PLDM_ERROR;
895-
}
801+
std::cout << "InbandCodeUpdate: AssembleCodeUpdateImage \n";
802+
auto method =
803+
bus.new_method_call(UPDATER_SERVICE, SOFTWARE_PATH, LID_INTERFACE,
804+
"AssembleCodeUpdateImage");
805+
bus.call_noreply(method);
896806
}
897-
else
807+
catch (const std::exception& e)
898808
{
899-
std::cerr << "Error occurred during fork. ERROR=" << errno << std::endl;
900-
return PLDM_ERROR;
809+
std::cerr
810+
<< "InbandCodeUpdate: Failed to Assemble code update image ERROR="
811+
<< e.what() << "\n";
812+
setCodeUpdateProgress(false);
813+
auto sensorId = getFirmwareUpdateSensor();
814+
sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0,
815+
uint8_t(CodeUpdateState::FAIL),
816+
uint8_t(CodeUpdateState::START));
817+
return -1;
901818
}
902-
903819
return PLDM_SUCCESS;
904820
}
905821

0 commit comments

Comments
 (0)