Skip to content

Commit

Permalink
Add mkrom.c
Browse files Browse the repository at this point in the history
  • Loading branch information
yhzhang0128 committed Jan 27, 2022
1 parent 53f6eef commit 69f2dd4
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ apps: apps/*.c

images:
@echo "$(YELLOW)-------- Create the Disk Image --------$(END)"
$(CC) $(BUILD_DIR)//mkfs.c -o $(BUILD_DIR)/mkfs
cd $(BUILD_DIR)/; ./mkfs
$(CC) $(BUILD_DIR)/mkfs.c -o $(BUILD_DIR)/mkfs
cd $(BUILD_DIR); ./mkfs
@echo "$(YELLOW)-------- Create the BootROM Image --------$(END)"
@echo "[Note] Require vivado_lab in your \$$PATH. Otherwise, you can execute the tcl command in $(BUILD_DIR)/arty_board/write_cfgmem.tcl manually in Vivado (the input box at the bottom of hardware manager)."
$(OBJCOPY) -O binary $(RELEASE_DIR)/earth.elf $(BUILD_DIR)/earth.bin
cd $(BUILD_DIR); vivado_lab -nojournal -mode batch -source arty_board/write_cfgmem.tcl; rm *.log *.prm
srec_info $(BUILD_DIR)/egos_bootROM.mcs -Intel
rm $(BUILD_DIR)/earth.bin
$(CC) $(BUILD_DIR)/mkrom.c -o $(BUILD_DIR)/mkrom
cd $(BUILD_DIR); ./mkrom
#cd $(BUILD_DIR); vivado_lab -nojournal -mode batch -source arty_board/write_cfgmem.tcl; rm *.log *.prm
#srec_info $(BUILD_DIR)/egos_bootROM.mcs -Intel
#rm $(BUILD_DIR)/earth.bin

loc:
cloc . --exclude-dir=$(BUILD_DIR)
Expand Down Expand Up @@ -66,4 +68,4 @@ EARTH_LDLIBS = -Wl,--start-group -lc -lgcc -lm -lmetal -lmetal-gloss -Wl,--end-g
GREEN = \033[1;32m
YELLOW = \033[1;33m
CYAN = \033[1;36m
END = \033[0m
END = \033[0m
106 changes: 106 additions & 0 deletions install/mkrom.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* (C) 2022, Cornell University
* All rights reserved.
*/

/* Author: Yunhao Zhang
* Description: create the bootROM image file (egos_bootROM.mcs)
* the bootROM has 16MB
* the first 4MB is reserved for the FE310 processor
* the second 4MB is reserved for the earth layer binary
* the last 8MB is reserved for the disk image
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <sys/stat.h>

char disk_file[] = "disk.img";
char earth_file[] = "earth.bin";
char fe310_file[] = "arty_board/fe310_arty.bit";

char mem_fe310[4 * 1024 * 1024];
char mem_earth[4 * 1024 * 1024];
char mem_disk [8 * 1024 * 1024];

void load_fe310();
void load_earth();
void load_disk();
int fe310_size, earth_size, disk_size;

int main() {
load_fe310();
load_earth();
load_disk();
return 0;
}

void load_disk() {
struct stat st;
stat(disk_file, &st);
disk_size = (int)st.st_size;
printf("[INFO] Disk image file has 0x%x bytes\n", disk_size);

freopen(earth_file, "r", stdin);
read(0, mem_disk, disk_size);
fclose(stdin);
}

void load_earth() {
struct stat st;
stat(earth_file, &st);
earth_size = (int)st.st_size;
printf("[INFO] Earth binary file has 0x%x bytes\n", earth_size);

freopen(earth_file, "r", stdin);
read(0, mem_earth, earth_size);
fclose(stdin);
}

void load_fe310() {
/* load the fe310 binary file */
struct stat st;
stat(fe310_file, &st);
int len = (int)st.st_size;
printf("[INFO] FE310 binary file has %d bytes\n", len);

/* load header */
freopen(fe310_file, "r", stdin);
int first, second;
first = getchar();
second = getchar();
int length = (first << 8) + second;
//printf("[INFO] The header has length %d bytes\n", length);
for (int i = 0, tmp; i < length; i++)
tmp = getchar();

/* load key length */
first = getchar();
second = getchar();
int key_len = (first << 8) + second;
//printf("[INFO] Keys have length %d byte\n", key_len);
assert(key_len == 1);

while (1) {
int key = getchar();
first = getchar();
second = getchar();
if ((char)key == 'e')
break;

length = (first << 8) + second;
for (int i = 0, tmp; i < length; i++)
tmp = getchar();
//printf("[INFO] Section %c has length %d\n", (char)key, length);
}

int third, fourth;
third = getchar();
fourth = getchar();
fe310_size = (first << 24) + (second << 16) + (third << 8) + fourth;
printf("[INFO] FE310 binary section has 0x%x bytes\n", fe310_size);

read(0, mem_fe310, fe310_size);
fclose(stdin);
}

0 comments on commit 69f2dd4

Please sign in to comment.