本文共 5864 字,大约阅读时间需要 19 分钟。
REDFISH UPDATE FIRMWARE
Author | Date | Version | Comment |
---|---|---|---|
zhangjian38 | 2020-3-23 | v0.1 | Init version |
zhangjian38 | 2020-3-26 | v0.2 |
文章目录
1. Update SOP
More details please refer to MegaRAC Redfish - API Doc (v1.7)
1.1 Upload image file
-
-
URI :
https://$ip/redfish/v1/UpdateService/Actions/Oem/UpdateService.UploadFirmwareImage
-
Method :
POST
-
Body : type
form-data
, value"Key":"image_file ", "Value":"<image_file_path>"
Note : This method use local file, not include transfer by ftp or http server
-
1.2 Start Update
-
-
URI :
https://$ip/redfish/v1/UpdateService/Actions/Oem/UpdateService.BMCFwUpdate
-
Method :
POST
-
Body : type
JSON(application/json)
, value{"FlashType":"FULLFwUpdate","UploadSelector":"Default"}
Note : The details about FlashType and UploadSelector Please refet to MegaRAC Redfish - API Doc (v1.7) 3.65.3.3
-
2. Key Code Flow
packages:
update_service_redfish_extension-src
libredfishflash-src
gami_bmc_update_module-src
2.1 Upload image file
-
URI Define File :
update_service_redfish_extension-6.56.0.0.0-src/data/app/RTP_1_5/extensions/redfish-resource/updateservice/redfish-resource-URI_pattern.lua
local URI_pattern = { { key = "updateservice_upload_action", pattern = "^" .. CONFIG.SERVICE_PREFIX .. "/UpdateService/(Actions)/(Oem)/(UpdateService.UploadFirmwareImage)$"}, ...}
-
Handler Define File :
update_service_redfish_extension-6.56.0.0.0-src/data/app/RTP_1_5/extensions/redfish-resource/updateservice/redfish-resource-handler.lua
local UploadFileHandler = require("redfish.upload-file")...local handler_table = { updateservice_upload_action = UploadFileHandler,...}
-
Handle Invoke :
- When Upload image file, UploadFileHandler:post will be invoked, in file
upload-file.lua
function UploadFileHandler:post(target, info, action) ...end
-
Judge that the URL parameter is valid ([There’s](javascript:😉 [nothing](javascript:😉 [to](javascript:😉 [say](javascript:😉 )
-
Wirte image to
/tmp/redfishfwupdate/rom.ima
function UploadFileHandler:post(target, info, action) ... local redis = self:get_db() local IsSignedImage = "Redfish:UpdateService:Oem:AMI:BMC:UploadedImageFormat" if string.match(fname, '(.-%.ima_enc)$') then coroutine.yield(redis:set(IsSignedImage, "signed")) else coroutine.yield(redis:set(IsSignedImage, "unsigned")) end local tmp_name = "/tmp/redfishfwupdate/" local f = io.open(tmp_name .. "rom.ima", "w") f:write(parsed_body) f:close() local fwupdate_in_progress = "Redfish:UpdateService:Oem:AMI:BMC:FWUpdateInProgress" local image_path = tmp_name .. "rom.ima" coroutine.yield(redis:set(fwupdate_in_progress, image_path)) ...end
- When Upload image file, UploadFileHandler:post will be invoked, in file
2.2 Start Update
-
**URI and Handler Define ** was same as 2.1 Upload image file
-
Handle Invoke :
-
When start update, UpdateServiceHandler:post will be invoked, in file
update-service.lua
Note : This Handler Cotains simple update and ami oem update, Now ,I only focus on oem update
function UpdateServiceHandler:post(target, info, action)...end
-
Judge that the URL parameter is valid ([There’s](javascript:😉 [nothing](javascript:😉 [to](javascript:😉 [say](javascript:😉 )
-
Invoke
function flashBMC()
a. Find Image File
local imagefile=io.popen("ls /tmp/redfishfwupdate/")local uploadedimage=imagefile:read("*a")imagefile:close()if string.find(uploadedimage,"rom.ima") == nil then self:error_action_requires_file()end
b. Set update parameter .
local FlashType = request_data.FlashTypelocal UploadSelector = request_data.UploadSelector
c. Checking ActiveImage and InactivedImage
d. Start update, create a file and set redis for update.
os.execute("touch "..FLASHER_START_FILE)local redis_action_key = "POST:Redfish:UpdateService:OemAction:StartFwUpdate:BMC" yield(redis:set(redis_action_key, turbo.escape.json_encode(request_data)))
-
package :
gami_bmc_update_module-src
,FwUpdate.lua
,functionFwUpdate.StartFwUpdate = function(group_name)
will be invoked.TODO : I don’t know why and how this function will be invokedNote : Why this this function will be invoked, please refer to doc “REDIS 2 FUNCTION HANDLER”
FwUpdate.StartFwUpdate = function(group_name) ... wRet = FwUpdate.UpdateFw_BMC(reqdata) ...end
In function
UpdateFw_BMC
a. Set to FlashMode
libipmi_update.updateservice:set_flashmode()
CALL LIB REDFISH FLASH(libredfishflash-src
)**This lib will sending a command to `/var/pipe/flasher_cmd`** ```lua function updateservice:set_flashmode() os.execute("echo '0' > "..FLASHER_FLASHPercent_FILE) local dual_image_support = updateservice:checkDualImageSupport() local wRet = flashlibrary.PrepareFlashArea(FLSH_CMD_PREP_TFTP_FLASH_AREA, dual_image_support) end ```
b. Download Image from Remote Path
```lua wRet = libipmi_update.updateservice:download_image() ``` Copy File to /mnt/fwupdate ```lua function updateservice:download_image() os.execute("touch "..FLASHER_DOWNLOAD_FILE) print("Uploading Image from /tmp/redfishfwupdate/ to /mnt/fwupdate/") local cmd = "cp /tmp/redfishfwupdate/rom.ima /mnt/fwupdate/rom.ima" local wRet = os.execute("echo '"..cmd.."'> /tmp/downloadimage_redfish.pid | "..cmd) end ```
c. Verify Image, CALL LIB REDFISH FLASH
```lua function updateservice:verifyimage_bmc(flashtype) wRet = flashlibrary.VerifyFirmwareImage(VeriInfo[0], section_info[0], section_count) end ```
d. Flash Image
lua wRet = libipmi_update.updateservice:startflash_bmc(flashtype, parameter)
CALL LIB REDFISH FLASH LIB REDFISH FLASH Function `StartImageFlash`, send cmd to `"/var/pipe/flasher_cmd"` ```c int StartImageFlash (unsigned char PreserveCfg, unsigned char ResetBMC,unsigned char FlashType,void *SectionName,INT8U MaxSectionCount) { FlasherCmd Cmd; Cmd.Command = REDFISH_FLASH_CMD_START_FLASH; SendCmdExpectNoReply(Cmd); } ``` Get Progress ```lua ProgressState = flashlibrary.GetFlashProgress(flprog) local Progress = ffi.string(flprog.Progress, ffi.sizeof(flprog.Progress)) Progress = string.match(Progress, "(%d+)") ```
-
转载地址:https://blog.csdn.net/qq_32030453/article/details/105221204 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!