void *kdump_core_header_init(const struct mrdump_control_block *kparams, uint64_t kmem_address, uint64_t kmem_size) { voprintf_info("kernel page offset %llu\n", kparams->machdesc.page_offset); if (kparams->machdesc.page_offset <= 0xffffffffULL) { voprintf_info("32b kernel detected\n"); return kdump_core32_header_init(kparams, kmem_address, kmem_size); } else { voprintf_info("64b kernel detected\n"); return kdump_core64_header_init(kparams, kmem_address, kmem_size); } }
part_t *card_dump_init(int dev, const char *part_name) { part_t *part = mt_part_get_partition((char *)part_name); if (part == NULL) { return NULL; } #ifdef MTK_GPT_SCHEME_SUPPORT voprintf_info("%s offset: %lu, size: %lu Mb\n", part->info->name, part->start_sect, (part->nr_sects * BLK_SIZE) / 0x100000UL); #else voprintf_info("%s offset: %lu, size: %lu Mb\n", part->name, part->startblk, (part->blknum * BLK_SIZE) / 0x100000UL); #endif return part; }
static void kdump_ui(struct mrdump_control_block *mrdump_cblock) { video_clean_screen(); video_set_cursor(0, 0); mrdump_status_error("Unknown error\n"); voprintf_info("Kdump triggerd by '%s'\n", mrdump_mode2string(mrdump_cblock->crash_record.reboot_mode)); struct aee_timer elapse_time; aee_timer_init(&elapse_time); uint32_t total_dump_size = memory_size(); aee_timer_start(&elapse_time); switch (mrdump_cblock->machdesc.output_device) { case MRDUMP_DEV_NULL: kdump_null_output(mrdump_cblock, total_dump_size); break; #if 0 case MRDUMP_DEV_SDCARD: kdump_sdcard_output(mrdump_cblock, total_dump_size); break; #endif case MRDUMP_DEV_EMMC: kdump_emmc_output(mrdump_cblock, total_dump_size); break; default: voprintf_error("Unknown device id %d\n", mrdump_cblock->machdesc.output_device); } aee_timer_stop(&elapse_time); voprintf_info("Reset count down %d ...\n", MRDUMP_DELAY_TIME); mtk_wdt_restart(); int timeout = MRDUMP_DELAY_TIME; while(timeout-- >= 0) { mdelay(1000); mtk_wdt_restart(); voprintf_info("\rsec %d", timeout); } aee_mrdump_flush_cblock(); video_clean_screen(); video_set_cursor(0, 0); }
int kdump_null_output(const struct mrdump_control_block *mrdump_cb, uint32_t total_dump_size) { const struct mrdump_machdesc *kparams = &mrdump_cb->machdesc; voprintf_info("null dumping(address %x, size:%dM)\n", kparams->phys_offset, total_dump_size / 0x100000UL); mtk_wdt_restart(); bool ok = true; void *bufp = kdump_core_header_init(mrdump_cb, (uint32_t)kparams->phys_offset, total_dump_size); if (bufp != NULL) { mtk_wdt_restart(); struct kzip_file *zf = kzip_open(NULL, null_write_cb); if (zf != NULL) { struct kzip_memlist memlist[3]; memlist[0].address = bufp; memlist[0].size = KDUMP_CORE_SIZE; memlist[1].address = kparams->phys_offset; memlist[1].size = total_dump_size; memlist[2].address = NULL; memlist[2].size = 0; kzip_add_file(zf, memlist, "SYS_COREDUMP"); kzip_close(zf); zf = NULL; } else { ok = false; } free(bufp); } mtk_wdt_restart(); if (ok) { voprintf_info("%s: dump finished, dumped.\n", __func__); mrdump_status_ok("NULL-OUTPUT\n"); } return 0; }
static int kzip_write_current(struct kzip_file *zfile, void *buf, int len) { KZIP_DEBUG("%s: write_cb %p len %d\n", __func__, zfile->write_cb, len); int retval = zfile->write_cb(zfile->handle, buf, len); if (retval > 0) { zfile->current_size += retval; } if ((zfile->current_size - zfile->reported_size) >= KDUMP_SIZE_REPORT) { voprintf_info(".. Written %dM\n", zfile->current_size / 0x100000); zfile->reported_size = zfile->current_size; } if ((zfile->current_size - zfile->wdk_kick_size) >= KDUMP_TICK_WDT) { mtk_wdt_restart(); zfile->wdk_kick_size = zfile->current_size; } return retval; }
bool kzip_add_file(struct kzip_file *zfile, const struct kzip_memlist *memlist, const char *zfilename) { int ret, flush; z_stream strm; struct aee_timer zip_time; if (zfile->entries_num >= KZIP_ENTRY_MAX) { voprintf_error("Too manry zip entry %d\n", zfile->entries_num); return false; } voprintf_debug("%s: zf %p(%p) %s\n", __func__, zfile, zfile->write_cb, zfilename); struct kzip_entry *zentry = &zfile->zentries[zfile->entries_num++]; zentry->filename = strdup(zfilename); zentry->localheader_offset = zfile->current_size; zentry->level = DEF_MEM_LEVEL; KZIP_DEBUG("%s: write local header\n", __func__); uint8_t zip_localheader[128]; int hsize = put_localheader(zip_localheader, zfilename, DEF_MEM_LEVEL); if (kzip_write_current(zfile, zip_localheader, hsize) != hsize) { return false; } KZIP_DEBUG("%s: init compressor\n", __func__); /* allocate deflate state */ strm.workspace = malloc(zlib_deflate_workspacesize(-MAX_WBITS, DEF_MEM_LEVEL)); ret = zlib_deflateInit2(&strm, zentry->level, Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY); if (ret != Z_OK) { voprintf_error("zlib compress init failed\n"); free(strm.workspace); return false; } uint8_t *out = malloc(CHUNK); aee_timer_init(&zip_time); aee_timer_start(&zip_time); /* compress until end of file */ do { flush = (memlist->size == 0) ? Z_FINISH : Z_NO_FLUSH; KZIP_DEBUG("-- Compress memory %x, size %d\n", memlist->address, memlist->size); strm.avail_in = memlist->size; strm.next_in = memlist->address; /* run deflate() on input until output buffer not full, finish compression if all of source has been read in */ do { strm.avail_out = CHUNK; strm.next_out = out; ret = zlib_deflate(&strm, flush); /* no bad return value */ assert(ret != Z_STREAM_ERROR); /* state not clobbered */ int have = CHUNK - strm.avail_out; if (have > 0) { aee_timer_stop(&zip_time); if (kzip_write_current(zfile, out, have) != have) { goto error; } aee_timer_start(&zip_time); } } while (strm.avail_out == 0); assert(strm.avail_in == 0); /* all input will be used */ memlist++; /* done when last data in file processed */ } while (flush != Z_FINISH); assert(ret == Z_STREAM_END); /* stream will be complete */ /* clean up and return */ (void)zlib_deflateEnd(&strm); free(strm.workspace); free(out); aee_timer_stop(&zip_time); voprintf_info("Zip time: %d sec\n", zip_time.acc_ms / 1000); zentry->comp_size = strm.total_out; zentry->uncomp_size = strm.total_in; zentry->crc32 = strm.crc32 ^ 0xffffffffUL; return true; error: free(strm.workspace); free(out); (void)zlib_deflateEnd(&strm); return false; }