diff options
author | Ram Muthiah <rammuthiah@google.com> | 2020-09-02 16:47:52 -0700 |
---|---|---|
committer | Alistair Delva <adelva@google.com> | 2020-10-02 07:16:53 -0700 |
commit | d45588b9f849166975432dc11b04f1fcf7bfb1e1 (patch) | |
tree | c0cd61923f64c46c097954704ba376a62e78170b | |
parent | 5b1d2444740f7c8db286afe93b5f37f7a79d1909 (diff) | |
download | platform_external_u-boot-master.tar.gz platform_external_u-boot-master.tar.bz2 platform_external_u-boot-master.zip |
Removed all uses of sprintf from the android boot flow and replaced them
with a hex to ascii helper function.
This error is likely due to heap corruption on 4Gig 32bit systems.
Bug: 166816998
Bug: 169336575
Test: Local boot of cuttlefish & acloud
[rammuthiah: Updated change to build post v2020.10 merge]
Signed-off-by: Ram Muthiah <rammuthiah@google.com>
Change-Id: Ie986dea24c8e65736e4132321fb692e460934ef7
-rw-r--r-- | arch/x86/lib/zimage.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c index 6973e0b08a..b30df08f07 100644 --- a/arch/x86/lib/zimage.c +++ b/arch/x86/lib/zimage.c @@ -350,6 +350,33 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } #ifdef CONFIG_ANDROID_BOOT_IMAGE +static char hex_to_char(uint8_t nibble) { + if (nibble < 10) { + return '0' + nibble; + } else { + return 'a' + nibble - 10; + } +} +// Helper function to convert 32bit int to a hex string +static void hex_to_str(char* str, ulong input) { + str[0] = '0'; str[1] = 'x'; + size_t str_idx = 2; + uint32_t byte_extracted; + uint8_t nibble; + // Assume that this is on a little endian system. + for(int byte_idx = 3; byte_idx >= 0; byte_idx--) { + byte_extracted = ((0xFF << (byte_idx*8)) & input) >> (byte_idx*8); + nibble = byte_extracted & 0xF0; + nibble = nibble >> 4; + nibble = nibble & 0xF; + str[str_idx] = hex_to_char(nibble); + str_idx++; + nibble = byte_extracted & 0xF; + str[str_idx] = hex_to_char(nibble); + str_idx++; + } + str[str_idx] = 0; +} int android_bootloader_boot_kernel(const struct andr_boot_info *boot_info) { ulong kernel_address; @@ -364,9 +391,9 @@ int android_bootloader_boot_kernel(const struct andr_boot_info *boot_info) return -1; kernel_address = android_image_get_kload(boot_info); - sprintf(kernel_addr_str, "0x%lx", kernel_address); - sprintf(ramdisk_addr_str, "0x%lx", ramdisk_address); - sprintf(ramdisk_len_str, "0x%lx", ramdisk_len); + hex_to_str(kernel_addr_str, kernel_address); + hex_to_str(ramdisk_addr_str, ramdisk_address); + hex_to_str(ramdisk_len_str , ramdisk_len); printf("Booting kernel at %s with fdt at %s ramdisk %s (%s bytes)...\n\n\n", kernel_addr_str, env_get("fdtaddr"), ramdisk_addr_str, ramdisk_len_str); |