diff options
| -rw-r--r-- | arch/powerpc/platforms/ps3/os-area.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/arch/powerpc/platforms/ps3/os-area.c b/arch/powerpc/platforms/ps3/os-area.c index 766685ab26f8..b9ea09d9d2fb 100644 --- a/arch/powerpc/platforms/ps3/os-area.c +++ b/arch/powerpc/platforms/ps3/os-area.c | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include <linux/workqueue.h> | 23 | #include <linux/workqueue.h> |
| 24 | #include <linux/fs.h> | 24 | #include <linux/fs.h> |
| 25 | #include <linux/syscalls.h> | 25 | #include <linux/syscalls.h> |
| 26 | #include <linux/ctype.h> | ||
| 26 | 27 | ||
| 27 | #include <asm/lmb.h> | 28 | #include <asm/lmb.h> |
| 28 | 29 | ||
| @@ -37,6 +38,8 @@ enum os_area_ldr_format { | |||
| 37 | HEADER_LDR_FORMAT_GZIP = 1, | 38 | HEADER_LDR_FORMAT_GZIP = 1, |
| 38 | }; | 39 | }; |
| 39 | 40 | ||
| 41 | #define OS_AREA_HEADER_MAGIC_NUM "cell_ext_os_area" | ||
| 42 | |||
| 40 | /** | 43 | /** |
| 41 | * struct os_area_header - os area header segment. | 44 | * struct os_area_header - os area header segment. |
| 42 | * @magic_num: Always 'cell_ext_os_area'. | 45 | * @magic_num: Always 'cell_ext_os_area'. |
| @@ -114,13 +117,11 @@ struct os_area_params { | |||
| 114 | u8 _reserved_5[8]; | 117 | u8 _reserved_5[8]; |
| 115 | }; | 118 | }; |
| 116 | 119 | ||
| 117 | enum { | 120 | #define OS_AREA_DB_MAGIC_NUM "-db-" |
| 118 | OS_AREA_DB_MAGIC_NUM = 0x2d64622dU, | ||
| 119 | }; | ||
| 120 | 121 | ||
| 121 | /** | 122 | /** |
| 122 | * struct os_area_db - Shared flash memory database. | 123 | * struct os_area_db - Shared flash memory database. |
| 123 | * @magic_num: Always '-db-' = 0x2d64622d. | 124 | * @magic_num: Always '-db-'. |
| 124 | * @version: os_area_db format version number. | 125 | * @version: os_area_db format version number. |
| 125 | * @index_64: byte offset of the database id index for 64 bit variables. | 126 | * @index_64: byte offset of the database id index for 64 bit variables. |
| 126 | * @count_64: number of usable 64 bit index entries | 127 | * @count_64: number of usable 64 bit index entries |
| @@ -135,7 +136,7 @@ enum { | |||
| 135 | */ | 136 | */ |
| 136 | 137 | ||
| 137 | struct os_area_db { | 138 | struct os_area_db { |
| 138 | u32 magic_num; | 139 | u8 magic_num[4]; |
| 139 | u16 version; | 140 | u16 version; |
| 140 | u16 _reserved_1; | 141 | u16 _reserved_1; |
| 141 | u16 index_64; | 142 | u16 index_64; |
| @@ -265,12 +266,26 @@ static void __init os_area_get_property(struct device_node *node, | |||
| 265 | prop->name); | 266 | prop->name); |
| 266 | } | 267 | } |
| 267 | 268 | ||
| 269 | static void dump_field(char *s, const u8 *field, int size_of_field) | ||
| 270 | { | ||
| 271 | #if defined(DEBUG) | ||
| 272 | int i; | ||
| 273 | |||
| 274 | for (i = 0; i < size_of_field; i++) | ||
| 275 | s[i] = isprint(field[i]) ? field[i] : '.'; | ||
| 276 | s[i] = 0; | ||
| 277 | #endif | ||
| 278 | } | ||
| 279 | |||
| 268 | #define dump_header(_a) _dump_header(_a, __func__, __LINE__) | 280 | #define dump_header(_a) _dump_header(_a, __func__, __LINE__) |
| 269 | static void _dump_header(const struct os_area_header *h, const char *func, | 281 | static void _dump_header(const struct os_area_header *h, const char *func, |
| 270 | int line) | 282 | int line) |
| 271 | { | 283 | { |
| 284 | char str[sizeof(h->magic_num) + 1]; | ||
| 285 | |||
| 286 | dump_field(str, h->magic_num, sizeof(h->magic_num)); | ||
| 272 | pr_debug("%s:%d: h.magic_num: '%s'\n", func, line, | 287 | pr_debug("%s:%d: h.magic_num: '%s'\n", func, line, |
| 273 | h->magic_num); | 288 | str); |
| 274 | pr_debug("%s:%d: h.hdr_version: %u\n", func, line, | 289 | pr_debug("%s:%d: h.hdr_version: %u\n", func, line, |
| 275 | h->hdr_version); | 290 | h->hdr_version); |
| 276 | pr_debug("%s:%d: h.db_area_offset: %u\n", func, line, | 291 | pr_debug("%s:%d: h.db_area_offset: %u\n", func, line, |
| @@ -311,7 +326,8 @@ static void _dump_params(const struct os_area_params *p, const char *func, | |||
| 311 | 326 | ||
| 312 | static int verify_header(const struct os_area_header *header) | 327 | static int verify_header(const struct os_area_header *header) |
| 313 | { | 328 | { |
| 314 | if (memcmp(header->magic_num, "cell_ext_os_area", 16)) { | 329 | if (memcmp(header->magic_num, OS_AREA_HEADER_MAGIC_NUM, |
| 330 | sizeof(header->magic_num))) { | ||
| 315 | pr_debug("%s:%d magic_num failed\n", __func__, __LINE__); | 331 | pr_debug("%s:%d magic_num failed\n", __func__, __LINE__); |
| 316 | return -1; | 332 | return -1; |
| 317 | } | 333 | } |
| @@ -331,7 +347,8 @@ static int verify_header(const struct os_area_header *header) | |||
| 331 | 347 | ||
| 332 | static int db_verify(const struct os_area_db *db) | 348 | static int db_verify(const struct os_area_db *db) |
| 333 | { | 349 | { |
| 334 | if (db->magic_num != OS_AREA_DB_MAGIC_NUM) { | 350 | if (memcmp(db->magic_num, OS_AREA_DB_MAGIC_NUM, |
| 351 | sizeof(db->magic_num))) { | ||
| 335 | pr_debug("%s:%d magic_num failed\n", __func__, __LINE__); | 352 | pr_debug("%s:%d magic_num failed\n", __func__, __LINE__); |
| 336 | return -1; | 353 | return -1; |
| 337 | } | 354 | } |
| @@ -484,8 +501,11 @@ static int db_get_rtc_diff(const struct os_area_db *db, int64_t *rtc_diff) | |||
| 484 | static void _dump_db(const struct os_area_db *db, const char *func, | 501 | static void _dump_db(const struct os_area_db *db, const char *func, |
| 485 | int line) | 502 | int line) |
| 486 | { | 503 | { |
| 504 | char str[sizeof(db->magic_num) + 1]; | ||
| 505 | |||
| 506 | dump_field(str, db->magic_num, sizeof(db->magic_num)); | ||
| 487 | pr_debug("%s:%d: db.magic_num: '%s'\n", func, line, | 507 | pr_debug("%s:%d: db.magic_num: '%s'\n", func, line, |
| 488 | (const char*)&db->magic_num); | 508 | str); |
| 489 | pr_debug("%s:%d: db.version: %u\n", func, line, | 509 | pr_debug("%s:%d: db.version: %u\n", func, line, |
| 490 | db->version); | 510 | db->version); |
| 491 | pr_debug("%s:%d: db.index_64: %u\n", func, line, | 511 | pr_debug("%s:%d: db.index_64: %u\n", func, line, |
| @@ -516,7 +536,7 @@ static void os_area_db_init(struct os_area_db *db) | |||
| 516 | 536 | ||
| 517 | memset(db, 0, sizeof(struct os_area_db)); | 537 | memset(db, 0, sizeof(struct os_area_db)); |
| 518 | 538 | ||
| 519 | db->magic_num = OS_AREA_DB_MAGIC_NUM; | 539 | memcpy(db->magic_num, OS_AREA_DB_MAGIC_NUM, sizeof(db->magic_num)); |
| 520 | db->version = 1; | 540 | db->version = 1; |
| 521 | db->index_64 = HEADER_SIZE; | 541 | db->index_64 = HEADER_SIZE; |
| 522 | db->count_64 = VALUES_64_COUNT; | 542 | db->count_64 = VALUES_64_COUNT; |
