Exemplo n.º 1
0
int ipanic_write_log_buf(struct mtd_info *mtd, unsigned int off, struct ipanic_log_index start, struct ipanic_log_index end)  
{
	struct mtd_ipanic_data *ctx = &mtd_drv_ctx;
	int saved_oip;
	int rc, rc2;
	unsigned int last_chunk = 0, copy_count = 0;

#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0)
    int log_copy_start = start.value;
    int log_copy_end = end.value;
    if (log_copy_start == log_copy_end) {
      int rc3 = mtd_ipanic_block_write(ctx, off, 5);
      return rc3;
    }
#else
    struct kmsg_dumper dumper;
    dumper.active = true;
    dumper.cur_idx = start.idx;
    dumper.cur_seq = start.seq;
    dumper.next_idx = end.idx;
    dumper.next_seq = end.seq;
    if (dumper.cur_idx == dumper.next_idx) {
        int rc3 = mtd_ipanic_block_write(ctx, off, 5);
        return rc3; 
    } 
#endif
    
	while (!last_chunk) {
		saved_oip = oops_in_progress;
		oops_in_progress = 1;
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0)		
		rc = log_buf_copy2(ctx->bounce, mtd->writesize, log_copy_start, log_copy_end);
		BUG_ON(rc < 0);
		log_copy_start += rc;
#else		
		rc = ipanic_kmsg_dump3(&dumper, ctx->bounce, PAGE_SIZE);
		BUG_ON(rc < 0);
#endif
		copy_count += rc;
		if (rc != mtd->writesize)
			last_chunk = rc;

		oops_in_progress = saved_oip;
		if (rc <= 0)
			break;

		rc2 = mtd_ipanic_block_write(ctx, off, rc);
		if (rc2 <= 0) {
			xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG,
			       "aee-ipanic: Flash write failed (%d)\n", rc2);
			return rc2;
		}
		off += rc2;
	}
	return copy_count;
}
static int ipanic_write_userspace(struct mtd_ipanic_data *ctx, unsigned int off)
{
	int saved_oip, rc, rc2;
	unsigned int copy_count = 0;

	memset(ctx->bounce, 0, PAGE_SIZE);
	DumpNativeInfo();

	while (1) {
		saved_oip = oops_in_progress;
		oops_in_progress = 1;
		rc = panic_dump_user_info(ctx->bounce, ctx->mtd->writesize, copy_count);
		oops_in_progress = saved_oip;

		if (rc <= 0)
			break;

		copy_count += rc;
		rc2 = mtd_ipanic_block_write(ctx, off, rc);
		if (rc2 <= 0) {
			xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG,
				    "%s: Flash write failed (%d)\n", __func__, rc2);
			return rc2;
		}
		off += rc2;
	}
	xlog_printk(ANDROID_LOG_DEBUG, IPANIC_LOG_TAG, "%s: count %d, strlen(NativeInfo):%d, off:%d\n", __func__, copy_count, strlen(NativeInfo), off);
	return copy_count;
}
static int ipanic_write_android_buf(struct mtd_info *mtd, unsigned int off, int type)
{
	struct mtd_ipanic_data *ctx = &mtd_drv_ctx;
	int saved_oip;
	int rc, rc2;
	unsigned int last_chunk = 0, copy_count = 0;

	while (!last_chunk) {
		saved_oip = oops_in_progress;
		oops_in_progress = 1;
		rc = panic_dump_android_log(ctx->bounce, mtd->writesize, type);
		BUG_ON(rc < 0);
		copy_count += rc;
		if (rc == 0)
			last_chunk = rc;

		oops_in_progress = saved_oip;
		if (rc <= 0)
			break;

		rc2 = mtd_ipanic_block_write(ctx, off, rc);
		if (rc2 <= 0) {
			xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG,
			       "aee-ipanic: Flash write failed (%d)\n", rc2);
			return rc2;
		}
		off += rc2;
	}
	//xlog_printk(ANDROID_LOG_DEBUG, IPANIC_LOG_TAG, "dump droid log type %d, count %d\n", type, copy_count);
	return copy_count;
}
/*
 * Writes the contents of the console to the specified offset in flash.
 * Returns number of bytes written
 */
static int ipanic_write_log_buf(struct mtd_info *mtd, unsigned int off, int log_copy_start, int log_copy_end)
{
	struct mtd_ipanic_data *ctx = &mtd_drv_ctx;
	int saved_oip;
	int rc, rc2;
	unsigned int last_chunk = 0, copy_count = 0;

	while (!last_chunk) {
		saved_oip = oops_in_progress;
		oops_in_progress = 1;
		rc = log_buf_copy2(ctx->bounce, mtd->writesize, log_copy_start, log_copy_end);
		BUG_ON(rc < 0);
		log_copy_start += rc;
		copy_count += rc;
		if (rc != mtd->writesize)
			last_chunk = rc;

		oops_in_progress = saved_oip;
		if (rc <= 0)
			break;

		rc2 = mtd_ipanic_block_write(ctx, off, rc);
		if (rc2 <= 0) {
			xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG,
			       "aee-ipanic: Flash write failed (%d)\n", rc2);
			return rc2;
		}
		off += rc2;
	}
	return copy_count;
}
static int mtd_ipanic_write_oops_header(struct mtd_info *mtd, unsigned int off)
{
	int wlen = 0, rc;
	struct mtd_ipanic_data *ctx = &mtd_drv_ctx;
	u8 *raw_oops_header = (u8 *)&oops_header;
	while (wlen < sizeof(struct ipanic_oops_header)) {
		int writesize = sizeof(struct ipanic_oops_header) - wlen;
		if (writesize > mtd->writesize)
			writesize = mtd->writesize;

		memcpy(ctx->bounce, raw_oops_header + wlen, writesize);
		rc = mtd_ipanic_block_write(ctx, off + wlen, writesize);
		if (rc < 0) {
			return rc;
		}
		wlen += writesize;
	}
	return wlen;
}