Skip to content

Commit 81944ba

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

File tree

5 files changed

+139
-198
lines changed

5 files changed

+139
-198
lines changed

oem/ibm/libpldmresponder/file_io.cpp

+29-5
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int DMA::transferHostDataToSocket(int fd, uint32_t length, uint64_t address)
7878
rc = write(xdmaFd, &xdmaOp, sizeof(xdmaOp));
7979
if (rc < 0)
8080
{
81-
rc = -errno;
81+
rc = errno;
8282
std::cerr
8383
<< "transferHostDataToSocket : Failed to execute the DMA operation, RC="
8484
<< rc << " ADDRESS=" << address << " LENGTH=" << length << "\n";
@@ -99,10 +99,16 @@ int DMA::transferHostDataToSocket(int fd, uint32_t length, uint64_t address)
9999
}
100100
return rc;
101101
}
102+
103+
rc = writeToUnixSocket(fd, static_cast<const char*>(vgaMemDump), length);
104+
if (rc < 0)
105+
{
106+
std::cerr
107+
<< "transferHostDataToSocket writing To Unix Socket failed. \n";
108+
return -1;
109+
}
102110
rc = length;
103-
std::thread dumpOffloadThread(writeToUnixSocket, fd,
104-
static_cast<const char*>(vgaMemDump), length);
105-
dumpOffloadThread.detach();
111+
106112
return rc;
107113
}
108114

@@ -187,10 +193,28 @@ int32_t DMA::transferDataHost(int fd, uint32_t offset, uint32_t length,
187193
xdmaOp.upstream = upstream ? 1 : 0;
188194
xdmaOp.hostAddr = address;
189195
xdmaOp.len = length;
196+
197+
// int retry = 0;
198+
199+
// do
200+
// {
190201
rc = write(xdmaFd, &xdmaOp, sizeof(xdmaOp));
202+
// std::cout << "KK total length of write0 from DMA:" << length
203+
// << " read out of total length rc:" << rc << " offset:" <<
204+
// offset
205+
// << " address:" << address << "\n";
206+
// if (rc > 0)
207+
// {
208+
// break;
209+
// }
210+
// retry++;
211+
// std::cout << "KK write0 retry:" << retry << " errno:" << errno <<
212+
// "\n"; usleep(1000000);
213+
// } while (retry < 3);
214+
191215
if (rc < 0)
192216
{
193-
rc = -errno;
217+
rc = errno;
194218
std::cerr
195219
<< "transferDataHost : Failed to execute the DMA operation, RC="
196220
<< rc << " UPSTREAM=" << upstream << " ADDRESS=" << address

oem/ibm/libpldmresponder/file_io_type_dump.cpp

+37-36
Original file line numberDiff line numberDiff line change
@@ -308,42 +308,43 @@ int DumpHandler::writeFromMemory(uint32_t, uint32_t length, uint64_t address,
308308
}
309309

310310
DumpHandler::fd = sock;
311-
grc = transferFileDataToSocket(DumpHandler::fd, length, address,
312-
responseHdr, event);
313-
return grc < 0 ? PLDM_ERROR : PLDM_SUCCESS;
314-
}
315-
316-
if (socketWriteStatus == Error)
317-
{
318-
std::cerr
319-
<< "DumpHandler::writeFromMemory: Error while writing to Unix socket"
320-
<< std::endl;
321-
if (DumpHandler::fd >= 0)
322-
{
323-
close(DumpHandler::fd);
324-
DumpHandler::fd = -1;
325-
}
326-
auto socketInterface = getOffloadUri(fileHandle);
327-
std::remove(socketInterface.c_str());
328-
resetOffloadUri();
329-
Response response(sizeof(pldm_msg_hdr) + responseHdr.command, 0);
330-
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
331-
encode_rw_file_by_type_memory_resp(responseHdr.instance_id,
332-
responseHdr.command, PLDM_ERROR, 0,
333-
responsePtr);
334-
responseHdr.respInterface->sendPLDMRespMsg(response, responseHdr.key);
335-
return PLDM_ERROR;
336-
}
337-
else if (socketWriteStatus == InProgress || socketWriteStatus == NotReady)
338-
{
339-
Response response(sizeof(pldm_msg_hdr) + responseHdr.command, 0);
340-
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
341-
encode_rw_file_by_type_memory_resp(
342-
responseHdr.instance_id, responseHdr.command, PLDM_ERROR_NOT_READY,
343-
0, responsePtr);
344-
responseHdr.respInterface->sendPLDMRespMsg(response, responseHdr.key);
345-
return PLDM_ERROR_NOT_READY;
346-
}
311+
// grc = transferFileDataToSocket(DumpHandler::fd, length, address,
312+
// responseHdr, event);
313+
// return grc < 0 ? PLDM_ERROR : PLDM_SUCCESS;
314+
}
315+
316+
/* if (socketWriteStatus == Error)
317+
{
318+
std::cerr
319+
<< "DumpHandler::writeFromMemory: Error while writing to Unix
320+
socket"
321+
<< std::endl;
322+
if (DumpHandler::fd >= 0)
323+
{
324+
close(DumpHandler::fd);
325+
DumpHandler::fd = -1;
326+
}
327+
auto socketInterface = getOffloadUri(fileHandle);
328+
std::remove(socketInterface.c_str());
329+
resetOffloadUri();
330+
Response response(sizeof(pldm_msg_hdr) + responseHdr.command, 0);
331+
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
332+
encode_rw_file_by_type_memory_resp(responseHdr.instance_id,
333+
responseHdr.command, PLDM_ERROR, 0,
334+
responsePtr);
335+
responseHdr.respInterface->sendPLDMRespMsg(response, responseHdr.key);
336+
return PLDM_ERROR;
337+
}
338+
else if (socketWriteStatus == InProgress || socketWriteStatus == NotReady)
339+
{
340+
Response response(sizeof(pldm_msg_hdr) + responseHdr.command, 0);
341+
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
342+
encode_rw_file_by_type_memory_resp(
343+
responseHdr.instance_id, responseHdr.command, PLDM_ERROR_NOT_READY,
344+
length, responsePtr);
345+
responseHdr.respInterface->sendPLDMRespMsg(response, responseHdr.key);
346+
return PLDM_ERROR_NOT_READY;
347+
}*/
347348

348349
grc = transferFileDataToSocket(DumpHandler::fd, length, address,
349350
responseHdr, event);

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)