Andrew Jeffery | 4fe996c | 2018-02-27 12:16:48 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 3 | #include "pnor_partition_table.hpp" |
| 4 | #include "common.h" |
| 5 | #include "config.h" |
Andrew Jeffery | 26558db | 2018-08-10 00:22:38 +0930 | [diff] [blame] | 6 | #include "mboxd.h" |
Deepak Kodihalli | 8a89969 | 2017-07-11 23:17:19 -0500 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Common/error.hpp" |
| 8 | #include <phosphor-logging/elog-errors.hpp> |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 9 | #include <syslog.h> |
| 10 | #include <endian.h> |
| 11 | #include <regex> |
| 12 | #include <fstream> |
| 13 | #include <algorithm> |
| 14 | |
| 15 | namespace openpower |
| 16 | { |
| 17 | namespace virtual_pnor |
| 18 | { |
| 19 | |
Deepak Kodihalli | 8a89969 | 2017-07-11 23:17:19 -0500 | [diff] [blame] | 20 | using namespace phosphor::logging; |
| 21 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 22 | |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 23 | namespace partition |
| 24 | { |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 25 | |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 26 | Table::Table(const struct mbox_context* ctx) : |
| 27 | szBytes(sizeof(pnor_partition_table)), numParts(0), |
| 28 | blockSize(1 << ctx->erase_size_shift), pnorSize(ctx->flash_size) |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 29 | { |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 30 | preparePartitions(ctx); |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 31 | prepareHeader(); |
| 32 | hostTbl = endianFixup(tbl); |
| 33 | } |
| 34 | |
| 35 | void Table::prepareHeader() |
| 36 | { |
| 37 | decltype(auto) table = getNativeTable(); |
| 38 | table.data.magic = PARTITION_HEADER_MAGIC; |
| 39 | table.data.version = PARTITION_VERSION_1; |
Andrew Jeffery | 7f9c343 | 2018-03-01 12:07:13 +1030 | [diff] [blame] | 40 | table.data.size = blocks(); |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 41 | table.data.entry_size = sizeof(pnor_partition); |
| 42 | table.data.entry_count = numParts; |
Deepak Kodihalli | d1d7930 | 2017-07-11 23:01:39 -0500 | [diff] [blame] | 43 | table.data.block_size = blockSize; |
| 44 | table.data.block_count = pnorSize / blockSize; |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 45 | table.checksum = details::checksum(table.data); |
| 46 | } |
| 47 | |
| 48 | inline void Table::allocateMemory(const fs::path& tocFile) |
| 49 | { |
| 50 | size_t num = 0; |
| 51 | std::string line; |
| 52 | std::ifstream file(tocFile.c_str()); |
| 53 | |
| 54 | // Find number of lines in partition file - this will help |
| 55 | // determine the number of partitions and hence also how much |
| 56 | // memory to allocate for the partitions array. |
| 57 | // The actual number of partitions may turn out to be lesser than this, |
| 58 | // in case of errors. |
| 59 | while (std::getline(file, line)) |
| 60 | { |
| 61 | // Check if line starts with "partition" |
| 62 | if (std::string::npos != line.find("partition", 0)) |
| 63 | { |
| 64 | ++num; |
| 65 | } |
| 66 | } |
| 67 | |
Andrew Jeffery | 7f9c343 | 2018-03-01 12:07:13 +1030 | [diff] [blame] | 68 | szBytes = sizeof(pnor_partition_table) + (num * sizeof(pnor_partition)); |
| 69 | tbl.resize(capacity()); |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 72 | void Table::preparePartitions(const struct mbox_context* ctx) |
Andrew Jeffery | 581a4f2 | 2018-02-21 15:29:38 +1030 | [diff] [blame] | 73 | { |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 74 | const fs::path roDir = ctx->paths.ro_loc; |
| 75 | const fs::path patchDir = ctx->paths.patch_loc; |
| 76 | fs::path tocFile = roDir / PARTITION_TOC_FILE; |
Andrew Jeffery | 581a4f2 | 2018-02-21 15:29:38 +1030 | [diff] [blame] | 77 | allocateMemory(tocFile); |
| 78 | |
| 79 | std::ifstream file(tocFile.c_str()); |
| 80 | std::string line; |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 81 | decltype(auto) table = getNativeTable(); |
| 82 | |
| 83 | while (std::getline(file, line)) |
| 84 | { |
Andrew Jeffery | faaa71c | 2018-02-21 16:29:48 +1030 | [diff] [blame] | 85 | pnor_partition& part = table.partitions[numParts]; |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 86 | fs::path patch; |
Andrew Jeffery | faaa71c | 2018-02-21 16:29:48 +1030 | [diff] [blame] | 87 | fs::path file; |
| 88 | |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 89 | // The ToC file presented in the vpnor squashfs looks like: |
| 90 | // |
| 91 | // version=IBM-witherspoon-ibm-OP9_v1.19_1.135 |
| 92 | // extended_version=op-build-v1.19-571-g04f4690-dirty,buildroot-2017.11-5-g65679be,skiboot-v5.10-rc4,hostboot-4c46d66,linux-4.14.20-openpower1-p4a6b675,petitboot-v1.6.6-pe5aaec2,machine-xml-0fea226,occ-3286b6b,hostboot-binaries-3d1af8f,capp-ucode-p9-dd2-v3,sbe-99e2fe2 |
| 93 | // partition00=part,0x00000000,0x00002000,00,READWRITE |
| 94 | // partition01=HBEL,0x00008000,0x0002c000,00,ECC,REPROVISION,CLEARECC,READWRITE |
| 95 | // ... |
| 96 | // |
| 97 | // As such we want to skip any lines that don't begin with 'partition' |
| 98 | if (std::string::npos == line.find("partition", 0)) |
Andrew Jeffery | faaa71c | 2018-02-21 16:29:48 +1030 | [diff] [blame] | 99 | { |
| 100 | continue; |
| 101 | } |
| 102 | |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 103 | parseTocLine(line, blockSize, part); |
| 104 | |
Andrew Jeffery | 4ca1aa5 | 2018-03-02 12:08:29 +1030 | [diff] [blame] | 105 | if (numParts > 0) |
| 106 | { |
| 107 | struct pnor_partition& prev = table.partitions[numParts - 1]; |
| 108 | uint32_t prev_end = prev.data.base + prev.data.size; |
| 109 | |
| 110 | if (part.data.id == prev.data.id) |
| 111 | { |
| 112 | MSG_ERR("ID for previous partition '%s' at block 0x%" PRIx32 |
| 113 | "matches current partition '%s' at block 0x%" PRIx32 |
| 114 | ": %" PRId32 "\n", |
| 115 | prev.data.name, prev.data.base, part.data.name, |
| 116 | part.data.base, part.data.id); |
| 117 | } |
| 118 | |
| 119 | if (part.data.base < prev_end) |
| 120 | { |
| 121 | std::stringstream err; |
| 122 | err << "Partition '" << part.data.name << "' start block 0x" |
| 123 | << std::hex << part.data.base << "is less than the end " |
| 124 | << "block 0x" << std::hex << prev_end << " of '" |
| 125 | << prev.data.name << "'"; |
| 126 | throw InvalidTocEntry(err.str()); |
| 127 | } |
| 128 | } |
| 129 | |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 130 | file = roDir / part.data.name; |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 131 | if (!fs::exists(file)) |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 132 | { |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 133 | std::stringstream err; |
| 134 | err << "Partition file " << file.native() << " does not exist"; |
| 135 | throw InvalidTocEntry(err.str()); |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 136 | } |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 137 | |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 138 | patch = patchDir / part.data.name; |
| 139 | if (fs::is_regular_file(patch)) |
| 140 | { |
| 141 | const size_t size = part.data.size * blockSize; |
| 142 | part.data.actual = |
| 143 | std::min(size, static_cast<size_t>(fs::file_size(patch))); |
| 144 | } |
| 145 | |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 146 | ++numParts; |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | const pnor_partition& Table::partition(size_t offset) const |
| 151 | { |
| 152 | const decltype(auto) table = getNativeTable(); |
Andrew Jeffery | bd38c21 | 2018-02-27 17:44:33 +1030 | [diff] [blame] | 153 | size_t blockOffset = offset / blockSize; |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 154 | |
| 155 | for (decltype(numParts) i{}; i < numParts; ++i) |
| 156 | { |
Andrew Jeffery | cd92851 | 2018-02-28 22:33:48 +1030 | [diff] [blame] | 157 | const struct pnor_partition& part = table.partitions[i]; |
Andrew Jeffery | 1a3f843 | 2018-03-02 10:18:02 +1030 | [diff] [blame] | 158 | size_t len = part.data.size; |
| 159 | |
Andrew Jeffery | cd92851 | 2018-02-28 22:33:48 +1030 | [diff] [blame] | 160 | if ((blockOffset >= part.data.base) && |
Andrew Jeffery | 1a3f843 | 2018-03-02 10:18:02 +1030 | [diff] [blame] | 161 | (blockOffset < (part.data.base + len))) |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 162 | { |
Andrew Jeffery | cd92851 | 2018-02-28 22:33:48 +1030 | [diff] [blame] | 163 | return part; |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 164 | } |
Andrew Jeffery | ae1edb9 | 2018-02-28 23:16:48 +1030 | [diff] [blame] | 165 | |
| 166 | /* Are we in a hole between partitions? */ |
| 167 | if (blockOffset < part.data.base) |
| 168 | { |
| 169 | throw UnmappedOffset(offset, part.data.base * blockSize); |
| 170 | } |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 171 | } |
| 172 | |
Andrew Jeffery | ae1edb9 | 2018-02-28 23:16:48 +1030 | [diff] [blame] | 173 | throw UnmappedOffset(offset, pnorSize); |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 174 | } |
| 175 | |
Deepak Kodihalli | 8a89969 | 2017-07-11 23:17:19 -0500 | [diff] [blame] | 176 | const pnor_partition& Table::partition(const std::string& name) const |
| 177 | { |
| 178 | const decltype(auto) table = getNativeTable(); |
| 179 | |
| 180 | for (decltype(numParts) i{}; i < numParts; ++i) |
| 181 | { |
| 182 | if (name == table.partitions[i].data.name) |
| 183 | { |
| 184 | return table.partitions[i]; |
| 185 | } |
| 186 | } |
| 187 | |
Andrew Jeffery | ae1edb9 | 2018-02-28 23:16:48 +1030 | [diff] [blame] | 188 | std::stringstream err; |
| 189 | err << "Partition " << name << " is not listed in the table of contents"; |
| 190 | throw UnknownPartition(err.str()); |
Deepak Kodihalli | 8a89969 | 2017-07-11 23:17:19 -0500 | [diff] [blame] | 191 | } |
| 192 | |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 193 | } // namespace partition |
| 194 | |
| 195 | PartitionTable endianFixup(const PartitionTable& in) |
| 196 | { |
| 197 | PartitionTable out; |
| 198 | out.resize(in.size()); |
| 199 | auto src = reinterpret_cast<const pnor_partition_table*>(in.data()); |
| 200 | auto dst = reinterpret_cast<pnor_partition_table*>(out.data()); |
| 201 | |
| 202 | dst->data.magic = htobe32(src->data.magic); |
| 203 | dst->data.version = htobe32(src->data.version); |
| 204 | dst->data.size = htobe32(src->data.size); |
| 205 | dst->data.entry_size = htobe32(src->data.entry_size); |
| 206 | dst->data.entry_count = htobe32(src->data.entry_count); |
| 207 | dst->data.block_size = htobe32(src->data.block_size); |
| 208 | dst->data.block_count = htobe32(src->data.block_count); |
Deepak Kodihalli | b9cdcd2 | 2017-07-12 08:14:48 -0500 | [diff] [blame] | 209 | dst->checksum = details::checksum(dst->data); |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 210 | |
| 211 | for (decltype(src->data.entry_count) i{}; i < src->data.entry_count; ++i) |
| 212 | { |
| 213 | auto psrc = &src->partitions[i]; |
| 214 | auto pdst = &dst->partitions[i]; |
| 215 | strncpy(pdst->data.name, psrc->data.name, PARTITION_NAME_MAX); |
| 216 | // Just to be safe |
| 217 | pdst->data.name[PARTITION_NAME_MAX] = '\0'; |
| 218 | pdst->data.base = htobe32(psrc->data.base); |
| 219 | pdst->data.size = htobe32(psrc->data.size); |
| 220 | pdst->data.pid = htobe32(psrc->data.pid); |
| 221 | pdst->data.id = htobe32(psrc->data.id); |
| 222 | pdst->data.type = htobe32(psrc->data.type); |
| 223 | pdst->data.flags = htobe32(psrc->data.flags); |
| 224 | pdst->data.actual = htobe32(psrc->data.actual); |
| 225 | for (size_t j = 0; j < PARTITION_USER_WORDS; ++j) |
| 226 | { |
| 227 | pdst->data.user.data[j] = htobe32(psrc->data.user.data[j]); |
| 228 | } |
Deepak Kodihalli | b9cdcd2 | 2017-07-12 08:14:48 -0500 | [diff] [blame] | 229 | pdst->checksum = details::checksum(pdst->data); |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | return out; |
| 233 | } |
| 234 | |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 235 | static inline void writeSizes(pnor_partition& part, size_t start, size_t end, |
| 236 | size_t blockSize) |
| 237 | { |
| 238 | size_t size = end - start; |
| 239 | part.data.base = align_up(start, blockSize) / blockSize; |
| 240 | size_t sizeInBlocks = align_up(size, blockSize) / blockSize; |
| 241 | part.data.size = sizeInBlocks; |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 242 | part.data.actual = size; |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static inline void writeUserdata(pnor_partition& part, uint32_t version, |
| 246 | const std::string& data) |
| 247 | { |
| 248 | std::istringstream stream(data); |
| 249 | std::string flag{}; |
| 250 | auto perms = 0; |
Andrew Jeffery | 0f9fbd6 | 2018-03-02 12:00:42 +1030 | [diff] [blame] | 251 | auto state = 0; |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 252 | |
Andrew Jeffery | 0f9fbd6 | 2018-03-02 12:00:42 +1030 | [diff] [blame] | 253 | MSG_DBG("Parsing ToC flags '%s'\n", data.c_str()); |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 254 | while (std::getline(stream, flag, ',')) |
| 255 | { |
Andrew Jeffery | 0f9fbd6 | 2018-03-02 12:00:42 +1030 | [diff] [blame] | 256 | if (flag == "") |
| 257 | continue; |
| 258 | |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 259 | if (flag == "ECC") |
| 260 | { |
Andrew Jeffery | 0f9fbd6 | 2018-03-02 12:00:42 +1030 | [diff] [blame] | 261 | state |= PARTITION_ECC_PROTECTED; |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 262 | } |
| 263 | else if (flag == "READONLY") |
| 264 | { |
| 265 | perms |= PARTITION_READONLY; |
| 266 | } |
Andrew Jeffery | 0f9fbd6 | 2018-03-02 12:00:42 +1030 | [diff] [blame] | 267 | else if (flag == "READWRITE") |
| 268 | { |
| 269 | perms &= ~PARTITION_READONLY; |
| 270 | } |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 271 | else if (flag == "PRESERVED") |
| 272 | { |
| 273 | perms |= PARTITION_PRESERVED; |
| 274 | } |
| 275 | else if (flag == "REPROVISION") |
| 276 | { |
| 277 | perms |= PARTITION_REPROVISION; |
| 278 | } |
| 279 | else if (flag == "VOLATILE") |
| 280 | { |
| 281 | perms |= PARTITION_VOLATILE; |
| 282 | } |
| 283 | else if (flag == "CLEARECC") |
| 284 | { |
| 285 | perms |= PARTITION_CLEARECC; |
| 286 | } |
Andrew Jeffery | 0f9fbd6 | 2018-03-02 12:00:42 +1030 | [diff] [blame] | 287 | else |
| 288 | { |
| 289 | MSG_INFO("Found unimplemented partition property: %s\n", |
| 290 | flag.c_str()); |
| 291 | } |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 292 | } |
| 293 | |
Andrew Jeffery | 0f9fbd6 | 2018-03-02 12:00:42 +1030 | [diff] [blame] | 294 | part.data.user.data[0] = state; |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 295 | part.data.user.data[1] = perms; |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 296 | part.data.user.data[1] |= version; |
| 297 | } |
| 298 | |
| 299 | static inline void writeDefaults(pnor_partition& part) |
| 300 | { |
| 301 | part.data.pid = PARENT_PATITION_ID; |
| 302 | part.data.type = PARTITION_TYPE_DATA; |
| 303 | part.data.flags = 0; // flags unused |
| 304 | } |
| 305 | |
| 306 | static inline void writeNameAndId(pnor_partition& part, std::string&& name, |
| 307 | const std::string& id) |
| 308 | { |
| 309 | name.resize(PARTITION_NAME_MAX); |
| 310 | memcpy(part.data.name, name.c_str(), sizeof(part.data.name)); |
| 311 | part.data.id = std::stoul(id); |
| 312 | } |
| 313 | |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 314 | void parseTocLine(const std::string& line, size_t blockSize, |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 315 | pnor_partition& part) |
| 316 | { |
| 317 | static constexpr auto ID_MATCH = 1; |
| 318 | static constexpr auto NAME_MATCH = 2; |
| 319 | static constexpr auto START_ADDR_MATCH = 4; |
| 320 | static constexpr auto END_ADDR_MATCH = 6; |
| 321 | static constexpr auto VERSION_MATCH = 8; |
| 322 | constexpr auto versionShift = 24; |
| 323 | |
| 324 | // Parse PNOR toc (table of contents) file, which has lines like : |
| 325 | // partition01=HBB,0x00010000,0x000a0000,0x80,ECC,PRESERVED, to indicate |
| 326 | // partition information |
| 327 | std::regex regex{ |
| 328 | "^partition([0-9]+)=([A-Za-z0-9_]+)," |
| 329 | "(0x)?([0-9a-fA-F]+),(0x)?([0-9a-fA-F]+),(0x)?([A-Fa-f0-9]{2})", |
| 330 | std::regex::extended}; |
| 331 | |
| 332 | std::smatch match; |
| 333 | if (!std::regex_search(line, match, regex)) |
| 334 | { |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 335 | std::stringstream err; |
| 336 | err << "Malformed partition description: " << line.c_str() << "\n"; |
| 337 | throw MalformedTocEntry(err.str()); |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | writeNameAndId(part, match[NAME_MATCH].str(), match[ID_MATCH].str()); |
| 341 | writeDefaults(part); |
| 342 | |
| 343 | unsigned long start = |
| 344 | std::stoul(match[START_ADDR_MATCH].str(), nullptr, 16); |
Andrew Jeffery | b87aa32 | 2018-02-27 16:27:02 +1030 | [diff] [blame] | 345 | if (start & (blockSize - 1)) |
| 346 | { |
| 347 | MSG_ERR("Start offset 0x%lx for partition '%s' is not aligned to block " |
| 348 | "size 0x%zx\n", |
| 349 | start, match[NAME_MATCH].str().c_str(), blockSize); |
| 350 | } |
| 351 | |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 352 | unsigned long end = std::stoul(match[END_ADDR_MATCH].str(), nullptr, 16); |
Andrew Jeffery | b87aa32 | 2018-02-27 16:27:02 +1030 | [diff] [blame] | 353 | if ((end - start) & (blockSize - 1)) |
| 354 | { |
| 355 | MSG_ERR("Partition '%s' has a size 0x%lx that is not aligned to block " |
| 356 | "size 0x%zx\n", |
| 357 | match[NAME_MATCH].str().c_str(), (end - start), blockSize); |
| 358 | } |
| 359 | |
Andrew Jeffery | db49341 | 2018-03-02 11:54:22 +1030 | [diff] [blame] | 360 | if (start >= end) |
| 361 | { |
| 362 | std::stringstream err; |
| 363 | err << "Partition " << match[NAME_MATCH].str() |
| 364 | << " has an invalid range: start offset (0x" << std::hex << start |
| 365 | << " is beyond open end (0x" << std::hex << end << ")\n"; |
| 366 | throw InvalidTocEntry(err.str()); |
| 367 | } |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 368 | writeSizes(part, start, end, blockSize); |
| 369 | |
| 370 | // Use the shift to convert "80" to 0x80000000 |
| 371 | unsigned long version = std::stoul(match[VERSION_MATCH].str(), nullptr, 16); |
| 372 | writeUserdata(part, version << versionShift, match.suffix().str()); |
| 373 | part.checksum = details::checksum(part.data); |
Andrew Jeffery | d394a78 | 2018-02-21 16:16:14 +1030 | [diff] [blame] | 374 | } |
| 375 | |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 376 | } // namespace virtual_pnor |
| 377 | } // namespace openpower |