Exemple #1
0
static long	 
flashread(Chan *c, void *buf, long n, vlong offset)
{
	Flash *f;
	char *s, *o;
	Flashpart *fp;
	Flashregion *r;
	int i;
	ulong start, end;

	if(c->qid.type & QTDIR)
		return devdirread(c, buf, n, nil, 0, flashgen);

	f = flash.card[c->dev];
	fp = &f->part[PART(c->qid.path)];
	if(fp->name == nil)
		error(Egreg);
	switch(TYPE(c->qid.path)){
	case Qdata:
		offset += fp->start;
		if(offset >= fp->end)
			return 0;
		if(offset+n > fp->end)
			n = fp->end - offset;
		n = readflash(f, buf, offset, n);
		if(n < 0)
			error(Eio);
		return n;
	case Qctl:
		s = malloc(READSTR);
		if(waserror()){
			free(s);
			nexterror();
		}
		o = seprint(s, s+READSTR, "%#2.2ux %#4.4ux %d %q\n",
			f->id, f->devid, f->width, f->sort!=nil? f->sort: "nor");
		for(i=0; i<f->nr; i++){
			r = &f->regions[i];
			if(r->start < fp->end && fp->start < r->end){
				start = r->start;
				if(fp->start > start)
					start = fp->start;
				end = r->end;
				if(fp->end < end)
					end = fp->end;
				o = seprint(o, s+READSTR, "%#8.8lux %#8.8lux %#8.8lux", start, end, r->erasesize);
				if(r->pagesize)
					o = seprint(o, s+READSTR, " %#8.8lux", r->pagesize);
				o = seprint(o, s+READSTR, "\n");
			}
		}
		n = readstr(offset, buf, n, s);
		poperror();
		free(s);
		return n;
	}
	error(Egreg);
	return 0;		/* not reached */
}
Exemple #2
0
//! Handles a monitor command.
void flash_handle_fn( uint8_t const app,
					uint8_t const verb,
					uint32_t const len)
{
		switch(verb) {
			case 0x21:
				eraseflash(cmddataword[0]);
				txdata(app,0,0);
				break;
			case 0x22:
				writeflash(cmddataword[0], cmddata[2]);
				txdata(app,0,0);
				break;
			case 0x23:
				cmddata[0] = readflash(cmddataword[0]);
				txdata(app,0,1);
				break;
		}
}