First commit

This commit is contained in:
kissste 2017-05-15 21:59:48 -04:00
commit 3fa968afe2
84 changed files with 9261 additions and 0 deletions

View file

@ -0,0 +1,7 @@
all:
gcc -o checksum checksum.c -s
gcc -o padding padding.c -s
g++ -o pick pick.cpp -s
clean:
rm -f pick padding checksum

View file

@ -0,0 +1,108 @@
// checksum.cpp : Defines the entry point for the console application.
/*
Compile command:
gcc -m32 -o tools/linux/checksum tools/linux/src/checksum.c -static
*/
#if 1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *fp;
unsigned int checksum = 0;
//unsigned char buf[502000]; //MAX FW Size = 512K-44K/2 = 501760
unsigned char *buf;
int i;
int size = 0;
if(argc != 2) return -1;
fp = fopen(argv[1], "rb+");
if(!fp) return -2;
fseek(fp,0L,SEEK_END);
size = ftell(fp);
fseek(fp,0L,SEEK_SET);
buf = malloc(size+100);
if(!buf){
fclose(fp);
return -3;
}
printf("size = %d \n\r", size);
memset(buf, 0, size+100);
fread(buf, 1, size, fp);
for(i=0;i<size;i++){
checksum += buf[i];
}
fseek(fp,0L,SEEK_END);
fwrite(&checksum, sizeof(int), 1, fp);
printf("checksum %x\n\r", checksum);
free(buf);
fclose(fp);
}
#else
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
//FILE *fp;
int fd;
unsigned int checksum = 0;
if(argc != 2) return -1;
//fp = fopen(argv[1], "r+");
//if(!fp) return -2;
fd = open(argv[1], O_RDWR);
if(fd<0) return -2;
//fseek(fp, 0, SEEK_SET);
lseek(fd, 0, SEEK_SET);
int size = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
printf("size = %d \n\r", size);
unsigned char buf[size+100];
memset(buf, 0, size+100);
read(fd, buf, size);
for(int i=0;i<size;i++){
checksum += buf[i];
}
lseek(fd, 0, SEEK_END);
write(fd, &checksum, sizeof(int));
printf("checksum %x\n\r", checksum);
close(fd);
}
#endif

Binary file not shown.

View file

@ -0,0 +1,45 @@
/*
Compile command:
gcc -m32 -o tools/linux/padding tools/linux/src/padding.c -static
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main(int argc, char *argv[])
{
FILE* fp;
// argv[1] -> length
// argv[2] -> data
// argv[3] -> output file name
char *unit;
int length = strtod(argv[1], &unit);
char data = strtod(argv[2], NULL);
char *buf;
printf("total %d %s, padding data %x, name %s\n", length, unit, data&0xFF, argv[3]);
if(unit[0]==0) length*=1;
else if(unit[0]=='K'||unit[0]=='k') length*=1024;
else if(unit[0]=='M'||unit[0]=='m') length*=(1024*1024);
else if(unit[0]=='G'||unit[0]=='g') length*=(1024*1024);
else {
printf("unit %s is Not valid\n", unit);
return;
}
fp = fopen(argv[3], "r+b");
if(!fp) return;
buf = malloc(length);
memset(buf, data, length);
printf("Original size %zd\n", fread(buf, 1, length, fp));
fseek(fp, 0, SEEK_SET);
printf("Padding size %zd\n", fwrite(buf, 1, length, fp));
free(buf);
fclose(fp);
}

Binary file not shown.

View file

@ -0,0 +1,140 @@
// pick.cpp : main project file.
// https://raw.githubusercontent.com/pvvx/RTL00MP3/34d4d9f465cc29867196bb22b73e811d5b984800/RTL00_SDKV35a/component/soc/realtek/8195a/misc/iar_utility/common/tools/src/pick.cpp
// compilation: g++ -o pick pick.cpp -s
//#include "stdafx.h"
//using namespace System;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#define PATTERN_1 0x96969999
#define PATTERN_2 0xFC66CC3F
#define PATTERN_3 0x03CC33C0
#define PATTERN_4 0x6231DCE5
unsigned int fw_head[4] = { PATTERN_1, PATTERN_2, PATTERN_3, PATTERN_4 };
unsigned int seg_head[4] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
/*
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
return 0;
}
*/
int main(int argc, char* argv[])
{
int arg_num = 6;
if ((argc>5) && (strstr(argv[5], "head"))) arg_num++;
if (argc != arg_num){
printf("Usage: pick.exe <start addr> <end addr> <input name> <output name> <body[+reset_offset][+sig], head[+reset_offset] [image2_start]>\n");
return -1;
}
unsigned char *buf;
unsigned int start;//=atoi(argv[1]);
unsigned int end;// = atoi(argv[2]);
unsigned int base;
int is_raw = 0;
int is_sig = 0;
char *inf = argv[3];
char *outf = argv[4];
int size;
FILE *ifp, *ofp;
//if(argv[1][0]=='0'&&(argv[1][1]=='x'||argv[1][1]=='X'))
// sscanf(argv[1], "0x%x", &start);
//else
// start=atoi(argv[1]);
start = strtol(argv[1], NULL, 0);
//if(argv[2][0]=='0'&&(argv[2][1]=='x'||argv[2][1]=='X'))
// sscanf(argv[2], "0x%x", &end);
//else
// end=atoi(argv[2]);
end = strtol(argv[2], NULL, 0);
base = start & 0xFFFF0000;
if (strstr(argv[5], "reset_offset")){
base = start;
}
if (strstr(argv[5], "raw")){
is_raw = 1;
}
else
is_raw = 0;
if (strstr(argv[5], "sig")){
is_sig = 1;
}
else
is_sig = 0;
printf("b:%d s:%d e:%d\n", base, start, end);
//printf("%s %s\n", inf, outf);
ifp = fopen(inf, "rb");
if (!ifp) return -2;
ofp = fopen(outf, "wb");
if (!ofp) return -3;
fseek(ifp, 0, SEEK_END);
size = ftell(ifp);
printf("size %d\n", size);
buf = (unsigned char *)malloc(size);
if (!buf) return -4;
if (end == 0) end = base + size;
if (end - start + 1 > 0){
fseek(ifp, start - base, SEEK_SET);
fread(buf, end - start, 1, ifp);
if (is_raw == 0){
if (strstr(argv[5], "head")){
int offset = strtol(argv[6], NULL, 0);
printf("append fw head %x\n", offset);
fwrite(fw_head, 4, sizeof(unsigned int), ofp);
seg_head[2] = (0xFFFF0000 | (offset / 1024));
}
else{
if (is_sig){
seg_head[2] = 0x35393138;
seg_head[3] = 0x31313738;
}
else{
seg_head[2] = 0xFFFFFFFF;
seg_head[3] = 0xFFFFFFFF;
}
}
seg_head[0] = end - start;
seg_head[1] = start;
fwrite(seg_head, 4, sizeof(unsigned int), ofp);
}
fwrite(buf, end - start, 1, ofp);
}
printf("copy size %d\n", end - start);
fclose(ifp);
fclose(ofp);
free(buf);
return 0;
}

Binary file not shown.