diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/Kconfig | 13 | ||||
-rw-r--r-- | cmd/fastboot.c | 2 | ||||
-rw-r--r-- | cmd/fastboot/Kconfig | 7 | ||||
-rw-r--r-- | cmd/gpt.c | 89 | ||||
-rw-r--r-- | cmd/nvedit.c | 17 | ||||
-rw-r--r-- | cmd/pxe.c | 12 | ||||
-rw-r--r-- | cmd/regulator.c | 2 | ||||
-rw-r--r-- | cmd/thordown.c | 6 | ||||
-rw-r--r-- | cmd/time.c | 2 | ||||
-rw-r--r-- | cmd/tpm_test.c | 6 | ||||
-rw-r--r-- | cmd/usb_gadget_sdp.c | 4 | ||||
-rw-r--r-- | cmd/usb_mass_storage.c | 6 |
12 files changed, 119 insertions, 47 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig index 07ec03b507..ce81b4c444 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -116,6 +116,9 @@ endmenu source "cmd/fastboot/Kconfig" +config BUILD_BIN2C + bool + comment "Commands" menu "Info commands" @@ -263,7 +266,6 @@ config CMD_IMI config CMD_IMLS bool "imls" - default y help List all images found in flash @@ -528,6 +530,7 @@ menu "Compression commands" config CMD_LZMADEC bool "lzmadec" + default y if CMD_BOOTI select LZMA help Support decompressing an LZMA (Lempel-Ziv-Markov chain algorithm) @@ -535,6 +538,7 @@ config CMD_LZMADEC config CMD_UNZIP bool "unzip" + default y if CMD_BOOTI help Uncompress a zip-compressed memory region. @@ -665,10 +669,17 @@ config CMD_GPT bool "GPT (GUID Partition Table) command" select PARTITION_UUIDS select EFI_PARTITION + imply RANDOM_UUID help Enable the 'gpt' command to ready and write GPT style partition tables. +config RANDOM_UUID + bool "GPT Random UUID generation" + help + Enable the generation of partitions with random UUIDs if none + are provided. + config CMD_GPT_RENAME bool "GPT partition renaming commands" depends on CMD_GPT diff --git a/cmd/fastboot.c b/cmd/fastboot.c index 488822a2ee..8adcca592d 100644 --- a/cmd/fastboot.c +++ b/cmd/fastboot.c @@ -27,7 +27,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) ret = board_usb_init(controller_index, USB_INIT_DEVICE); if (ret) { - error("USB init failed: %d", ret); + pr_err("USB init failed: %d", ret); return CMD_RET_FAILURE; } diff --git a/cmd/fastboot/Kconfig b/cmd/fastboot/Kconfig index fb0c5da94c..214bbc23fc 100644 --- a/cmd/fastboot/Kconfig +++ b/cmd/fastboot/Kconfig @@ -3,11 +3,16 @@ comment "FASTBOOT" menuconfig FASTBOOT bool "Fastboot support" depends on USB_GADGET + default y if ARCH_SUNXI && USB_MUSB_GADGET if FASTBOOT config USB_FUNCTION_FASTBOOT bool "Enable USB fastboot gadget" + default y + select USB_GADGET_DOWNLOAD + imply ANDROID_BOOT_IMAGE + imply CMD_FASTBOOT help This enables the USB part of the fastboot gadget. @@ -69,6 +74,8 @@ config FASTBOOT_FLASH config FASTBOOT_FLASH_MMC_DEV int "Define FASTBOOT MMC FLASH default device" depends on FASTBOOT_FLASH && MMC + default 0 if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA = -1 + default 1 if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA != -1 help The fastboot "flash" command requires additional information regarding the non-volatile storage device. Define this to @@ -402,7 +402,7 @@ static int set_gpt_info(struct blk_desc *dev_desc, if (!val) { #ifdef CONFIG_RANDOM_UUID *str_disk_guid = malloc(UUID_STR_LEN + 1); - if (str_disk_guid == NULL) + if (*str_disk_guid == NULL) return -ENOMEM; gen_rand_uuid_str(*str_disk_guid, UUID_STR_FORMAT_STD); #else @@ -633,6 +633,21 @@ static int do_disk_guid(struct blk_desc *dev_desc, char * const namestr) } #ifdef CONFIG_CMD_GPT_RENAME +/* + * There are 3 malloc() calls in set_gpt_info() and there is no info about which + * failed. + */ +static void set_gpt_cleanup(char **str_disk_guid, + disk_partition_t **partitions) +{ +#ifdef CONFIG_RANDOM_UUID + if (str_disk_guid) + free(str_disk_guid); +#endif + if (partitions) + free(partitions); +} + static int do_rename_gpt_parts(struct blk_desc *dev_desc, char *subcomm, char *name1, char *name2) { @@ -651,19 +666,27 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, char *subcomm, ret = get_disk_guid(dev_desc, disk_guid); if (ret < 0) return ret; + /* + * Allocates disk_partitions, requiring matching call to del_gpt_info() + * if successful. + */ numparts = get_gpt_info(dev_desc); if (numparts <= 0) return numparts ? numparts : -ENODEV; partlistlen = calc_parts_list_len(numparts); partitions_list = malloc(partlistlen); - if (partitions_list == NULL) + if (!partitions_list) { + del_gpt_info(); return -ENOMEM; + } memset(partitions_list, '\0', partlistlen); ret = create_gpt_partitions_list(numparts, disk_guid, partitions_list); - if (ret < 0) + if (ret < 0) { + free(partitions_list); return ret; + } /* * Uncomment the following line to print a string that 'gpt write' * or 'gpt verify' will accept as input. @@ -671,15 +694,23 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, char *subcomm, debug("OLD partitions_list is %s with %u chars\n", partitions_list, (unsigned)strlen(partitions_list)); + /* set_gpt_info allocates new_partitions and str_disk_guid */ ret = set_gpt_info(dev_desc, partitions_list, &str_disk_guid, &new_partitions, &part_count); - if (ret < 0) - return ret; + if (ret < 0) { + del_gpt_info(); + free(partitions_list); + if (ret == -ENOMEM) + set_gpt_cleanup(&str_disk_guid, &new_partitions); + else + goto out; + } if (!strcmp(subcomm, "swap")) { if ((strlen(name1) > PART_NAME_LEN) || (strlen(name2) > PART_NAME_LEN)) { printf("Names longer than %d characters are truncated.\n", PART_NAME_LEN); - return -EINVAL; + ret = -EINVAL; + goto out; } list_for_each(pos, &disk_partitions) { curr = list_entry(pos, struct disk_part, list); @@ -693,21 +724,24 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, char *subcomm, } if ((ctr1 + ctr2 < 2) || (ctr1 != ctr2)) { printf("Cannot swap partition names except in pairs.\n"); - return -EINVAL; + ret = -EINVAL; + goto out; } } else { /* rename */ if (strlen(name2) > PART_NAME_LEN) { printf("Names longer than %d characters are truncated.\n", PART_NAME_LEN); - return -EINVAL; + ret = -EINVAL; + goto out; } partnum = (int)simple_strtol(name1, NULL, 10); if ((partnum < 0) || (partnum > numparts)) { printf("Illegal partition number %s\n", name1); - return -EINVAL; + ret = -EINVAL; + goto out; } ret = part_get_info(dev_desc, partnum, new_partitions); if (ret < 0) - return ret; + goto out; /* U-Boot partition numbering starts at 1 */ list_for_each(pos, &disk_partitions) { @@ -722,33 +756,50 @@ static int do_rename_gpt_parts(struct blk_desc *dev_desc, char *subcomm, ret = create_gpt_partitions_list(numparts, disk_guid, partitions_list); if (ret < 0) - return ret; + goto out; debug("NEW partitions_list is %s with %u chars\n", partitions_list, (unsigned)strlen(partitions_list)); ret = set_gpt_info(dev_desc, partitions_list, &str_disk_guid, &new_partitions, &part_count); - if (ret < 0) - return ret; + /* + * Even though valid pointers are here passed into set_gpt_info(), + * it mallocs again, and there's no way to tell which failed. + */ + if (ret < 0) { + del_gpt_info(); + free(partitions_list); + if (ret == -ENOMEM) + set_gpt_cleanup(&str_disk_guid, &new_partitions); + else + goto out; + } debug("Writing new partition table\n"); ret = gpt_restore(dev_desc, disk_guid, new_partitions, numparts); if (ret < 0) { printf("Writing new partition table failed\n"); - return ret; + goto out; } debug("Reading back new partition table\n"); + /* + * Empty the existing disk_partitions list, as otherwise the memory in + * the original list is unreachable. + */ + del_gpt_info(); numparts = get_gpt_info(dev_desc); - if (numparts <= 0) - return numparts ? numparts : -ENODEV; + if (numparts <= 0) { + ret = numparts ? numparts : -ENODEV; + goto out; + } printf("new partition table with %d partitions is:\n", numparts); print_gpt_info(); - del_gpt_info(); - free(partitions_list); - free(str_disk_guid); + out: free(new_partitions); + free(str_disk_guid); + free(partitions_list); return ret; } #endif diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 4033d90c8e..90f76bbc20 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -393,15 +393,18 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) sprintf(message, "Please enter '%s': ", argv[1]); } else { /* env_ask envname message1 ... messagen [size] */ - for (i = 2, pos = 0; i < argc; i++) { + for (i = 2, pos = 0; i < argc && pos+1 < sizeof(message); i++) { if (pos) message[pos++] = ' '; - strcpy(message + pos, argv[i]); + strncpy(message + pos, argv[i], sizeof(message) - pos); pos += strlen(argv[i]); } - message[pos++] = ' '; - message[pos] = '\0'; + if (pos < sizeof(message) - 1) { + message[pos++] = ' '; + message[pos] = '\0'; + } else + message[CONFIG_SYS_CBSIZE - 1] = '\0'; } if (size >= CONFIG_SYS_CBSIZE) @@ -927,7 +930,7 @@ NXTARG: ; H_MATCH_KEY | H_MATCH_IDENT, &ptr, size, argc, argv); if (len < 0) { - error("Cannot export environment: errno = %d\n", errno); + pr_err("Cannot export environment: errno = %d\n", errno); return 1; } sprintf(buf, "%zX", (size_t)len); @@ -947,7 +950,7 @@ NXTARG: ; H_MATCH_KEY | H_MATCH_IDENT, &res, ENV_SIZE, argc, argv); if (len < 0) { - error("Cannot export environment: errno = %d\n", errno); + pr_err("Cannot export environment: errno = %d\n", errno); return 1; } @@ -1082,7 +1085,7 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag, if (himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR, crlf_is_lf, 0, NULL) == 0) { - error("Environment import failed: errno = %d\n", errno); + pr_err("Environment import failed: errno = %d\n", errno); return 1; } gd->flags |= GD_FLG_ENV_READY; @@ -616,7 +616,7 @@ static int label_localboot(struct pxe_label *label) static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) { char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL }; - char initrd_str[22]; + char initrd_str[28]; char mac_str[29] = ""; char ip_str[68] = ""; int bootm_argc = 2; @@ -648,9 +648,9 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) } bootm_argv[2] = initrd_str; - strcpy(bootm_argv[2], env_get("ramdisk_addr_r")); + strncpy(bootm_argv[2], env_get("ramdisk_addr_r"), 18); strcat(bootm_argv[2], ":"); - strcat(bootm_argv[2], env_get("filesize")); + strncat(bootm_argv[2], env_get("filesize"), 9); } if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) { @@ -689,9 +689,9 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) } if (label->append) - strcpy(bootargs, label->append); - strcat(bootargs, ip_str); - strcat(bootargs, mac_str); + strncpy(bootargs, label->append, sizeof(bootargs)); + strncat(bootargs, ip_str, sizeof(bootargs) - strlen(bootargs)); + strncat(bootargs, mac_str, sizeof(bootargs) - strlen(bootargs)); cli_simple_process_macros(bootargs, finalbootargs); env_set("bootargs", finalbootargs); diff --git a/cmd/regulator.c b/cmd/regulator.c index 2ef5bc9a82..b605255180 100644 --- a/cmd/regulator.c +++ b/cmd/regulator.c @@ -71,7 +71,7 @@ static int curr_dev_and_platdata(struct udevice **devp, *uc_pdata = dev_get_uclass_platdata(*devp); if (!*uc_pdata) { - error("Regulator: %s - missing platform data!", currdev->name); + pr_err("Regulator: %s - missing platform data!", currdev->name); return CMD_RET_FAILURE; } diff --git a/cmd/thordown.c b/cmd/thordown.c index 436b7f5631..1bb5fc2ec2 100644 --- a/cmd/thordown.c +++ b/cmd/thordown.c @@ -33,7 +33,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) int controller_index = simple_strtoul(usb_controller, NULL, 0); ret = board_usb_init(controller_index, USB_INIT_DEVICE); if (ret) { - error("USB init failed: %d", ret); + pr_err("USB init failed: %d", ret); ret = CMD_RET_FAILURE; goto exit; } @@ -42,14 +42,14 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ret = thor_init(); if (ret) { - error("THOR DOWNLOAD failed: %d", ret); + pr_err("THOR DOWNLOAD failed: %d", ret); ret = CMD_RET_FAILURE; goto exit; } ret = thor_handle(); if (ret) { - error("THOR failed: %d", ret); + pr_err("THOR failed: %d", ret); ret = CMD_RET_FAILURE; goto exit; } diff --git a/cmd/time.c b/cmd/time.c index de57e3b9dd..2cd8b1a577 100644 --- a/cmd/time.c +++ b/cmd/time.c @@ -28,7 +28,7 @@ static int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong cycles = 0; int retval = 0; - int repeatable; + int repeatable = 0; if (argc == 1) return CMD_RET_USAGE; diff --git a/cmd/tpm_test.c b/cmd/tpm_test.c index 3306405948..37ad2ff33d 100644 --- a/cmd/tpm_test.c +++ b/cmd/tpm_test.c @@ -303,12 +303,12 @@ static int test_readonly(void) index_0 += 1; if (tpm_nv_write_value(INDEX0, (uint8_t *)&index_0, sizeof(index_0) != TPM_SUCCESS)) { - error("\tcould not write index 0\n"); + pr_err("\tcould not write index 0\n"); } tpm_nv_write_value_lock(INDEX0); if (tpm_nv_write_value(INDEX0, (uint8_t *)&index_0, sizeof(index_0)) == TPM_SUCCESS) - error("\tindex 0 is not locked\n"); + pr_err("\tindex 0 is not locked\n"); printf("\tdone\n"); return 0; @@ -471,7 +471,7 @@ static int test_write_limit(void) case TPM_MAXNVWRITES: assert(i >= TPM_MAX_NV_WRITES_NOOWNER); default: - error("\tunexpected error code %d (0x%x)\n", + pr_err("\tunexpected error code %d (0x%x)\n", result, result); } } diff --git a/cmd/usb_gadget_sdp.c b/cmd/usb_gadget_sdp.c index b1d8b2858e..ae4d73c125 100644 --- a/cmd/usb_gadget_sdp.c +++ b/cmd/usb_gadget_sdp.c @@ -28,13 +28,13 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ret = sdp_init(controller_index); if (ret) { - error("SDP init failed: %d", ret); + pr_err("SDP init failed: %d", ret); goto exit; } /* This command typically does not return but jumps to an image */ sdp_handle(controller_index); - error("SDP ended"); + pr_err("SDP ended"); exit: g_dnl_unregister(); diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c index 3353f95c74..cfeecb7068 100644 --- a/cmd/usb_mass_storage.c +++ b/cmd/usb_mass_storage.c @@ -162,21 +162,21 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, controller_index = (unsigned int)(simple_strtoul( usb_controller, NULL, 0)); if (board_usb_init(controller_index, USB_INIT_DEVICE)) { - error("Couldn't init USB controller."); + pr_err("Couldn't init USB controller."); rc = CMD_RET_FAILURE; goto cleanup_ums_init; } rc = fsg_init(ums, ums_count); if (rc) { - error("fsg_init failed"); + pr_err("fsg_init failed"); rc = CMD_RET_FAILURE; goto cleanup_board; } rc = g_dnl_register("usb_dnl_ums"); if (rc) { - error("g_dnl_register failed"); + pr_err("g_dnl_register failed"); rc = CMD_RET_FAILURE; goto cleanup_board; } |