Пример #1
0
void cmd_memfill() {
	unsigned long addr,len,val;
	char *tmp;
	const char usage[] = "Usage: memfill addr len val\n";
	
	tmp = strtok(NULL," ");
	if(!tmp) {
		printf(usage);
		return;
	}
	addr = hex_to_ulong(tmp);

	tmp = strtok(NULL," ");
	if(!tmp) {
		printf(usage);
		return;
	}
	len = hex_to_ulong(tmp);

	tmp = strtok(NULL," ");
	if(!tmp) {
		printf(usage);
		return;
	}
	val = hex_to_ulong(tmp) & 0xff;

	memset((unsigned long *)addr,val,len);
	printf("アドレス%08xから%08xまでを値%02xで埋めました\n",(unsigned int)addr,(unsigned int)(addr+len-1),(unsigned int)val);
}
Пример #2
0
void cmd_spirom_dump() {
	unsigned long addr,len;
	unsigned char count,uc;
	char tmp[48];
	unsigned char rdbuf[16];

	char *arg = strtok(NULL," ");
	if(!arg) {
		printf("Usage: spi dump addr len\n");
		return;
	}
	addr = hex_to_ulong(arg);

	len = 0;
	arg = strtok(NULL," ");
	if(arg) len  = hex_to_ulong(arg);
	
	int p=0;
	if(len == 0) len = 0x100;

	count = 0;
	while(len) {
		if(sci_rxcount()) break;

		spirom_read(addr,16,rdbuf);

        if(count == 0) {
			printf("%08x ",(unsigned int)addr);
        }

        uc = rdbuf[p++];
		p = p & 15;
        if((uc >= ' ') && (uc <= 0x7e)) tmp[count] = uc;
        else                            tmp[count] = '.';
        printf("%02x ",uc);

        addr++; // アドレス増やす
        len--; // 長さを減らす

        count++;

        if(!len) // 残りがなくなってしまったら
        {
            while(count != 16) {
                printf("   ");
                tmp[count++] = ' ';
            }
        }
        if(count == 16) {
            tmp[count] = '\0';
            printf("%s\n",tmp);
        }
        count &= 15;
	}
}
Пример #3
0
long get_line_address(FILE *fp) {
/*
    Function to get a numeric representation of the address
    given on a file string
*/
    char next_char;
    char address_str[8] = {'\0'};
    int i;
    unsigned long result = 0; 
    next_char = fgetc(fp);
    if (' ' != next_char) {
        printf("The file being parsed is badly formatted: no space between an operation and an address ('%c' found instead).\n",
                next_char);
        exit(EXIT_SUCCESS);
    }
    for (i = 0; i < 8; i++) {
        next_char = fgetc(fp);
        if (',' == next_char) {
            break;
        }
        verify_address_character(next_char);
        address_str[i] = next_char;
    }
    result = hex_to_ulong(address_str);
    return result;
}
Пример #4
0
long    long_name_mask_delim_opt(const char *context,
				         const LONG_NAME_MASK * table,
			               const char *names, const char *delim,
				         int flags)
{
    const char *myname = "name_mask";
    char   *saved_names = mystrdup(names);
    char   *bp = saved_names;
    long    result = 0;
    const LONG_NAME_MASK *np;
    char   *name;
    int     (*lookup) (const char *, const char *);
    unsigned long ulval;

    if ((flags & NAME_MASK_REQUIRED) == 0)
	msg_panic("%s: missing NAME_MASK_FATAL/RETURN/WARN/IGNORE flag",
		  myname);

    if (flags & NAME_MASK_ANY_CASE)
	lookup = strcasecmp;
    else
	lookup = strcmp;

    /*
     * Break up the names string, and look up each component in the table. If
     * the name is found, merge its mask with the result.
     */
    while ((name = mystrtok(&bp, delim)) != 0) {
	for (np = table; /* void */ ; np++) {
	    if (np->name == 0) {
		if ((flags & NAME_MASK_NUMBER)
		    && hex_to_ulong(name, ~0UL, &ulval)) {
		    result |= ulval;
		} else if (flags & NAME_MASK_FATAL) {
		    msg_fatal("unknown %s value \"%s\" in \"%s\"",
			      context, name, names);
		} else if (flags & NAME_MASK_RETURN) {
		    msg_warn("unknown %s value \"%s\" in \"%s\"",
			     context, name, names);
		    myfree(saved_names);
		    return (0);
		} else if (flags & NAME_MASK_WARN) {
		    msg_warn("unknown %s value \"%s\" in \"%s\"",
			     context, name, names);
		}
		break;
	    }
	    if (lookup(name, np->name) == 0) {
		if (msg_verbose)
		    msg_info("%s: %s", myname, name);
		result |= np->mask;
		break;
	    }
	}
    }

    myfree(saved_names);
    return (result);
}
Пример #5
0
void cmd_memwr() {
	unsigned long addr,val;
	char *tmp;
	unsigned char size = 0;
	const char usage[] = "Usage: memwr { b|w|l } addr val\n";

	tmp = strtok(NULL," ");
	if(!tmp) {
		printf(usage);
		return;
	}
	if(!strcmp(tmp,"b")) size = 1;
	if(!strcmp(tmp,"w")) size = 2;
	if(!strcmp(tmp,"l")) size = 4;

	if(size == 0) {
		printf(usage);
		return;
	}

	tmp = strtok(NULL," ");
	if(!tmp)
	{
		printf(usage);
		return;
	}
	addr = hex_to_ulong(tmp);

	tmp = strtok(NULL," ");
	if(!strlen(tmp))
	{
		printf(usage);
		return;
	}
	val = hex_to_ulong(tmp);

	if(size == 1) *(unsigned char *)addr = val;
	if(size == 2) *(unsigned short*)addr = val;
	if(size == 4) *(unsigned long *)addr = val;

	printf("アドレス%08xに値%02xを書きました\n",(unsigned int)addr,(unsigned int)val);
}
Пример #6
0
void cmd_jmp() {
	unsigned long addr;
	char *tmp;

	typedef void (*FUNC)(void);
	FUNC func;
	
	tmp = strtok(NULL," ");
	if(!tmp) {
		printf("Usage: jmp addr\n");
		return;
	}
	addr = hex_to_ulong(tmp);

	printf("アドレス%08xへジャンプします\n",(unsigned int)addr);

	func = (FUNC)addr;
	func();

	printf("ユーザプログラム終了\n");
}
Пример #7
0
int yDecode(FILE * fOut, FILE * fIn, long y_line, long y_size,int y_part)
	{
	unsigned char srcbuf[4100];
	unsigned char desbuf[4100];
	unsigned char * srcp;
	unsigned char * desp;
	int deslen;
	int srclen;
	unsigned char c;
	int id;
	char * cp;
	long decolen;
//	long sumlen;
//	int partnr;
	unsigned long crc32;
	char name[260];
	int esize;
	unsigned char * partbuf;
	unsigned char * partptr;
	long partsize;
	long partfree;
	long wlen;
	long flen;

	if (aDsp) print("yDecoder started...\r\n");

	// sumlen=0; partnr=1;

part_start:
	CrcInit();  // Analyse only CRC per part
	decolen=0;
	deslen=0; desp=desbuf;

	if (y_part)  // This is a multipart message !
		{
		cp=ad_fgetscr((char*) srcbuf,4097,fIn);  // fgets especially with ad_length
		if (cp==NULL)
			{
			eprint("Unexpected eof in yEncoded file\r\n");
			errors++;
			return(1);
			}

		if (aDsp) print("=ypart-line:  %s\r\n",srcbuf);

		if (strncmp((char*) srcbuf,"=ypart ",7))
			{
			eprint("Missing =ypart line in yEncoded multipart message\r\n");
			errors++;
			return(2);
			}
		cp=strstr((char*)srcbuf,"end=");
		if (cp==NULL)
			{
			eprint("Missing end= in yEncoded multipart message\r\n");
			errors++;
			return(2);
			}
		y_end=atol(cp+4);

		cp=strstr((char*)srcbuf,"begin=");
		if (cp==NULL)
			{
			eprint("Missing begin= in yEncoded multipart message\r\n");
			errors++;
			return(2);
			}
		y_begin=atol(cp+6);

		if (aDsp) print("part-begin: %ld\r\n",y_begin);
		if (aDsp) print("part-end  : %ld\r\n",y_end);

		partbuf=malloc(y_end-y_begin+10);  // Allocate a buffer for the part
		partptr=partbuf;
		partsize=y_end-y_begin+1;
		partfree=partsize;
		}

loop:

	cp=ad_fgetscr((char*) srcbuf,4097,fIn);  // fgets especially with ad_length
	if (cp==NULL)
		{
		eprint("Unexpected eof in yEncoded file\r\n");
		errors++;
		return(1);
		}
	if (strncmp((char*) srcbuf,"=yend ",6)==0)
		{
		if (aDsp) print("Endline (%d bytes): %s\r\n",decolen,srcbuf);
		goto end_of_file;
		}
	if (strncmp((char*) srcbuf,"=ybegin ",8)==0)
		{
		eprint("Unexpected =ybegin in yEncoded file\r\n");
		errors++;
		return(1);
		}
	srclen=strlen((char*)srcbuf);
	if (srclen<y_line)
		{
		if (aDsp) print("Last line.\r\n");
		}
	srcp=srcbuf;

loop2:
	c=*srcp; srcp++;
	if (c==0)
		{
		goto loop;  // End of line reached
		}
	if (c == '=')  // The escape character comes in
		{
		c=*srcp; srcp++;
		if (c==0) return(2); // Last char cannot be escape char !
		c=(unsigned char)(c-64);
		}
	c=(unsigned char)(c-42);  // Subtract the secret number
	*desp=c; desp++; deslen++;	decolen++;

	CrcAdd(c);

	if (deslen>=4096)
		{

		if (y_part)  // MultiPart --> to the partbuffer !
			{
			if (deslen>partfree)
				{
				eprint("Partial message corrupt: longer than (end-begin)!\r\n");
				errors++;
				return(11);
				}
			memcpy(partptr,desbuf,deslen);
			partptr=partptr+deslen;
			partfree=partfree-deslen;
			}
		else    // Single part --> directly to target file
			{
			id=fwrite(desbuf,deslen,1,fOut);
			if (id != 1)
				{
				eprint("Error in writing decoded file (code=%d)\r\n",errno);
				errors++;
				return(3);
				}
			}
		deslen=0; desp=desbuf;
		}
	goto loop2;

end_of_file:


	if (deslen>0)  // Empty the last buffer
		{
		if (y_part)
      	{
			if (deslen>partfree)
				{
				eprint("Partial message corrupt: longer than (end-begin)!\r\n");
				errors++;
				return(11);
				}
			memcpy(partptr,desbuf,deslen);
			//partptr=partptr+deslen;
			//partfree=partfree-deslen;
			}
		else    // Single part --> directly to target file
			{
			id=fwrite(desbuf,deslen,1,fOut);
			if (id != 1)
				{
				eprint("Error in writing decoded file (code=%d)\r\n",errno);
				errors++;
				return(3);
				}
			}



//		id=fwrite(desbuf,deslen,1,fOut);
//		if (id != 1)
//			{
//			eprint("Error in writing decoded file (code=%d)\r\n",errno);
//			return(4);
//			}
		}

	cp=strstr((char*) srcbuf,"size=");  // Compare the decoded size to the =yend size
	if (cp)
		{
		esize=atoi(cp+5);
		if (esize != decolen)
			{
			sprintf(name,"%s(size=%ld)",attname,decolen);
			strcpy(attname,name);
			eprint("Corrupt yEnc binary - endsize mismatch (%s%s)\r\n",attname,attext);
			errors++; errfiles++;
			return(0);
			}
		}


	// Check the srcbuf for the CRC
	if (y_part==0)
		{
		cp=strstr((char*)srcbuf,"crc32=");
		if (cp)
			{
			crc32=hex_to_ulong((char*)(cp+6));
			ad_rescrc=crc_val ^ 0xFFFFFFFFl;
			if (aDsp) print("Included CRC: $%08lx - calculated CRC: $%08lx\r\n",crc32,ad_rescrc);
			}
		}
	else
		{
		cp=strstr((char*)srcbuf,"pcrc32=");
		if (cp)
			{
			crc32=hex_to_ulong((char*)(cp+7));
			ad_rescrc=crc_val ^ 0xFFFFFFFFl;
			if (aDsp) print("Included CRC: $%08lx - calculated CRC: $%08lx\r\n",crc32,ad_rescrc);
			}
		}

	if (cp!=NULL)
		{
		if (crc32 != ad_rescrc)
			{
			sprintf(name,"%s(crc=%08lx)",attname,ad_rescrc);
			strcpy(attname,name);
			eprint("Corrupt yEnc binary - CRC mismatch (%s%s)\r\n",attname,attext);
			errors++; errfiles++;
			return(0);
			}
		}

	if (y_part==0)  // Single message
		{
		if ((y_part==0) & (decolen != y_size))
			{
			// eprint("Y-Decoder: Size mismatch - file corrupt.\r\n");

			sprintf(name,"%s(len=%ld)",attname,decolen);
			strcpy(attname,name);
			eprint("Corrupt yEnc binary - size mismatch (%s%s)\r\n",attname,attext);
			errors++; errfiles++;
			return(0);
			}

		ad_reslen=decolen;
		ad_rescrc=crc_val ^ 0xFFFFFFFFl;

		if (aDsp) print("yDecoder: Job done. %ld bytes written. CRC: $%08lx \r\n",decolen,ad_rescrc);
		return(0);
		}

	// Multipart message

	if ((y_part>0) & (decolen != (y_end-y_begin+1)))
		{
		eprint("yDecoder: Part size mismatch - file corrupt.\r\n");
		errors++; errparts++;
		return(6);
		}

	// ----- Special handling for external decoder

	// Now write the decoded part to the target file !

	id=fseek(fOut,y_begin-1,0);
	if (id)
		{
		eprint("Cannot write a part (fseek failed) [reason:%d]\r\n",errno);
		errors++;
		return(12);
		}
	flen=decolen;
	partptr=partbuf;

	if (aDsp) print("Write part to target file (start: %ld, size: %ld)\r\n",y_begin-1,flen);

	while (flen>0)
		{
		wlen=flen;
		if (wlen>8192) wlen=8192;
		id=fwrite(partptr,wlen,1,fOut);

		if (id != 1)
			{
			eprint("Cannot write a part (fwrite failed) [reason:%d]\r\n",errno);
			errors++;
			return(12);
			}
		partptr=partptr+wlen;
		flen=flen-wlen;
		}

	free(partbuf);  // Give the part-buffer back !

	return(0);
	// --------------------------------------------

/* ----- unused from newsreader decoder

	sumlen=sumlen+decolen;
	if (sumlen == y_size)  // Completely decoded
		{
		if (aDsp) print("yDecoder: Multpart Job done. %ld bytes written\r\n",sumlen);

		ad_reslen=sumlen;
		ad_rescrc=crc_val ^ 0xFFFFFFFFl;

		return(0);
		}
	if (sumlen>y_size)
		{
		eprint("yDecoder: More data than expected. File corrupt.\r\n");
		errors++;
		return(7);
		}

	// Now scan the file for the rest !

	partnr++;  // Now scan for this part number

ploop:

	cp=ad_fgetscr((char*) srcbuf,4097,fIn);  // fgets especially with ad_length
	if (cp==NULL)
		{
		eprint("Unexpected eof in multipart yEncoded file\r\n");
		errors++;
		return(1);
		}
	if (strncmp((char*) srcbuf,"=ybegin ",8))
		{
		if (aDsp) print("yEnc skipped: %s\r\n",srcbuf);
		goto ploop;
		}
	cp=strstr((char*)srcbuf," part=");
	if (cp==NULL)
		{
		eprint("No part in next ybegin found - in multipart yEncoded file\r\n");
		errors++;
		return(1);
		}
	if (atoi(cp+6) != partnr)
		{
		eprint("Unexpected part (%d) found in yEncoded message. Expected was (%d)\r\n",atoi(cp+6),partnr);
		errors++;
		return(1);
		}
	if (aDsp) print("Found part # %d\r\n",partnr);

	// Additional plausi possible for name & size

	goto part_start;

*/
	}
