Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
0004  */
0005 
0006 #include <linux/bcm47xx_nvram.h>
0007 #include <linux/mtd/mtd.h>
0008 #include <linux/mtd/partitions.h>
0009 
0010 #include "ofpart_linksys_ns.h"
0011 
0012 #define NVRAM_BOOT_PART     "bootpartition"
0013 
0014 static int ofpart_linksys_ns_bootpartition(void)
0015 {
0016     char buf[4];
0017     int bootpartition;
0018 
0019     /* Check CFE environment variable */
0020     if (bcm47xx_nvram_getenv(NVRAM_BOOT_PART, buf, sizeof(buf)) > 0) {
0021         if (!kstrtoint(buf, 0, &bootpartition))
0022             return bootpartition;
0023         pr_warn("Failed to parse %s value \"%s\"\n", NVRAM_BOOT_PART,
0024             buf);
0025     } else {
0026         pr_warn("Failed to get NVRAM \"%s\"\n", NVRAM_BOOT_PART);
0027     }
0028 
0029     return 0;
0030 }
0031 
0032 int linksys_ns_partitions_post_parse(struct mtd_info *mtd,
0033                      struct mtd_partition *parts,
0034                      int nr_parts)
0035 {
0036     int bootpartition = ofpart_linksys_ns_bootpartition();
0037     int trx_idx = 0;
0038     int i;
0039 
0040     for (i = 0; i < nr_parts; i++) {
0041         if (of_device_is_compatible(parts[i].of_node, "linksys,ns-firmware")) {
0042             if (trx_idx++ == bootpartition)
0043                 parts[i].name = "firmware";
0044             else
0045                 parts[i].name = "backup";
0046         }
0047     }
0048 
0049     return 0;
0050 }