From patchwork Fri Dec 22 21:13:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 122667 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2747128qgn; Fri, 22 Dec 2017 13:19:31 -0800 (PST) X-Google-Smtp-Source: ACJfBouyCCElmCVPSeSXO7kb+uXhqDmox7AjrhjqmGKcC43I4jiOGgDZFFNBpHNTLlJjEu8V9GqM X-Received: by 10.80.244.194 with SMTP id v2mr16910130edm.68.1513977571735; Fri, 22 Dec 2017 13:19:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513977571; cv=none; d=google.com; s=arc-20160816; b=zAMONe/wE3rs7AOXDMUfks1xgBK75KPfXcgSsrbttlLtJj7tNBzBPFfrlmp4GEt4RR 5NKPORNb0f+CiQLzmJgVCmSxdtp5doRA0Oh/NWN6XJ3xrPYkY6qeKDZoEuHDps4U1gmN N+TjF7q7TRgV6zmOqGgCZ2ABJokWiFBpE/l2vl+7LS8CwHJCc6xKRPP+cFSE4EyJCm0b 5249RO9iPPLorK9JvDFj5w9YUxlQnnBOZjoceAVPToSsxqgIfW/SKmshONZ5URyGJwfi dGhe57MNDe462CAbrv++z7s3Ei1JfrMOm9j/juxzHF/P5XJcaBbSkWALKniT9rrwyq7p p/hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:references :in-reply-to:message-id:date:to:from:arc-authentication-results; bh=HymPVBUdr734g+Jr3Qg9eyulZRsHrKuRFA0TxtL7cEI=; b=d4TDz4SuNpEB7qKMjPR/LsSzHHPzBVpycsWBhfeIGMFbD84PaMZ9bmQyQ04Or+5Dx+ muzk3m4D/7xLho6M08WEr4RFv2npbbrNK//JlOst9J3LZcJ4KoNqpA/UpoH2KFZMxEJ/ BbVtWyy27vAXOYKzNNcQHkes/2vGnIDh+jHldBsqxxuadAVW92RSPqMu2+FpaNl/F5/B 1932k0gHhTbZc6uIPz2jRr/wPMLNrToBGcCnF9eQR2W6zezCjI7OLxJrS199joPwb8Jj OTAlnC4ONyMrIN9svEvCnhWAeev5/AFlFuwq5092UGvRf5yXLySrkwbDMJy89XbqQcEu Wqvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id j35si6218343edd.284.2017.12.22.13.19.31; Fri, 22 Dec 2017 13:19:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 55A41C2200F; Fri, 22 Dec 2017 21:16:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3341AC2221C; Fri, 22 Dec 2017 21:14:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 043B3C2221A; Fri, 22 Dec 2017 21:14:22 +0000 (UTC) Received: from mail.free-electrons.com (mail.free-electrons.com [62.4.15.54]) by lists.denx.de (Postfix) with ESMTP id A6C6CC21FBB for ; Fri, 22 Dec 2017 21:14:16 +0000 (UTC) Received: by mail.free-electrons.com (Postfix, from userid 110) id CBD2C207C8; Fri, 22 Dec 2017 22:14:15 +0100 (CET) Received: from localhost.localdomain (unknown [80.12.41.248]) by mail.free-electrons.com (Postfix) with ESMTPSA id 1AC54203A1; Fri, 22 Dec 2017 22:14:15 +0100 (CET) From: Quentin Schulz To: jagan@openedev.com, maxime.ripard@free-electrons.com, hdegoede@redhat.com, sjg@chromium.org, wd@denx.de, andre.przywara@arm.com, lukma@denx.de Date: Fri, 22 Dec 2017 22:13:40 +0100 Message-Id: <0a56db0dbb1b0eec0151842b800ad73d7ddbfc15.1513975247.git-series.quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Cc: thomas.petazzoni@free-electrons.com, u-boot@lists.denx.de Subject: [U-Boot] [PATCH 06/11] env: add env_driver to env_driver functions' arguments X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Might be interesting to get some infos about the driver (e.g. its location) when inside one of its functions. Signed-off-by: Quentin Schulz --- env/eeprom.c | 6 +++--- env/env.c | 8 ++++---- env/ext4.c | 4 ++-- env/fat.c | 4 ++-- env/flash.c | 10 +++++----- env/mmc.c | 6 +++--- env/nand.c | 8 ++++---- env/nowhere.c | 4 ++-- env/nvram.c | 8 ++++---- env/onenand.c | 4 ++-- env/remote.c | 6 +++--- env/sata.c | 4 ++-- env/sf.c | 8 ++++---- env/ubi.c | 8 ++++---- include/environment.h | 14 ++++++++++---- 15 files changed, 54 insertions(+), 48 deletions(-) diff --git a/env/eeprom.c b/env/eeprom.c index 584379e..b0ffce4 100644 --- a/env/eeprom.c +++ b/env/eeprom.c @@ -61,7 +61,7 @@ static int eeprom_bus_write(unsigned dev_addr, unsigned offset, return rcode; } -static int env_eeprom_get_char(int index) +static int env_eeprom_get_char(struct env_driver *drv, int index) { uchar c; unsigned int off = CONFIG_ENV_OFFSET; @@ -76,7 +76,7 @@ static int env_eeprom_get_char(int index) return c; } -static int env_eeprom_load(void) +static int env_eeprom_load(struct env_driver *drv) { char buf_env[CONFIG_ENV_SIZE]; unsigned int off = CONFIG_ENV_OFFSET; @@ -186,7 +186,7 @@ static int env_eeprom_load(void) return 0; } -static int env_eeprom_save(void) +static int env_eeprom_save(struct env_driver *drv) { env_t env_new; int rc; diff --git a/env/env.c b/env/env.c index 43a62b8..7c98083 100644 --- a/env/env.c +++ b/env/env.c @@ -153,7 +153,7 @@ int env_get_char(int index) if (!(gd->env_has_init & BIT(drv->location))) continue; - ret = drv->get_char(index); + ret = drv->get_char(drv, index); if (!ret) return 0; @@ -181,7 +181,7 @@ int env_load(void) continue; printf("Loading Environment from %s... ", drv->name); - ret = drv->load(); + ret = drv->load(drv); printf("%s\n", ret ? "Failed" : "OK"); if (!ret) break; @@ -205,7 +205,7 @@ int env_load(void) printf("Overriding env variables with ones from %s env...", __func__, drv->name); - ret = drv->load(); + ret = drv->load(drv); printf("%s\n", ret ? "Failed" : "OK"); if (!ret) { found = true; @@ -241,7 +241,7 @@ int env_save(void) continue; printf("Saving Environment to %s... ", drv->name); - ret = drv->save(); + ret = drv->save(drv); printf("%s\n", ret ? "Failed" : "OK"); #ifdef CONFIG_ENV_VAR_WHITELIST /* When whitelisting, we want to save to all media available */ diff --git a/env/ext4.c b/env/ext4.c index 6520221..77c0389 100644 --- a/env/ext4.c +++ b/env/ext4.c @@ -34,7 +34,7 @@ DECLARE_GLOBAL_DATA_PTR; #ifdef CONFIG_CMD_SAVEENV -static int env_ext4_save(void) +static int env_ext4_save(struct env_driver *drv) { env_t env_new; struct blk_desc *dev_desc = NULL; @@ -75,7 +75,7 @@ static int env_ext4_save(void) } #endif /* CONFIG_CMD_SAVEENV */ -static int env_ext4_load(void) +static int env_ext4_load(struct env_driver *drv) { ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); struct blk_desc *dev_desc = NULL; diff --git a/env/fat.c b/env/fat.c index 51c4ced..05b5971 100644 --- a/env/fat.c +++ b/env/fat.c @@ -34,7 +34,7 @@ DECLARE_GLOBAL_DATA_PTR; #ifdef CMD_SAVEENV -static int env_fat_save(void) +static int env_fat_save(struct env_driver *drv) { env_t env_new; struct blk_desc *dev_desc = NULL; @@ -73,7 +73,7 @@ static int env_fat_save(void) #endif /* CMD_SAVEENV */ #ifdef LOADENV -static int env_fat_load(void) +static int env_fat_load(struct env_driver *drv) { ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); struct blk_desc *dev_desc = NULL; diff --git a/env/flash.c b/env/flash.c index bac10ff..45e58b4 100644 --- a/env/flash.c +++ b/env/flash.c @@ -71,7 +71,7 @@ static ulong __maybe_unused end_addr_new = #ifdef CONFIG_ENV_ADDR_REDUND #ifdef INITENV -static int env_flash_init(void) +static int env_flash_init(struct env_driver *drv) { int crc1_ok = 0, crc2_ok = 0; @@ -117,7 +117,7 @@ static int env_flash_init(void) #endif #ifdef CMD_SAVEENV -static int env_flash_save(void) +static int env_flash_save(struct env_driver *drv) { env_t env_new; char *saved_data = NULL; @@ -222,7 +222,7 @@ done: #else /* ! CONFIG_ENV_ADDR_REDUND */ #ifdef INITENV -static int env_flash_init(void) +static int env_flash_init(struct env_driver *drv) { if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) { gd->env_addr = (ulong)&(env_ptr->data); @@ -237,7 +237,7 @@ static int env_flash_init(void) #endif #ifdef CMD_SAVEENV -static int env_flash_save(void) +static int env_flash_save(struct env_driver *drv) { env_t env_new; int rc = 1; @@ -308,7 +308,7 @@ done: #endif /* CONFIG_ENV_ADDR_REDUND */ #ifdef LOADENV -static int env_flash_load(void) +static int env_flash_load(struct env_driver *drv) { #ifdef CONFIG_ENV_ADDR_REDUND if (gd->env_addr != (ulong)&(flash_addr->data)) { diff --git a/env/mmc.c b/env/mmc.c index 885e000..64d1404 100644 --- a/env/mmc.c +++ b/env/mmc.c @@ -143,7 +143,7 @@ static inline int write_env(struct mmc *mmc, unsigned long size, return (n == blk_cnt) ? 0 : -1; } -static int env_mmc_save(void) +static int env_mmc_save(struct env_driver *drv) { ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); int dev = mmc_get_env_dev(); @@ -206,7 +206,7 @@ static inline int read_env(struct mmc *mmc, unsigned long size, } #ifdef CONFIG_ENV_OFFSET_REDUND -static int env_mmc_load(void) +static int env_mmc_load(struct env_driver *drv) { #if !defined(ENV_IS_EMBEDDED) struct mmc *mmc; @@ -268,7 +268,7 @@ err: return ret; } #else /* ! CONFIG_ENV_OFFSET_REDUND */ -static int env_mmc_load(void) +static int env_mmc_load(struct env_driver *drv) { #if !defined(ENV_IS_EMBEDDED) ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); diff --git a/env/nand.c b/env/nand.c index 8058b55..6ed3c26 100644 --- a/env/nand.c +++ b/env/nand.c @@ -62,7 +62,7 @@ DECLARE_GLOBAL_DATA_PTR; * This way the SPL loads not only the U-Boot image from NAND but * also the environment. */ -static int env_nand_init(void) +static int env_nand_init(struct env_driver *drv) { #if defined(ENV_IS_EMBEDDED) || defined(CONFIG_NAND_ENV_DST) int crc1_ok = 0, crc2_ok = 0; @@ -183,7 +183,7 @@ static int erase_and_write_env(const struct nand_env_location *location, return ret; } -static int env_nand_save(void) +static int env_nand_save(struct env_driver *drv) { int ret = 0; ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); @@ -315,7 +315,7 @@ int get_nand_env_oob(struct mtd_info *mtd, unsigned long *result) #endif #ifdef CONFIG_ENV_OFFSET_REDUND -static int env_nand_load(void) +static int env_nand_load(struct env_driver *drv) { #if defined(ENV_IS_EMBEDDED) return 0; @@ -368,7 +368,7 @@ done: * device i.e., nand_dev_desc + 0. This is also the behaviour using * the new NAND code. */ -static int env_nand_load(void) +static int env_nand_load(struct env_driver *drv) { #if !defined(ENV_IS_EMBEDDED) int ret; diff --git a/env/nowhere.c b/env/nowhere.c index 7a37909..fb6ea9e 100644 --- a/env/nowhere.c +++ b/env/nowhere.c @@ -15,7 +15,7 @@ DECLARE_GLOBAL_DATA_PTR; -static int env_nowhere_load(void) +static int env_nowhere_load(struct env_driver *drv) { return !env_import((char *)default_environment, 0); } @@ -24,7 +24,7 @@ static int env_nowhere_load(void) * Because we only ever have the default environment available we must mark * it as invalid. */ -static int env_nowhere_init(void) +static int env_nowhere_init(struct env_driver *drv) { gd->env_addr = (ulong)&default_environment[0]; gd->env_valid = ENV_VALID; diff --git a/env/nvram.c b/env/nvram.c index c8b3475..aad341d 100644 --- a/env/nvram.c +++ b/env/nvram.c @@ -41,7 +41,7 @@ env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; #endif #ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE -static int env_nvram_get_char(int index) +static int env_nvram_get_char(struct env_driver *drv, int index) { uchar c; @@ -51,7 +51,7 @@ static int env_nvram_get_char(int index) } #endif -static int env_nvram_load(void) +static int env_nvram_load(struct env_driver *drv) { char buf[CONFIG_ENV_SIZE]; @@ -65,7 +65,7 @@ static int env_nvram_load(void) return 0; } -static int env_nvram_save(void) +static int env_nvram_save(struct env_driver *drv) { env_t env_new; int rcode = 0; @@ -88,7 +88,7 @@ static int env_nvram_save(void) * * We are still running from ROM, so data use is limited */ -static int env_nvram_init(void) +static int env_nvram_init(struct env_driver *drv) { #if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE) ulong crc; diff --git a/env/onenand.c b/env/onenand.c index 2e3045c..e633ebe 100644 --- a/env/onenand.c +++ b/env/onenand.c @@ -26,7 +26,7 @@ DECLARE_GLOBAL_DATA_PTR; -static int env_onenand_load(void) +static int env_onenand_load(struct env_driver *drv) { struct mtd_info *mtd = &onenand_mtd; #ifdef CONFIG_ENV_ADDR_FLEX @@ -63,7 +63,7 @@ static int env_onenand_load(void) return rc ? 0 : -EIO; } -static int env_onenand_save(void) +static int env_onenand_save(struct env_driver *drv) { env_t env_new; int ret; diff --git a/env/remote.c b/env/remote.c index c013fdd..b004964 100644 --- a/env/remote.c +++ b/env/remote.c @@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR; #define CONFIG_ENV_OFFSET 0 #endif -static int env_remote_init(void) +static int env_remote_init(struct env_driver *drv) { if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) { gd->env_addr = (ulong)&(env_ptr->data); @@ -35,7 +35,7 @@ static int env_remote_init(void) } #ifdef CONFIG_CMD_SAVEENV -static int env_remote_save(void) +static int env_remote_save(struct env_driver *drv) { #ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n"); @@ -46,7 +46,7 @@ static int env_remote_save(void) } #endif /* CONFIG_CMD_SAVEENV */ -static int env_remote_load(void) +static int env_remote_load(struct env_driver *drv) { #ifndef ENV_IS_EMBEDDED env_import((char *)env_ptr, 1); diff --git a/env/sata.c b/env/sata.c index a770297..93289be 100644 --- a/env/sata.c +++ b/env/sata.c @@ -45,7 +45,7 @@ static inline int write_env(struct blk_desc *sata, unsigned long size, return (n == blk_cnt) ? 0 : -1; } -static int env_sata_save(void) +static int env_sata_save(struct env_driver *drv) { ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); struct blk_desc *sata = NULL; @@ -91,7 +91,7 @@ static inline int read_env(struct blk_desc *sata, unsigned long size, return (n == blk_cnt) ? 0 : -1; } -static void env_sata_load(void) +static void env_sata_load(struct env_driver *drv) { ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); struct blk_desc *sata = NULL; diff --git a/env/sf.c b/env/sf.c index e51b1ae..e811cde 100644 --- a/env/sf.c +++ b/env/sf.c @@ -82,7 +82,7 @@ static int setup_flash_device(void) #if defined(CONFIG_ENV_OFFSET_REDUND) #ifdef CMD_SAVEENV -static int env_sf_save(void) +static int env_sf_save(struct env_driver *drv) { env_t env_new; char *saved_buffer = NULL, flag = OBSOLETE_FLAG; @@ -162,7 +162,7 @@ static int env_sf_save(void) } #endif /* CMD_SAVEENV */ -static int env_sf_load(void) +static int env_sf_load(struct env_driver *drv) { int ret; int crc1_ok = 0, crc2_ok = 0; @@ -251,7 +251,7 @@ out: } #else #ifdef CMD_SAVEENV -static int env_sf_save(void) +static int env_sf_save(struct env_driver *drv) { u32 saved_size, saved_offset, sector; char *saved_buffer = NULL; @@ -312,7 +312,7 @@ static int env_sf_save(void) } #endif /* CMD_SAVEENV */ -static int env_sf_load(void) +static int env_sf_load(struct env_driver *drv) { int ret; char *buf = NULL; diff --git a/env/ubi.c b/env/ubi.c index 1c4653d..a649999 100644 --- a/env/ubi.c +++ b/env/ubi.c @@ -20,7 +20,7 @@ DECLARE_GLOBAL_DATA_PTR; #ifdef CONFIG_CMD_SAVEENV #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT -static int env_ubi_save(void) +static int env_ubi_save(struct env_driver *drv) { ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); int ret; @@ -62,7 +62,7 @@ static int env_ubi_save(void) return 0; } #else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */ -static int env_ubi_save(void) +static int env_ubi_save(struct env_driver *drv) { ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); int ret; @@ -91,7 +91,7 @@ static int env_ubi_save(void) #endif /* CONFIG_CMD_SAVEENV */ #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT -static int env_ubi_load(void) +static int env_ubi_load(struct env_driver *drv) { ALLOC_CACHE_ALIGN_BUFFER(char, env1_buf, CONFIG_ENV_SIZE); ALLOC_CACHE_ALIGN_BUFFER(char, env2_buf, CONFIG_ENV_SIZE); @@ -135,7 +135,7 @@ static int env_ubi_load(void) return 0; } #else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */ -static int env_ubi_load(void) +static int env_ubi_load(struct env_driver *drv) { ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); diff --git a/include/environment.h b/include/environment.h index 33e47ba..34a0d5e 100644 --- a/include/environment.h +++ b/include/environment.h @@ -222,6 +222,8 @@ enum env_operation { ENVO_SAVE, }; +struct env_driver; + struct env_driver { const char *name; enum env_location location; @@ -232,10 +234,11 @@ struct env_driver { * This method is optional. If not provided, a default implementation * will read from gd->env_addr. * + * @drv: the driver whose get_char function is about to be called * @index: Index of character to read (0=first) * @return character read, or -ve on error */ - int (*get_char)(int index); + int (*get_char)(struct env_driver *drv, int index); /** * load() - Load the environment from storage @@ -243,28 +246,31 @@ struct env_driver { * This method is optional. If not provided, no environment will be * loaded. * + * @drv: the driver whose load function is about to be called * @return 0 if OK, -ve on error */ - int (*load)(void); + int (*load)(struct env_driver *drv); /** * save() - Save the environment to storage * * This method is required for 'saveenv' to work. * + * @drv: the driver whose save function is about to be called * @return 0 if OK, -ve on error */ - int (*save)(void); + int (*save)(struct env_driver *drv); /** * init() - Set up the initial pre-relocation environment * * This method is optional. * + * @drv: the driver whose init function is about to be called * @return 0 if OK, -ENOENT if no initial environment could be found, * other -ve on error */ - int (*init)(void); + int (*init)(struct env_driver *drv); }; #ifdef CONFIG_ENV_VAR_WHITELIST