/* * JFFS2 -- Journalling Flash File System, Version 2. * * Copyright © 2001-2007 Red Hat, Inc. * Copyright © 2004-2010 David Woodhouse * * Created by David Woodhouse * * For licensing information, see the file 'LICENCE' in this directory. * */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include #include #include #include #include #include #include #include "nodelist.h" #include "debug.h" #ifdef JFFS2_DBG_SANITY_CHECKS void __jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) { if (unlikely(jeb && jeb->used_size + jeb->dirty_size + jeb->free_size + jeb->wasted_size + jeb->unchecked_size != c->sector_size)) { JFFS2_ERROR("eeep, space accounting for block at 0x%08x is screwed.\n", jeb->offset); JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + wasted %#08x + unchecked %#08x != total %#08x.\n", jeb->free_size, jeb->dirty_size, jeb->used_size, jeb->wasted_size, jeb->unchecked_size, c->sector_size); BUG(); } if (unlikely(c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size + c->wasted_size + c->unchecked_size != c->flash_size)) { JFFS2_ERROR("eeep, space accounting superblock info is screwed.\n"); JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + erasing %#08x + bad %#08x + wasted %#08x + unchecked %#08x != total %#08x.\n", c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size, c->wasted_size, c->unchecked_size, c->flash_size); BUG(); } } void __jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) { spin_lock(&c->erase_completion_lock); jffs2_dbg_acct_sanity_check_nolock(c, jeb); spin_unlock(&c->erase_completion_lock); } #endif /* JFFS2_DBG_SANITY_CHECKS */ #ifdef JFFS2_DBG_PARANOIA_CHECKS /* * Check the fragtree. */ void __jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f) { mutex_lock(&f->sem); __jffs2_dbg_fragtree_paranoia_check_nolock(f); mutex_unlock(&f->sem); } void __jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f) { struct jffs2_node_frag *frag; int bitched = 0; for (frag = frag_first(&f->fragtree); frag; frag = frag_next(frag)) { struct jffs2_full_dnode *fn = frag->node; if (!fn || !fn->raw) continue; if (ref_flags(fn->raw) == REF_PRISTINE) { if (fn->frags > 1) { JFFS2_ERROR("REF_PRISTINE node at 0x%08x had %d frags. Tell dwmw2.\n", ref_offset(fn->raw), fn->frags); bitched = 1; } /* A hole node which isn't multi-page should be garbage-collected and merged anyway, so we just check for the frag size here, rather than mucking around with actually reading the node and checking the compression type, which is the real way to tell a hole node. */ if (frag->ofs & (PAGE_CACHE_SIZE-1) && frag_prev(frag) && frag_prev(frag)->size < PAGE_CACHE_SIZE && frag_prev(frag)->node) { JFFS2_ERROR("REF_PRISTINE node at 0x%08x had a previous non-hole frag in the same page. Tell dwmw2.\n", ref_offset(fn->raw)); bitched = 1; } if ((frag->ofs+frag->size) & (PAGE_CACHE_SIZE-1) && frag_next(frag) && frag_next(frag)->size < PAGE_CACHE_SIZE && frag_next(frag)->node) { JFFS2_ERROR("REF_PRISTINE node at 0x%08x (%08x-%08x) had a following non-hole frag in the same page. Tell dwmw2.\n", ref_offset(fn->raw), frag->ofs, frag->ofs+frag->size); bitched = 1; } } } if (bitched) { JFFS2_ERROR("fragtree is corrupted.\n"); __jffs2_dbg_dump_fragtree_nolock(f); BUG(); } } /* * Check if the flash contains all 0xFF before we start writing. */ void __jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c, uint32_t ofs, int len) { size_t retlen; int ret, i; unsigned char *buf; buf = kmalloc(len, GFP_KERNEL); if (!buf) return; ret = jffs2_flash_read(c, ofs, len, &retlen, buf); if (ret || (retlen != len)) { JFFS2_WARNING("read %d bytes failed or short. ret %d, retlen %zd.\n", len, ret, retlen); kfree(buf); return; } ret = 0; for (i = 0; i < len; i++) if (buf[i] != 0xff) ret = 1; if (ret) { JFFS2_ERROR("argh, about to write node to %#08x on flash, but there are data already there. The first corrupted byte is at %#08x offset.\n", ofs, ofs + i); __jffs2_dbg_dump_buffer(buf, len, ofs); kfree(buf); BUG(); } kfree(buf); } void __jffs2_dbg_superblock_counts(struct jffs2_sb_info *c) { struct jffs2_eraseblock *jeb; uint32_t free = 0, dirty = 0, used = 0, wasted = 0, erasing = 0, bad = 0, unchecked = 0; int nr_counted = 0; int dump = 0; if (c->gcblock) { nr_counted++; free += c->gcblock->free_size; dirty += c->gcblock->dirty_size; used += c->gcblock->used_size; wasted += c->gcblock->wasted_size; unchecked += c->gcblock->unchecked_size; } if (c->nextblock) { nr_counted++; free += c->nextblock->free_size; dirty += c->nextblock->dirty_size; used += c->nextblock->used_size; wasted += c->nextblock->wasted_size; unchecked += c->nextblock->unchecked_size; } list_for_each_entry(jeb, &c->clean_list, list) { nr_counted++; free += jeb->free_size; dirty += jeb->dirty_size; used += jeb->used_size; wasted += jeb->wasted_size; unchecked += jeb->unchecked_size; } list_for_each_entry(jeb, &c->very_dirty_list, li
/*
 *  linux/arch/m68k/hp300/time.c
 *
 *  Copyright (C) 1998 Philip Blundell <philb@gnu.org>
 *
 *  This file contains the HP300-specific time handling code.
 */

