format codes

This commit is contained in:
Chiharu Shirasaka 2020-10-12 17:13:52 +09:00
parent 9e49a0152d
commit 0252289f9f
2 changed files with 141 additions and 142 deletions

View File

@ -1,9 +1,9 @@
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
char *outfile = "nk.bin";
int verbose = 0;
@ -21,8 +21,7 @@ unsigned char magic[7] = "B000FF\n";
unsigned int start = 0xa0200000;
unsigned int len = 0;
void
usage(){
void usage() {
fprintf(stderr, "usage: bsd-ce [-h] [-o outfile] u-boot.bin\n");
fprintf(stderr, "\n");
fprintf(stderr, " -h this help\n");
@ -30,8 +29,7 @@ usage(){
fprintf(stderr, " default: %s\n", outfile);
}
int
main(int argc, char* argv[]){
int main(int argc, char *argv[]) {
int n, i;
unsigned int i32, cksum, ch;
long len;
@ -47,14 +45,14 @@ main(int argc, char* argv[]){
return 1;
}
}
argc -= optind; argv += optind;
argc -= optind;
argv += optind;
if (argc != 1) {
fprintf(stderr, "missing kernel name\n");
usage();
return 1;
}
/* load the loader (err...) */
if ((lfile = fopen(argv[0], "rb")) == NULL)
errx(1, "unable to open '%s'", argv[0]);
@ -79,11 +77,11 @@ main(int argc, char* argv[]){
WRITE(&start, sizeof(start));
WRITE(&loader_size, sizeof(loader_size));
/* Calculate the loader checksum */
cksum = 0;
for (len = 0; len < loader_size; len++) {
ch = (unsigned char)loader[len]; cksum += ch;
ch = (unsigned char)loader[len];
cksum += ch;
}
i32 = start;
WRITE(&i32, sizeof(unsigned int));
@ -103,9 +101,12 @@ main(int argc, char* argv[]){
* Write NK.BIN footer - this is just a series of 3x uint32_t indicating
* a file of zero length, starting at our init code.
*/
i32 = 0; WRITE(&i32, sizeof(i32));
i32 = start; WRITE(&i32, sizeof(i32));
i32 = 0; WRITE(&i32, sizeof(i32));
i32 = 0;
WRITE(&i32, sizeof(i32));
i32 = start;
WRITE(&i32, sizeof(i32));
i32 = 0;
WRITE(&i32, sizeof(i32));
free(loader);
fclose(fout);

View File

@ -1,9 +1,9 @@
#include <sys/types.h>
#include <fcntl.h>
#include <gelf.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
uint8_t magic[7] = "B000FF\n";
@ -11,9 +11,7 @@ uint8_t magic[7] = "B000FF\n";
if (!fread(buf, len, 1, f)) \
err(1, "read error");
int
main(int argc, char* argv[])
{
int main(int argc, char *argv[]) {
FILE *f;
uint8_t marker[7];
uint32_t i32, addr, cksum, len, i;
@ -43,7 +41,8 @@ main(int argc, char* argv[])
printf("image %u\n", n);
c = 0;
for (i = 0; i < len; i++) {
ch = getc(f); c += ch;
ch = getc(f);
c += ch;
}
printf(" addr %08x\n", addr);
printf(" len %08x\n", len);
@ -55,7 +54,6 @@ main(int argc, char* argv[])
}
n++;
}
fclose(f);