X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=common%2Fupdate.c;h=a5879cb52c4112702c914ca83c7892abb85931cc;hb=5a1a8a63be8f7262a300eddafb18020926b12fb6;hp=1da80b70f2db6d1f01b5dca3141240a01ef1d169;hpb=cdc7732f3737f2bb97b77eb3d7c9da344bb73612;p=platform%2Fkernel%2Fu-boot.git diff --git a/common/update.c b/common/update.c index 1da80b7..a5879cb 100644 --- a/common/update.c +++ b/common/update.c @@ -1,30 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2008 Semihalf * * Written by: Rafal Czubak * Bartlomiej Sieka - * - * SPDX-License-Identifier: GPL-2.0+ */ #include +#include +#include #if !(defined(CONFIG_FIT) && defined(CONFIG_OF_LIBFDT)) #error "CONFIG_FIT and CONFIG_OF_LIBFDT are required for auto-update feature" #endif -#if defined(CONFIG_UPDATE_TFTP) && defined(CONFIG_SYS_NO_FLASH) -#error "CONFIG_UPDATE_TFTP and CONFIG_SYS_NO_FLASH needed for legacy behaviour" +#if defined(CONFIG_UPDATE_TFTP) && !defined(CONFIG_MTD_NOR_FLASH) +#error "CONFIG_UPDATE_TFTP and !CONFIG_MTD_NOR_FLASH needed for legacy behaviour" #endif #include +#include #include #include #include #include +#include #include #include +#include +#if defined(CONFIG_DFU_TFTP) || defined(CONFIG_UPDATE_TFTP) /* env variable holding the location of the update file */ #define UPDATE_FILE_ENV "updatefile" @@ -43,8 +48,7 @@ extern ulong tftp_timeout_ms; extern int tftp_timeout_count_max; -extern ulong load_addr; -#ifndef CONFIG_SYS_NO_FLASH +#ifdef CONFIG_MTD_NOR_FLASH extern flash_info_t flash_info[]; static uchar *saved_prot_info; #endif @@ -59,7 +63,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr) /* save used globals and env variable */ saved_timeout_msecs = tftp_timeout_ms; saved_timeout_count = tftp_timeout_count_max; - saved_netretry = strdup(getenv("netretry")); + saved_netretry = strdup(env_get("netretry")); saved_bootfile = strdup(net_boot_file_name); /* set timeouts for auto-update */ @@ -67,10 +71,10 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr) tftp_timeout_count_max = cnt_max; /* we don't want to retry the connection if errors occur */ - setenv("netretry", "no"); + env_set("netretry", "no"); /* download the update file */ - load_addr = addr; + image_load_addr = addr; copy_filename(net_boot_file_name, filename, sizeof(net_boot_file_name)); size = net_loop(TFTPGET); @@ -83,7 +87,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr) tftp_timeout_ms = saved_timeout_msecs; tftp_timeout_count_max = saved_timeout_count; - setenv("netretry", saved_netretry); + env_set("netretry", saved_netretry); if (saved_netretry != NULL) free(saved_netretry); @@ -96,7 +100,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr) return rv; } -#ifndef CONFIG_SYS_NO_FLASH +#ifdef CONFIG_MTD_NOR_FLASH static int update_flash_protect(int prot, ulong addr_first, ulong addr_last) { uchar *sp_info_ptr; @@ -172,7 +176,7 @@ static int update_flash_protect(int prot, ulong addr_first, ulong addr_last) static int update_flash(ulong addr_source, ulong addr_first, ulong size) { -#ifndef CONFIG_SYS_NO_FLASH +#ifdef CONFIG_MTD_NOR_FLASH ulong addr_last = addr_first + size - 1; /* round last address to the sector boundary */ @@ -211,6 +215,7 @@ static int update_flash(ulong addr_source, ulong addr_first, ulong size) #endif return 0; } +#endif /* CONFIG_DFU_TFTP || CONFIG_UPDATE_TFTP */ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, ulong *fladdr, ulong *size) @@ -228,6 +233,7 @@ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, return 0; } +#if defined(CONFIG_DFU_TFTP) || defined(CONFIG_UPDATE_TFTP) int update_tftp(ulong addr, char *interface, char *devstring) { char *filename, *env_addr, *fit_image_name; @@ -242,7 +248,7 @@ int update_tftp(ulong addr, char *interface, char *devstring) } else if (interface && devstring) { update_tftp_dfu = true; } else { - error("Interface: %s and devstring: %s not supported!\n", + pr_err("Interface: %s and devstring: %s not supported!\n", interface, devstring); return -EINVAL; } @@ -254,7 +260,7 @@ int update_tftp(ulong addr, char *interface, char *devstring) printf("Auto-update from TFTP: "); /* get the file name of the update file */ - filename = getenv(UPDATE_FILE_ENV); + filename = env_get(UPDATE_FILE_ENV); if (filename == NULL) { printf("failed, env. variable '%s' not found\n", UPDATE_FILE_ENV); @@ -264,7 +270,8 @@ int update_tftp(ulong addr, char *interface, char *devstring) printf("trying update file '%s'\n", filename); /* get load address of downloaded update file */ - if ((env_addr = getenv("loadaddr")) != NULL) + env_addr = env_get("loadaddr"); + if (env_addr) addr = simple_strtoul(env_addr, NULL, 16); else addr = CONFIG_UPDATE_LOAD_ADDR; @@ -277,7 +284,7 @@ int update_tftp(ulong addr, char *interface, char *devstring) } got_update_file: - fit = (void *)addr; + fit = map_sysmem(addr, 0); if (!fit_check_format((void *)fit)) { printf("Bad FIT format of the update file, aborting " @@ -306,8 +313,7 @@ got_update_file: printf("\n"); if (update_fit_getparams(fit, noffset, &update_addr, &update_fladdr, &update_size)) { - printf("Error: can't get update parameteres, " - "aborting\n"); + printf("Error: can't get update parameters, aborting\n"); ret = 1; goto next_node; } @@ -321,8 +327,77 @@ got_update_file: } } else if (fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE)) { - ret = dfu_tftp_write(fit_image_name, update_addr, - update_size, interface, devstring); + ret = dfu_write_by_name(fit_image_name, + (void *)update_addr, + update_size, interface, + devstring); + if (ret) + return ret; + } +next_node: + noffset = fdt_next_node(fit, noffset, &ndepth); + } + + return ret; +} +#endif /* CONFIG_DFU_UPDATE || CONFIG_UPDATE_TFTP */ + +#ifdef CONFIG_UPDATE_FIT +/** + * fit_update - update storage with FIT image + * @fit: Pointer to FIT image + * + * Update firmware on storage using FIT image as input. + * The storage area to be update will be identified by the name + * in FIT and matching it to "dfu_alt_info" variable. + * + * Return: 0 - on success, non-zero - otherwise + */ +int fit_update(const void *fit) +{ + char *fit_image_name; + ulong update_addr, update_fladdr, update_size; + int images_noffset, ndepth, noffset; + int ret = 0; + + if (!fit) + return -EINVAL; + + if (!fit_check_format((void *)fit)) { + printf("Bad FIT format of the update file, aborting auto-update\n"); + return -EINVAL; + } + + /* process updates */ + images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); + + ndepth = 0; + noffset = fdt_next_node(fit, images_noffset, &ndepth); + while (noffset >= 0 && ndepth > 0) { + if (ndepth != 1) + goto next_node; + + fit_image_name = (char *)fit_get_name(fit, noffset, NULL); + printf("Processing update '%s' :", fit_image_name); + + if (!fit_image_verify(fit, noffset)) { + printf("Error: invalid update hash, aborting\n"); + ret = 1; + goto next_node; + } + + printf("\n"); + if (update_fit_getparams(fit, noffset, &update_addr, + &update_fladdr, &update_size)) { + printf("Error: can't get update parameters, aborting\n"); + ret = 1; + goto next_node; + } + + if (fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE)) { + ret = dfu_write_by_name(fit_image_name, + (void *)update_addr, + update_size, NULL, NULL); if (ret) return ret; } @@ -332,3 +407,4 @@ next_node: return ret; } +#endif /* CONFIG_UPDATE_FIT */