OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /or1k/trunk/mp3/sw/utils
    from Rev 302 to Rev 1765
    Reverse comparison

Rev 302 → Rev 1765

/bin2hex.c
0,0 → 1,32
#include <stdio.h>
 
/* Number of bytes before line is broken
For example if target flash is 8 bits wide,
define BREAK as 1. If it is 16 bits wide,
define it as 2 etc.
*/
#define BREAK 1
int main(int argc, char **argv)
{
 
FILE *fd;
int c;
int i = 0;
 
if(argc < 2) {
printf("no input file specified\n");
exit(1);
}
fd = fopen( argv[1], "r" );
while ((c = fgetc(fd)) != EOF) {
printf("%.2lx", c);
if (++i == BREAK) {
printf("\n");
i = 0;
}
}
return 0;
}
/Makefile
0,0 → 1,21
all: dummy
 
bin2c: bin2c.c
gcc -O2 -o bin2c bin2c.c
 
bin2srec: bin2srec.c
gcc -O2 -o bin2srec bin2srec.c
 
loader: loader.c
gcc -O2 -o loader loader.c
 
bin2flimg: bin2flimg.c
gcc -O2 -o bin2flimg bin2flimg.c
 
bin2hex: bin2hex.c
gcc -O2 -o bin2hex bin2hex.c
 
dummy: bin2c bin2srec loader bin2flimg bin2hex
 
clean:
rm -rf bin2c bin2srec loader bin2flimg bin2hex *~ *.bak
/bin2flimg.c
0,0 → 1,38
#include <stdio.h>
int main(int argc, char **argv)
{
 
FILE *fd;
int c, i, j, width;
unsigned long word;
 
if(argc < 3) {
printf("no input file specified");
exit(1);
}
width = atoi(argv[1]);
 
fd = fopen( argv[2], "r" );
 
while (!feof(fd)) {
j = 0;
word = 0;
while (j < width) {
c = fgetc(fd);
if (c == EOF) {
c = 0;
}
word = (word << 8) + c;
j++;
}
if(width == 1)
printf("%.2lx\n", word);
else if(width == 2)
printf("%.4lx\n", word);
else
printf("%.8lx\n", word);
}
return 0;
}
/loader.c
0,0 → 1,123
/* Small utility that makes flash image. */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../mad-xess/fsyst.h"
 
unsigned int swap (unsigned int x) {
return (x & 0xFF) << 24
| (x & 0xFF00) << 8
| (x & 0xFF0000) >> 8
| (x & 0xFF000000) >> 24;
}
 
/* Copies data from fi to fo. Returns nonzero
if error. */
int copy_into (FILE *fo, FILE *fi)
{
char buf[8192];
int bread;
do
{
bread = fread (&buf, 1, sizeof(buf), fi);
if (bread != fwrite (&buf, 1, bread, fo))
return 1;
} while (bread == sizeof(buf));
return 0;
}
 
/* Writes file to fo and returns error. */
int write_file (FILE *fo, struct file_struct *file)
{
unsigned int u;
int ok = 0;
u = swap(file->length);
printf("%08x:%08x\n", file->length, u);
if (fwrite(&u, sizeof(unsigned long), 1, fo))
ok = 1;
u = swap(file->type);
if (fwrite(&u, sizeof(unsigned long), 1, fo) && ok)
return 0;
fprintf (stderr, "Cannot write to file.\n");
return 1;
}
 
int main(int argc, char *argv[])
{
int i;
FILE *fo;
struct file_struct file;
if (argc <= 1)
{
printf ("Usage: loader image_file.mfs [file.mp3 [...]]\n");
return 1;
}
if ((fo = fopen (argv[1], "wb+")) == NULL)
{
fprintf (stderr, "Cannot open output file '%s'\n", argv[1]);
return 2;
}
 
file.type = FT_ROOT;
file.length = HEADER_SIZE;
if (write_file (fo, &file))
return 3;
 
for (i = 2; i < argc; i++)
{
FILE *fi = fopen (argv[i], "rb");
struct stat fi_stat;
int align;
if (!fi)
{
fprintf (stderr, "Cannot open input file '%s'\n", argv[i]);
return 1;
}
stat (argv[i], &fi_stat);
printf ("Track %i: %s (size %i)\n", i - 1, argv[i], (int)fi_stat.st_size);
 
file.type = FT_TRACK_NO;
file.length = HEADER_SIZE + sizeof (unsigned int);
file.data[0] = swap(i - 1);
if (write_file (fo, &file))
return 3;
if (!fwrite (&file.data[0], sizeof (unsigned int), 1, fo))
{
fprintf (stderr, "Cannot write to file.\n");
return 3;
}
 
file.type = FT_TRACK_NAME;
align = (4 - ((strlen (argv[i]) + 1) & 3)) & 3;
file.length = HEADER_SIZE + strlen (argv[i]) + 1 + align;
if (write_file (fo, &file))
return 3;
if (!fwrite (argv[i], strlen (argv[i]) + 1 + align, 1, fo))
{
fprintf (stderr, "Cannot write to file.\n");
return 3;
}
 
file.type = FT_TRACK_DATA;
align = (4 - (fi_stat.st_size & 3)) & 3;
file.length = HEADER_SIZE + fi_stat.st_size + align;
if (write_file (fo, &file))
return 3;
copy_into(fo, fi);
fwrite (&align, 1, align, fo);
fclose (fi);
}
file.type = FT_END;
file.length = 0;
if (write_file (fo, &file))
return 3;
printf ("Done.\n");
fclose (fo);
return 0;
}
/bin2srec.c
0,0 → 1,43
#include <stdio.h>
#define SMARK "S214"
#define SADDR 0x000000
#define INIT_ADDR 0x100100
#define SCHKSUM 0xff
 
int main(int argc, char **argv)
{
 
FILE *fd;
int c, i, j;
unsigned long addr = INIT_ADDR;
unsigned char chksum;
 
if(argc < 2)
error("no input file specified");
 
fd = fopen( argv[1], "r" );
 
while (!feof(fd)) {
j = 0;
chksum = SCHKSUM;
printf("%s%.6lx", SMARK, addr);
while (j < 16) {
c = fgetc(fd);
if (c == EOF) {
c = 0;
}
printf("%.2lx", c);
chksum -= c;
j++;
}
 
chksum -= addr & 0xff;
chksum -= (addr >> 8) & 0xff;
chksum -= (addr >> 16) & 0xff;
chksum -= 0x14;
printf("%.2lx\r\n", chksum);
addr += 16;
}
return 0;
}
/bin2c.c
0,0 → 1,24
#include <stdio.h>
 
int main(void)
{
 
int c, i = 0;
 
printf("#ifdef HAVE_CONFIG_H\n");
printf("# include \"config.h\"\n");
printf("#endif\n\n");
printf("#ifdef EMBED\n");
 
printf("unsigned char flash_data[] = {\n");
 
while((c = getchar()) != EOF) {
printf("0x%.2x, ", c);
if(!(i % 32))
printf("\n");
i++;
}
 
printf(" };\n");
printf("#endif\n");
}
/merge2srec
0,0 → 1,10
#!/bin/sh
 
LINE_NB=`wc -l < $1`
MIN=`expr $LINE_NB - 1`
 
head -$MIN $1 > out.exo
 
cat $2 >> out.exo
tail -1 $1 >> out.exo
 
merge2srec Property changes : Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.