diff --git a/common/boot_rkimg.c b/common/boot_rkimg.c index f0d210009c..46d8ea3113 100644 --- a/common/boot_rkimg.c +++ b/common/boot_rkimg.c @@ -5,28 +5,26 @@ */ #include +#include #include -#include -#include -#include +#include +#include #include +#include +#include +#include +#include +#include #include #include #include -#include #include -#include -#include -#include -#include -#include - -#define TAG_KERNEL 0x4C4E524B - -#define DTB_FILE "rk-kernel.dtb" +#define TAG_KERNEL 0x4C4E524B +#define DTB_FILE "rk-kernel.dtb" #define BOOTLOADER_MESSAGE_OFFSET_IN_MISC (16 * 1024) #define BOOTLOADER_MESSAGE_BLK_OFFSET (BOOTLOADER_MESSAGE_OFFSET_IN_MISC >> 9) + DECLARE_GLOBAL_DATA_PTR; struct bootloader_message { @@ -88,26 +86,22 @@ static void boot_lmb_init(bootm_headers_t *images) #endif /* - * non-OTA packaged kernel.img & boot.img - * return the image size on success, and a - * negative value on error. + * non-OTA packaged kernel.img & boot.img return the image size on success, + * and a negative value on error. */ int read_rockchip_image(struct blk_desc *dev_desc, disk_partition_t *part_info, void *dst) { struct rockchip_image *img; int header_len = 8; - int cnt; - int ret; + int cnt, ret; #ifdef CONFIG_ROCKCHIP_CRC u32 crc32; #endif img = memalign(ARCH_DMA_MINALIGN, RK_BLK_SIZE); - if (!img) { - printf("out of memory\n"); + if (!img) return -ENOMEM; - } /* read first block with header imformation */ ret = blk_dread(dev_desc, part_info->start, 1, img); @@ -117,14 +111,15 @@ int read_rockchip_image(struct blk_desc *dev_desc, } if (img->tag != TAG_KERNEL) { - printf("%s: invalid image tag(0x%x)\n", part_info->name, img->tag); + printf("Invalid %s image tag(0x%x)\n", + part_info->name, img->tag); ret = -EINVAL; goto err; } /* * read the rest blks - * total size = image size + 8 bytes header + 4 bytes crc32 + * total size = image size + 8 bytes header + 4 bytes crc32 */ cnt = DIV_ROUND_UP(img->size + 8 + 4, RK_BLK_SIZE); if (!sysmem_alloc_base_by_name((const char *)part_info->name, @@ -138,8 +133,7 @@ int read_rockchip_image(struct blk_desc *dev_desc, ret = blk_dread(dev_desc, part_info->start + 1, cnt - 1, dst + RK_BLK_SIZE - header_len); if (ret != (cnt - 1)) { - printf("%s try to read %d blocks failed, only read %d blocks\n", - part_info->name, cnt - 1, ret); + printf("Read %s part failed, ret=%d\n", part_info->name, ret); ret = -EIO; } else { ret = img->size; @@ -147,8 +141,7 @@ int read_rockchip_image(struct blk_desc *dev_desc, #ifdef CONFIG_ROCKCHIP_CRC printf("%s image CRC32 verify... ", part_info->name); - crc32 = rockchip_crc_verify((unsigned char *)(unsigned long)dst, - img->size + 4); + crc32 = rockchip_crc_verify((uchar *)(unsigned long)dst, img->size + 4); if (!crc32) { printf("fail!\n"); ret = -EINVAL; @@ -165,11 +158,11 @@ err: /* Gets the storage type of the current device */ int get_bootdev_type(void) { - int type = 0; - ulong devnum = 0; char *boot_media = NULL, *devtype = NULL; char boot_options[128] = {0}; static int appended; + ulong devnum = 0; + int type = 0; devtype = env_get("devtype"); devnum = env_get_ulong("devnum", 10, 0); @@ -277,7 +270,7 @@ struct blk_desc *rockchip_get_bootdev(void) dev_desc = blk_get_devnum_by_type(dev_type, devnum); if (!dev_desc) { - printf("%s: can't find dev_desc!\n", __func__); + printf("%s: Can't find dev_desc!\n", __func__); return NULL; } @@ -291,7 +284,7 @@ struct blk_desc *rockchip_get_bootdev(void) mmc = find_mmc_device(devnum); printf("MMC%d: %s, %dMhz\n", devnum, - timing[mmc->timing], mmc->clock / 1000000); + timing[mmc->timing], mmc->clock / 1000000); } #endif @@ -306,6 +299,7 @@ static void rkloader_set_bootloader_msg(struct bootloader_message *bmsg) { struct blk_desc *dev_desc; disk_partition_t part_info; + int ret, cnt; dev_desc = rockchip_get_bootdev(); if (!dev_desc) { @@ -313,28 +307,23 @@ static void rkloader_set_bootloader_msg(struct bootloader_message *bmsg) return; } - int ret = part_get_info_by_name(dev_desc, PART_MISC, - &part_info); + ret = part_get_info_by_name(dev_desc, PART_MISC, &part_info); if (ret < 0) { - printf("not found misc partition.\n"); + printf("%s: Could not found misc partition\n", __func__); return; } - int size = DIV_ROUND_UP(sizeof(struct bootloader_message), RK_BLK_SIZE) - * RK_BLK_SIZE; - ret = blk_dwrite(dev_desc, part_info.start + BOOTLOADER_MESSAGE_BLK_OFFSET, - size >> 9, bmsg); - if (ret != (size >> 9)) { - printf("wape data failed!"); - } + + cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), dev_desc->blksz); + ret = blk_dwrite(dev_desc, + part_info.start + BOOTLOADER_MESSAGE_BLK_OFFSET, + cnt, bmsg); + if (ret != cnt) + printf("%s: Wipe data failed\n", __func__); } void board_run_recovery(void) { - char *const boot_recovery_cmd[] = {"run", "boot_recovery_cmd", NULL}; - - env_set("boot_recovery_cmd", "bootrkp boot-recovery"); - - do_run(NULL, 0, ARRAY_SIZE(boot_recovery_cmd), boot_recovery_cmd); + run_command("bootrkp boot-recovery", 0); } void board_run_recovery_wipe_data(void) @@ -342,6 +331,7 @@ void board_run_recovery_wipe_data(void) struct bootloader_message bmsg; struct blk_desc *dev_desc; disk_partition_t part_info; + int ret; printf("Rebooting into recovery to do wipe_data\n"); dev_desc = rockchip_get_bootdev(); @@ -350,20 +340,17 @@ void board_run_recovery_wipe_data(void) return; } - int ret; - - ret = part_get_info_by_name(dev_desc, PART_MISC, - &part_info); - + ret = part_get_info_by_name(dev_desc, PART_MISC, &part_info); if (ret < 0) { - printf("not found misc partition, just run recovery.\n"); + printf("%s: Could not found misc partition, just run recovery\n", + __func__); board_run_recovery(); } memset((char *)&bmsg, 0, sizeof(struct bootloader_message)); strcpy(bmsg.command, "boot-recovery"); - bmsg.status[0] = 0; strcpy(bmsg.recovery, "recovery\n--wipe_data"); + bmsg.status[0] = 0; rkloader_set_bootloader_msg(&bmsg); @@ -385,15 +372,13 @@ void board_run_recovery_wipe_data(void) */ int rockchip_get_boot_mode(void) { + struct bootloader_message *bmsg = NULL; struct blk_desc *dev_desc; disk_partition_t part_info; - struct bootloader_message *bmsg = NULL; - int size = DIV_ROUND_UP(sizeof(struct bootloader_message), RK_BLK_SIZE) - * RK_BLK_SIZE; - int ret; uint32_t reg_boot_mode; char *env_reboot_mode; int clear_boot_reg = 0; + int ret, cnt; /* * Here, we mainly check for: @@ -419,18 +404,19 @@ int rockchip_get_boot_mode(void) printf("%s: dev_desc is NULL!\n", __func__); return -ENODEV; } - ret = part_get_info_by_name(dev_desc, PART_MISC, - &part_info); + + ret = part_get_info_by_name(dev_desc, PART_MISC, &part_info); if (ret < 0) { - printf("get part %s fail %d\n", PART_MISC, ret); + printf("%s: Could not found misc partition\n", __func__); goto fallback; } - bmsg = memalign(ARCH_DMA_MINALIGN, size); + cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), dev_desc->blksz); + bmsg = memalign(ARCH_DMA_MINALIGN, cnt * dev_desc->blksz); ret = blk_dread(dev_desc, part_info.start + BOOTLOADER_MESSAGE_BLK_OFFSET, - size >> 9, bmsg); - if (ret != (size >> 9)) { + cnt, bmsg); + if (ret != cnt) { free(bmsg); return -EIO; } @@ -523,22 +509,19 @@ static void fdt_ramdisk_skip_relocation(void) int boot_rockchip_image(struct blk_desc *dev_desc, disk_partition_t *boot_part) { - ulong fdt_addr_r = env_get_ulong("fdt_addr_r", 16, 0); ulong ramdisk_addr_r = env_get_ulong("ramdisk_addr_r", 16, 0); ulong kernel_addr_r = env_get_ulong("kernel_addr_r", 16, 0); + ulong fdt_addr_r = env_get_ulong("fdt_addr_r", 16, 0); disk_partition_t kernel_part; int ramdisk_size; int kernel_size; int fdt_size; int ret = 0; - int part_num; printf("=Booting Rockchip format image=\n"); - part_num = part_get_info_by_name(dev_desc, PART_KERNEL, - &kernel_part); - - if (part_num < 0 || !boot_part) { - printf("%s kernel or boot part info error\n", __func__); + ret = part_get_info_by_name(dev_desc, PART_KERNEL, &kernel_part); + if (ret < 0 || !boot_part) { + printf("Could not found misc partition\n"); ret = -EINVAL; goto out; } @@ -546,7 +529,7 @@ int boot_rockchip_image(struct blk_desc *dev_desc, disk_partition_t *boot_part) kernel_size = read_rockchip_image(dev_desc, &kernel_part, (void *)kernel_addr_r); if (kernel_size < 0) { - printf("%s kernel part read error\n", __func__); + printf("Read kernel image failed, ret=%d\n", ret); ret = -EINVAL; goto out; } @@ -554,8 +537,7 @@ int boot_rockchip_image(struct blk_desc *dev_desc, disk_partition_t *boot_part) ramdisk_size = read_rockchip_image(dev_desc, boot_part, (void *)ramdisk_addr_r); if (ramdisk_size < 0) { - printf("%s ramdisk part %s read error\n", __func__, - boot_part->name); + printf("Read ramdisk image failed, ret=%d\n", ret); ramdisk_size = 0; } @@ -571,7 +553,7 @@ int boot_rockchip_image(struct blk_desc *dev_desc, disk_partition_t *boot_part) if (gd->fdt_blob != (void *)fdt_addr_r) { fdt_size = rockchip_read_dtb_file((void *)fdt_addr_r); if (fdt_size < 0) { - printf("%s fdt read error\n", __func__); + printf("Read fdt failed, ret=%d\n", fdt_size); ret = -EINVAL; goto out; } @@ -589,8 +571,9 @@ int boot_rockchip_image(struct blk_desc *dev_desc, disk_partition_t *boot_part) #if defined(CONFIG_ARM64) char cmdbuf[64]; - sprintf(cmdbuf, "booti 0x%lx 0x%lx:0x%x 0x%lx", - kernel_addr_r, ramdisk_addr_r, ramdisk_size, fdt_addr_r); + + snprintf(cmdbuf, 64, "booti 0x%lx 0x%lx:0x%x 0x%lx", + kernel_addr_r, ramdisk_addr_r, ramdisk_size, fdt_addr_r); run_command(cmdbuf, 0); #else /* We asume it's always zImage on 32-bit platform */