blob: 9dbabac2040214b914e361f11e7fa772f976f5f9 [file] [log] [blame]
Patrick Venture54c3b532018-08-01 11:45:49 -07001/*
Patrick Venture514f6482018-08-07 14:27:58 -07002 * Copyright 2018 Google Inc.
Patrick Venture54c3b532018-08-01 11:45:49 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "flash-ipmi.hpp"
18
Patrick Venture8ec019f2018-08-07 11:22:33 -070019#include <cstdio>
20#include <phosphor-logging/log.hpp>
21
22using namespace phosphor::logging;
23
24namespace
25{
26
27/**
28 * Close a file pointer and set to null.
29 *
30 * @param[in] fd a pointer to your file handle.
31 */
32void closeFile(std::FILE** fd)
33{
34 if (!fd)
35 {
36 return;
37 }
38
39 if (*fd)
40 {
41 std::fclose(*fd);
42 (*fd) = nullptr;
43 }
44}
45}
46
47void FlashUpdate::closeEverything()
48{
49 closeFile(&flashFd);
50}
51
52FlashUpdate::~FlashUpdate()
53{
54 /* Close without deleting. This object can only be destroyed if the ipmi
55 * daemon unloads it, by closing down. In this event, we want the verified
56 * file to live on.
57 */
58 closeEverything();
59}
60
Patrick Venture54c3b532018-08-01 11:45:49 -070061void FlashUpdate::abortEverything()
62{
Patrick Venture8ec019f2018-08-07 11:22:33 -070063 closeEverything();
64
65 /* TODO: And now delete everything */
Patrick Venture54c3b532018-08-01 11:45:49 -070066 return;
67}
68
69bool FlashUpdate::openEverything()
70{
Patrick Venture8ec019f2018-08-07 11:22:33 -070071 flashFd = std::fopen(tmpPath.c_str(), "w");
72 if (flashFd == nullptr)
73 {
74 log<level::INFO>("Unable to open staging path",
75 entry("PATH=%s", tmpPath.c_str()));
76 return false;
77 }
78
Patrick Venture54c3b532018-08-01 11:45:49 -070079 return true;
80}
81
82/* Prepare to receive a BMC image and then a signature. */
Patrick Venture8ec019f2018-08-07 11:22:33 -070083bool FlashUpdate::start(uint32_t length)
Patrick Venture54c3b532018-08-01 11:45:49 -070084{
Patrick Venture54c3b532018-08-01 11:45:49 -070085 /* Close out and delete everything. */
86 abortEverything();
87
Patrick Venture8ec019f2018-08-07 11:22:33 -070088 /* TODO: Validate request->length */
89 flashLength = length;
90
Patrick Venture54c3b532018-08-01 11:45:49 -070091 /* Start over! */
92 return openEverything();
93}
Patrick Venture79e131f2018-08-01 13:34:35 -070094
95bool FlashUpdate::flashData(uint32_t offset, const std::vector<uint8_t>& bytes)
96{
97 /* TODO: implement. */
98 return false;
99}
Patrick Venture2c1205d2018-08-03 10:23:14 -0700100
101bool FlashUpdate::flashFinish()
102{
103 /* TODO: implement. */
104 return false;
105}
Patrick Venture8d9f7322018-08-03 10:39:13 -0700106
107bool FlashUpdate::startHash(uint32_t length)
108{
109 /* TODO: implement. */
110 return false;
111}
Patrick Venturecfe66872018-08-03 13:32:33 -0700112
113bool FlashUpdate::hashData(uint32_t offset, const std::vector<uint8_t>& bytes)
114{
115 /* TODO: implement. */
116 return false;
117}
Patrick Venturefbc7d192018-08-03 13:54:21 -0700118
119bool FlashUpdate::hashFinish()
120{
121 /* TODO: implement. */
122 return false;
123}
Patrick Venture1cb87d22018-08-03 18:22:09 -0700124
125bool FlashUpdate::startDataVerification()
126{
127 /* TODO: implement. */
128 return false;
129}
Patrick Venture5c251ca2018-08-03 18:31:01 -0700130
131bool FlashUpdate::abortUpdate()
132{
133 /* TODO: implement. */
134 return false;
135}