From c80260e5ef3c780f2b6006fb4e50aaae2089d56f Mon Sep 17 00:00:00 2001 From: Cyril Bur Date: Thu, 14 Jan 2016 18:08:30 +1100 Subject: external/gard: Fix displaying 'cleared' gard records When a garded component is replaced hostboot detects this and updates the gard partition. What hostboot does is set the record_id field to 0xFFFFFFFF but leaves the rest of the flash untouched, this has caused issues with the gard tool the thinking was that an entire record of all 0xFF bytes would signal not a valid record. This patch add rectifies this issue and `gard list` will no longer show any record with an id of 0xFFFFFFFF. Equivalent to 91cebdcd557dfc2dfc8050a34edb11a43facaf74 in master Signed-off-by: Cyril Bur Signed-off-by: Stewart Smith --- external/gard/gard.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/external/gard/gard.c b/external/gard/gard.c index 01488e3..869ada0 100644 --- a/external/gard/gard.c +++ b/external/gard/gard.c @@ -40,6 +40,8 @@ #include "gard.h" +#define CLEARED_RECORD_ID 0xFFFFFFFF + #define FDT_ACTIVE_FLASH_PATH "/proc/device-tree/chosen/ibm,system-flash" #define SYSFS_MTD_PATH "/sys/class/mtd/" #define FLASH_GARD_PART "GUARD" @@ -359,6 +361,11 @@ static int get_dev_mtd(const char *fdt_flash_path, char **r_path) return done ? rc : -1; } +static bool is_valid_id(uint32_t record_id) +{ + return record_id != CLEARED_RECORD_ID; +} + static int do_iterate(struct gard_ctx *ctx, int (*func)(struct gard_ctx *ctx, int pos, struct gard_record *gard, void *priv), @@ -405,13 +412,36 @@ static int get_largest_pos(struct gard_ctx *ctx) return largest; } +static int count_valid_records_i(struct gard_ctx *ctx, int pos, struct gard_record *gard, void *priv) +{ + if (!gard || !priv) + return -1; + + if (is_valid_id(be32toh(gard->record_id))) + (*(int *)priv)++; + + return 0; +} + +static int count_valid_records(struct gard_ctx *ctx) +{ + int rc, count = 0; + + rc = do_iterate(ctx, &count_valid_records_i, &count); + if (rc) + return 0; + + return count; +} + static int do_list_i(struct gard_ctx *ctx, int pos, struct gard_record *gard, void *priv) { if (!gard) return -1; - printf("| %08x | %08x | %-15s |\n", be32toh(gard->record_id), - be32toh(gard->errlog_eid), path_type_to_str(gard->target_id.type_size >> PATH_TYPE_SHIFT)); + if (is_valid_id(be32toh(gard->record_id))) + printf("| %08x | %08x | %-15s |\n", be32toh(gard->record_id), be32toh(gard->errlog_eid), + path_type_to_str(gard->target_id.type_size >> PATH_TYPE_SHIFT)); return 0; } @@ -421,7 +451,7 @@ static int do_list(struct gard_ctx *ctx, int argc, char **argv) int rc; /* No entries */ - if (get_largest_pos(ctx) == -1) { + if (count_valid_records(ctx) == 0) { printf("No GARD entries to display\n"); rc = 0; } else { -- cgit v1.1