#include <asm/ptrace.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/kernel_stat.h>
#include <linux/interrupt.h>
#include <asm/machdep.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/traps.h>
#include <asm/blinken.h>

/* Clock hardware definitions */

#define CLOCKBASE	0xf05f8000

#define	CLKCR1		0x1
#define	CLKCR2		0x3
#define	CLKCR3		CLKCR1
#define	CLKSR		CLKCR2
#define	CLKMSB1		0x5
#define	CLKMSB2		0x9
#define	CLKMSB3		0xD

/* This is for machines which generate the exact clock. */
#define USECS_PER_JIFFY (1000000/HZ)

#define INTVAL ((10000 / 4) - 1)

static irqreturn_t hp300_tick(int irq, void *dev_id)
{
	unsigned long tmp;
	irq_handler_t vector = dev_id;
	in_8(CLOCKBASE + CLKSR);
	asm volatile ("movpw %1@(5),%0" : "=d" (tmp) : "a" (CLOCKBASE));
	/* Turn off the network and SCSI leds */
	blinken_leds(0, 0xe0);
	return vector(irq, NULL);
}

u32 hp300_gettimeoffset(void)
{
  /* Read current timer 1 value */
  unsigned char lsb, msb1, msb2;
  unsigned short ticks;

  msb1 = in_8(CLOCKBASE + 5);
  lsb = in_8(CLOCKBASE + 7);
  msb2 = in_8(CLOCKBASE + 5);
  if (msb1 != msb2)
    /* A carry happened while we were reading.  Read it again */
    lsb = in_8(CLOCKBASE + 7);
  ticks = INTVAL - ((msb2 << 8) | lsb);
  return ((USECS_PER_JIFFY * ticks) / INTVAL) * 1000;
}

