char *emmc_allocate_and_read(int offset, int length) { int size; char *buff = NULL; if (length == 0) { return NULL; } size = ALIGN(length, EMMC_BLOCK_SIZE); buff = kzalloc(size, GFP_KERNEL); if (buff != NULL) { if (card_dump_func_read(buff, size, offset, DUMP_INTO_BOOT_CARD_IPANIC) != 0) { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: read from IPANIC data failed(offset:%d,size:%d)\n", __FUNCTION__, offset, size); kfree(buff); return NULL; } } else { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: Cannot allocate buffer to read(len:%d)\n", __FUNCTION__, length); return NULL; } ipanic_block_scramble(buff, size); return buff; }
char *ipanic_read_size(int off, int len) { int size; char *buff = NULL; if (len == 0) return NULL; size = ALIGN(len, EMMC_BLOCK_SIZE); buff = kzalloc(size, GFP_KERNEL); if (buff == NULL) { LOGE("%s: cannot allocate buffer(len:%d)\n", __func__, len); return NULL; } if (card_dump_func_read(buff, size, off, DUMP_INTO_BOOT_CARD_IPANIC) != 0) { LOGE("%s: read failed(offset:%d,size:%d)\n", __func__, off, size); kfree(buff); return NULL; } return buff; }
static struct aee_oops *emmc_ipanic_oops_copy(void) { struct aee_oops *oops = NULL; struct ipanic_header *hdr = NULL; int hdr_size = ALIGN(sizeof(struct ipanic_header), EMMC_BLOCK_SIZE); hdr = kzalloc(hdr_size, GFP_KERNEL); if (hdr == NULL) { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: Cannot allocate ipanic header memory\n", __FUNCTION__); return NULL; } if (card_dump_func_read((unsigned char *)hdr, hdr_size, 0, EMMC_ID) < 0) { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: emmc panic log header read failed\n", __func__); return NULL; } ipanic_block_scramble((unsigned char *)hdr, hdr_size); if (ipanic_header_check(hdr) != 0) { return NULL; } oops = aee_oops_create(AE_DEFECT_FATAL, AE_KE, IPANIC_MODULE_TAG); if (oops != NULL) { struct ipanic_oops_header *oops_header = (struct ipanic_oops_header *) emmc_allocate_and_read(hdr->oops_header_offset, hdr->oops_header_length); if (oops_header == NULL) { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: Can't read oops header(len:%d)\n", __FUNCTION__, hdr->oops_header_length); goto error_return; } aee_oops_set_process_path(oops, oops_header->process_path); aee_oops_set_backtrace(oops, oops_header->backtrace); kfree(oops_header); if(hdr->oops_detail_length != 0) { oops->detail = emmc_allocate_and_read(hdr->oops_detail_offset, hdr->oops_detail_length); oops->detail_len = hdr->oops_detail_length; }else { #define TMPDETAILSTR "panic detail is empty" oops->detail = kstrdup(TMPDETAILSTR, GFP_KERNEL); oops->detail_len = sizeof TMPDETAILSTR; } if (oops->detail == NULL) { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: read detail failed(len: %d)\n", __FUNCTION__, oops->detail_len); goto error_return; } oops->console = emmc_allocate_and_read(hdr->console_offset, hdr->console_length); oops->console_len = hdr->console_length; if (oops->console == NULL) { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: read console failed(len: %d)\n", __FUNCTION__, oops->console_len); goto error_return; } /*If panic from kernel context, no user sapce info available. Shouldn't fail*/ if (0 == hdr->userspace_info_length) { oops->userspace_info = NULL; oops->userspace_info_len = 0; } else { oops->userspace_info = emmc_allocate_and_read(hdr->userspace_info_offset, hdr->userspace_info_length); oops->userspace_info_len = hdr->userspace_info_length; if (oops->userspace_info == NULL) { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: read usrespace info failed\n", __FUNCTION__); goto error_return; } } oops->android_main = emmc_allocate_and_read(hdr->android_main_offset, hdr->android_main_length); oops->android_main_len = hdr->android_main_length; if (oops->android_main == NULL) { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: read android_main failed\n", __FUNCTION__); goto error_return; } oops->android_radio = emmc_allocate_and_read(hdr->android_radio_offset, hdr->android_radio_length); oops->android_radio_len = hdr->android_radio_length; if (oops->android_radio == NULL) { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: read android_radio failed\n", __FUNCTION__); goto error_return; } oops->android_system = emmc_allocate_and_read(hdr->android_system_offset, hdr->android_system_length); oops->android_system_len = hdr->android_system_length; if (oops->android_system == NULL) { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: read android_system failed\n", __FUNCTION__); goto error_return; } xlog_printk(ANDROID_LOG_DEBUG, IPANIC_LOG_TAG, "ipanic_oops_copy return OK\n"); kfree(hdr); return oops; } else { xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG, "%s: kmalloc failed at header\n", __FUNCTION__); kfree(hdr); return NULL; } error_return: kfree(hdr); aee_oops_free(oops); return NULL; }
static int emmc_read_last_kmsg(void) { int size; struct proc_dir_entry *entry; struct ram_console_buffer *bufp = NULL; #ifdef MTK_GPT_SCHEME_SUPPORT int emmc_ready_flag = 0; int count = 0; emmc_ready_flag = get_emmc_dump_status(); while (emmc_ready_flag != 1) { msleep(2000); if (emmc_ready_flag == -1) { pr_err("emmc have no expd partition!\n"); return 1; } pr_err("emmc expd not ready!\n"); emmc_ready_flag = get_emmc_dump_status(); count++; if (count > 100) { pr_err("emmc mount expd partition error!\n"); return 1; } } #endif size = ram_console_buffer_size + sizeof(struct ram_console_buffer); size = size / EMMC_BLOCK_SIZE; size *= EMMC_BLOCK_SIZE; ram_console2_log = kzalloc(size, GFP_KERNEL); if (ram_console2_log == NULL) { pr_err("ram_console: malloc size 2 error!\n"); return 1; } if (card_dump_func_read(ram_console2_log, size, EMMC_ADDR, DUMP_INTO_BOOT_CARD_IPANIC) != 0) { kfree(ram_console2_log); ram_console2_log = NULL; pr_err("ram_console: read emmc data 2 error!\n"); return 1; } bufp = (struct ram_console_buffer *)ram_console2_log; if (bufp->sig != RAM_CONSOLE_SIG) { kfree(ram_console2_log); ram_console2_log = NULL; pr_err("ram_console: emmc read data sig is not match!\n"); return 1; } entry = proc_create("last_kmsg2", 0444, NULL, &ram_console2_file_ops); if (!entry) { pr_err("ram_console: failed to create proc entry\n"); kfree(ram_console2_log); ram_console2_log = NULL; return 1; } pr_err("ram_console: create last_kmsg2 ok.\n"); return 0; }