Пример #8
0
void cmd_time() {
	// RTCのテスト
	RX62N_RTC_TIME rtctime = {0x2012,0x01,0x18,0x05,0x05,0x34,0x00}; // BCDで指定する

	char *tmp = strtok(NULL,"/");
	if(!tmp) {
		if(rtc_get_time(&rtctime)) {
			printf("%04x/%02x/%02x %02x:%02x:%02x\n",
				rtctime.year,rtctime.mon,rtctime.day,
				rtctime.hour,rtctime.min,rtctime.second
			);
		}
		else {
			sci_puts("RTCが設定されていないので適当な時刻を設定します。");
			if(rtc_set_time(&rtctime) == 0) {
				sci_puts("RTC起動失敗\n");
			}
		}
		return;
	}

	rtctime.year = hex_to_ulong(tmp);
	tmp = strtok(NULL,"/");
	if(tmp) rtctime.mon = hex_to_ulong(tmp);
	tmp = strtok(NULL," ");
	if(tmp) rtctime.day = hex_to_ulong(tmp);

	tmp = strtok(NULL,":");
	if(tmp) rtctime.hour = hex_to_ulong(tmp);
	tmp = strtok(NULL,":");
	if(tmp) rtctime.min = hex_to_ulong(tmp);
	tmp = strtok(NULL," ");
	if(tmp) rtctime.second = hex_to_ulong(tmp);

	if(rtc_set_time(&rtctime) == 0) {
		sci_puts("RTCの設定で失敗しました\n");
		return;
	}

/*
	RX62N_RTC_TIME rtctime = {0x2011,0x08,0x02,0x02,0x23,0x45,0x12}; // BCDで指定する
	if(rtc_set_time(&rtctime) == 0)
	{
		sci_puts("[RTC起動失敗]\n");
		return false;
	}

	rtctime.year = 0;
	rtctime.mon = 0;
	rtctime.day = 0;
	rtctime.hour = 0;
	rtctime.min = 0;
	rtctime.second = 0;

	for(i=0;i<10;i++)
	{
		timer_wait_ms(500);
	}
	sci_puts("[RTC起動成功]\n");
*/
}