void __init hp300_sched_init(irq_handler_t vector)
{
  out_8(CLOCKBASE + CLKCR2, 0x1);		/* select CR1 */
  out_8(CLOCKBASE + CLKCR1, 0x1);		/* reset */

  asm volatile(" movpw %0,%1@(5)" : : "d" (INTVAL), "a" (CLOCKBASE));

  if (request_irq(IRQ_AUTO_6, hp300_tick, 0, "timer tick", vector))
    pr_err("Couldn't register timer interrupt\n");

  out_8(CLOCKBASE + CLKCR2, 0x1);		/* select CR1 */
  out_8(CLOCKBASE + CLKCR1, 0x40);		/* enable irq */
}
n", offs, offs + len, len); i = skip = offs % JFFS2_BUFDUMP_BYTES_PER_LINE; offs = offs & ~(JFFS2_BUFDUMP_BYTES_PER_LINE - 1); if (skip != 0) printk(JFFS2_DBG "%#08x: ", offs); while (skip--) printk(" "); while (i < len) { if ((i % JFFS2_BUFDUMP_BYTES_PER_LINE) == 0 && i != len -1) { if (i != 0) printk("\n"); offs += JFFS2_BUFDUMP_BYTES_PER_LINE; printk(JFFS2_DBG "%0#8x: ", offs); } printk("%02x ", buf[i]); i += 1; } printk("\n"); } /* * Dump a JFFS2 node. */ void __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs) { union jffs2_node_union node; int len = sizeof(union jffs2_node_union); size_t retlen; uint32_t crc; int ret; printk(JFFS2_DBG_MSG_PREFIX " dump node at offset %#08x.\n", ofs); ret = jffs2_flash_read(c, ofs, len, &retlen, (unsigned char *)&node); if (ret || (retlen != len)) { JFFS2_ERROR("read %d bytes failed or short. ret %d, retlen %zd.\n", len, ret, retlen); return; } printk(JFFS2_DBG "magic:\t%#04x\n", je16_to_cpu(node.u.magic)); printk(JFFS2_DBG "nodetype:\t%#04x\n", je16_to_cpu(node.u.nodetype)); printk(JFFS2_DBG "totlen:\t%#08x\n", je32_to_cpu(node.u.totlen)); printk(JFFS2_DBG "hdr_crc:\t%#08x\n", je32_to_cpu(node.u.hdr_crc)); crc = crc32(0, &node.u, sizeof(node.u) - 4); if (crc != je32_to_cpu(node.u.hdr_crc)) { JFFS2_ERROR("wrong common header CRC.\n"); return; } if (je16_to_cpu(node.u.magic) != JFFS2_MAGIC_BITMASK && je16_to_cpu(node.u.magic) != JFFS2_OLD_MAGIC_BITMASK) { JFFS2_ERROR("wrong node magic: %#04x instead of %#04x.\n", je16_to_cpu(node.u.magic), JFFS2_MAGIC_BITMASK); return; } switch(je16_to_cpu(node.u.nodetype)) { case JFFS2_NODETYPE_INODE: printk(JFFS2_DBG "the node is inode node\n"); printk(JFFS2_DBG "ino:\t%#08x\n", je32_to_cpu(node.i.ino)); printk(JFFS2_DBG "version:\t%#08x\n", je32_to_cpu(node.i.version)); printk(JFFS2_DBG "mode:\t%#08x\n", node.i.mode.m); printk(JFFS2_DBG "uid:\t%#04x\n", je16_to_cpu(node.i.uid)); printk(JFFS2_DBG "gid:\t%#04x\n", je16_to_cpu(node.i.gid)); printk(JFFS2_DBG "isize:\t%#08x\n", je32_to_cpu(node.i.isize)); printk(JFFS2_DBG "atime:\t%#08x\n", je32_to_cpu(node.i.atime)); printk(JFFS2_DBG "mtime:\t%#08x\n", je32_to_cpu(node.i.mtime)); printk(JFFS2_DBG "ctime:\t%#08x\n", je32_to_cpu(node.i.ctime)); printk(JFFS2_DBG "offset:\t%#08x\n", je32_to_cpu(node.i.offset)); printk(JFFS2_DBG "csize:\t%#08x\n", je32_to_cpu(node.i.csize)); printk(JFFS2_DBG "dsize:\t%#08x\n", je32_to_cpu(node.i.dsize)); printk(JFFS2_DBG "compr:\t%#02x\n", node.i.compr); printk(JFFS2_DBG "usercompr:\t%#02x\n", node.i.usercompr); printk(JFFS2_DBG "flags:\t%#04x\n", je16_to_cpu(node.i.flags)); printk(JFFS2_DBG "data_crc:\t%#08x\n", je32_to_cpu(node.i.data_crc)); printk(JFFS2_DBG "node_crc:\t%#08x\n", je32_to_cpu(node.i.node_crc)); crc = crc32(0, &node.i, sizeof(node.i) - 8); if (crc != je32_to_cpu(node.i.node_crc)) { JFFS2_ERROR("wrong node header CRC.\n"); return; } break; case JFFS2_NODETYPE_DIRENT: printk(JFFS2_DBG "the node is dirent node\n"); printk(JFFS2_DBG "pino:\t%#08x\n", je32_to_cpu(node.d.pino)); printk(JFFS2_DBG "version:\t%#08x\n", je32_to_cpu(node.d.version)); printk(JFFS2_DBG "ino:\t%#08x\n", je32_to_cpu(node.d.ino)); printk(JFFS2_DBG "mctime:\t%#08x\n", je32_to_cpu(node.d.mctime)); printk(JFFS2_DBG "nsize:\t%#02x\n", node.d.nsize); printk(JFFS2_DBG "type:\t%#02x\n", node.d.type); printk(JFFS2_DBG "node_crc:\t%#08x\n", je32_to_cpu(node.d.node_crc)); printk(JFFS2_DBG "name_crc:\t%#08x\n", je32_to_cpu(node.d.name_crc)); node.d.name[node.d.nsize] = '\0'; printk(JFFS2_DBG "name:\t\"%s\"\n", node.d.name); crc = crc32(0, &node.d, sizeof(node.d) - 8); if (crc != je32_to_cpu(node.d.node_crc)) { JFFS2_ERROR("wrong node header CRC.\n"); return; } break; default: printk(JFFS2_DBG "node type is unknown\n"); break; } } #endif /* JFFS2_DBG_DUMPS || JFFS2_DBG_PARANOIA_CHECKS */