Initial Risc-V64 support

This commit is contained in:
bzt 2021-01-18 03:26:37 +01:00
parent fffccd2238
commit c389221fc4
15 changed files with 55 additions and 16 deletions

Binary file not shown.

Binary file not shown.

BIN
dist/bootboot.rv64 vendored Normal file

Binary file not shown.

View File

@ -16,7 +16,7 @@ ZIPNAME = ../$(TARGET)-$(shell uname -s).zip
endif
endif
OBJS = $(SRCS:.c=.o)
INCBIN = ../dist/boot.bin ../dist/bootboot.bin ../dist/bootboot.efi ../dist/bootboot.img ../aarch64-rpi/LICENCE.broadcom ../aarch64-rpi/bootcode.bin ../aarch64-rpi/fixup.dat ../aarch64-rpi/start.elf
INCBIN = ../dist/boot.bin ../dist/bootboot.bin ../dist/bootboot.efi ../dist/bootboot.img ../dist/bootboot.rv64 ../aarch64-rpi/LICENCE.broadcom ../aarch64-rpi/bootcode.bin ../aarch64-rpi/fixup.dat ../aarch64-rpi/start.elf
all: data.c $(TARGET)

View File

@ -97,7 +97,7 @@ Példa:
| directory | tömb | többarchitektúrás lemezképekhez |
A `file` és a `directory` kölcsönösen kizárja egymást. Mindkettő lehet sztring (ha csak egy architektúrához generálunk),
vagy tömb (egy elem minden architektúrához). Jelenleg kettő támogatott, azaz minden tömb maximum két elemű lehet.
vagy tömb (egy elem minden architektúrához). Jelenleg három támogatott, azaz minden tömb maximum három elemű lehet.
Hogy melyik architektúrát jelenti, azt az dönti el, hogy a mabbában vagy lemezképben milyen architektúrájú kernel található.
A `type` típus csak `directory` esetén kötelező megadni.
@ -105,8 +105,8 @@ Példák:
```
"initrd": { "file": "initrd.bin" },
"initrd": { "type": "tar", "gzip": 0, "directory": "boot" },
"initrd": { "gzip": true, "file": [ "initrd-x86.bin", "initrd-arm.bin" ] },
"initrd": { "type": "cpio", "gzip": true, "directory": [ "boot/arm", "boot/x86" ] },
"initrd": { "gzip": true, "file": [ "initrd-x86.bin", "initrd-arm.bin", "initrd-rv64.bin" ] },
"initrd": { "type": "cpio", "gzip": true, "directory": [ "boot/arm", "boot/x86", "boot/riscv64" ] },
```
### Partíciók

View File

@ -96,16 +96,16 @@ Example:
| directory | array | for multiarch images |
The fields `file` and `directory` are mutually exclusive. They can be both strings (if there's only one architecture),
or arrays (one array element for each architecture). Currently two architecture supported, which means there can be
two strings in the arrays. Which architecture is used depends on the kernel's architecture in that folder or image
or arrays (one array element for each architecture). Currently three architecture supported, which means there can be
three strings in the arrays. Which architecture is used depends on the kernel's architecture in that folder or image
file. Type is only mandatory for `directory`.
Examples:
```
"initrd": { "file": "initrd.bin" },
"initrd": { "type": "tar", "gzip": 0, "directory": "boot" },
"initrd": { "gzip": true, "file": [ "initrd-x86.bin", "initrd-arm.bin" ] },
"initrd": { "type": "cpio", "gzip": true, "directory": [ "boot/arm", "boot/x86" ] },
"initrd": { "gzip": true, "file": [ "initrd-x86.bin", "initrd-arm.bin", "initrd-rv64.bin" ] },
"initrd": { "type": "cpio", "gzip": true, "directory": [ "boot/arm", "boot/x86", "boot/riscv64" ] },
```
### Partitions

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,7 @@ extern unsigned char binary_boot_bin[512];
extern unsigned char binary_bootboot_bin[12288];
extern unsigned char binary_bootboot_efi[101490];
extern unsigned char binary_bootboot_img[34712];
extern unsigned char binary_bootboot_rv64[8192];
extern unsigned char binary_LICENCE_broadcom[1594];
extern unsigned char binary_bootcode_bin[52456];
extern unsigned char binary_fixup_dat[7297];

View File

@ -30,7 +30,7 @@
#include "main.h"
#include "data.h"
char *initrdnames[NUMARCH+1] = { "INITRD", "AARCH64", "X86_64" };
char *initrdnames[NUMARCH+1] = { "INITRD", "AARCH64", "X86_64", "RISCV64" };
int nextcluster = 3, lastcluster = 0, bpc, esp_size, esp_bbs = 0;
unsigned char *esp, *data;
uint16_t *fat16_1 = NULL, *fat16_2;
@ -182,7 +182,8 @@ void esp_makepart()
/* additional platform */
}
if(boot & (1 << 2)) {
/* additional platform */
/* Risc-V 64 */
ptr = esp_addfile(rootdir, "KERNEL.IMG", binary_bootboot_rv64, sizeof(binary_bootboot_rv64));
}
if(boot & (1 << 1)) {
/* x86 PC (UEFI) */

View File

@ -218,10 +218,11 @@ void parsekernel(int idx, unsigned char *data, int v)
if((!memcmp(ehdr->e_ident,ELFMAG,SELFMAG)||!memcmp(ehdr->e_ident,"OS/Z",4)) &&
ehdr->e_ident[EI_CLASS]==ELFCLASS64 && ehdr->e_ident[EI_DATA]==ELFDATA2LSB) {
if(v) printf("ELF64\r\nArchitecture: %s\r\n", ehdr->e_machine==EM_AARCH64 ? "AArch64" : (ehdr->e_machine==EM_X86_64 ?
"x86_64" : "invalid"));
"x86_64" : (ehdr->e_machine==EM_RISCV ? "riscv64" : "invalid")));
if(ehdr->e_machine == EM_AARCH64) { ma = 2*1024*1024-1; fa = 4095; initrd_arch[idx] = 1; } else
if(ehdr->e_machine == EM_X86_64) { ma = 4095; fa = 2*1024*1024-1; initrd_arch[idx] = 2; } else
{ fprintf(stderr,"mkbootimg: %s. %s: e_machine 62, 183.\r\n",lang[ERR_BADARCH],lang[ERR_ACCEPTVALUES]); exit(1); }
if(ehdr->e_machine == EM_RISCV) { ma = 4095; fa = 2*1024*1024-1; initrd_arch[idx] = 3; } else
{ fprintf(stderr,"mkbootimg: %s. %s: e_machine 62, 183, 243.\r\n",lang[ERR_BADARCH],lang[ERR_ACCEPTVALUES]); exit(1); }
phdr=(Elf64_Phdr *)((uint8_t *)ehdr+ehdr->e_phoff);
for(i=0;i<ehdr->e_phnum;i++){
if(phdr->p_type==PT_LOAD) {
@ -264,10 +265,12 @@ void parsekernel(int idx, unsigned char *data, int v)
if(((mz_hdr*)(data))->magic==MZ_MAGIC && ((mz_hdr*)(data))->peaddr<65536 && pehdr->magic == PE_MAGIC &&
pehdr->file_type == PE_OPT_MAGIC_PE32PLUS) {
if(v) printf("PE32+\r\nArchitecture: %s\r\n", pehdr->machine == IMAGE_FILE_MACHINE_ARM64 ? "AArch64" : (
pehdr->machine == IMAGE_FILE_MACHINE_AMD64 ? "x86_64" : "invalid"));
pehdr->machine == IMAGE_FILE_MACHINE_AMD64 ? "x86_64" : (
pehdr->machine == IMAGE_FILE_MACHINE_AMD64 ? "riscv64" : "invalid")));
if(pehdr->machine == IMAGE_FILE_MACHINE_ARM64) { ma = 2*1024*1024-1; fa = 4095; initrd_arch[idx] = 1; } else
if(pehdr->machine == IMAGE_FILE_MACHINE_AMD64) { ma = 4095; fa = 2*1024*1024-1; initrd_arch[idx] = 2; } else
{ fprintf(stderr,"mkbootimg: %s. %s: pe_hdr.machine 0x8664, 0xAA64\r\n",lang[ERR_BADARCH],lang[ERR_ACCEPTVALUES]); exit(1); }
if(pehdr->machine == IMAGE_FILE_MACHINE_RISCV64){ma = 4095; fa = 2*1024*1024-1; initrd_arch[idx] = 3; } else
{ fprintf(stderr,"mkbootimg: %s. %s: pe_hdr.machine 0x8664, 0xAA64, 0x5064\r\n",lang[ERR_BADARCH],lang[ERR_ACCEPTVALUES]); exit(1); }
core_size = (pehdr->entry_point-pehdr->code_base) + pehdr->text_size + pehdr->data_size;
bss = pehdr->bss_size;
core_addr = (int64_t)pehdr->code_base;

View File

@ -37,7 +37,7 @@
#include "lang.h"
#include "zlib.h"
#define NUMARCH 2
#define NUMARCH 3
#define MAXPATH 1024
#ifndef S_ISLNK
@ -54,6 +54,7 @@
#define PT_LOAD 1 /* Loadable program segment */
#define EM_X86_64 62 /* AMD x86-64 architecture */
#define EM_AARCH64 183 /* ARM aarch64 architecture */
#define EM_RISCV 243 /* RISC-V */
typedef struct
{
@ -114,6 +115,7 @@ typedef struct
#define PE_MAGIC 0x00004550 /* "PE\0\0" */
#define IMAGE_FILE_MACHINE_AMD64 0x8664 /* AMD x86_64 architecture */
#define IMAGE_FILE_MACHINE_ARM64 0xaa64 /* ARM aarch64 architecture */
#define IMAGE_FILE_MACHINE_RISCV64 0x5064 /* RISC-V riscv64 architecture */
#define PE_OPT_MAGIC_PE32PLUS 0x020b /* PE32+ format */
typedef struct
{

View File

@ -32,7 +32,7 @@ CFLAGS = -Wall -fpic -ffreestanding -fno-stack-protector -nostdinc -nostdlib -I.
LDFLAGS = -nostdlib -nostartfiles -T link.ld
STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment
all: mykernel.x86_64.elf mykernel.aarch64.elf
all: mykernel.x86_64.elf mykernel.aarch64.elf mykernel.riscv64.elf
mykernel.x86_64.elf: kernel.c
x86_64-elf-gcc $(CFLAGS) -mno-red-zone -c kernel.c -o kernel.o
@ -48,5 +48,14 @@ mykernel.aarch64.elf: kernel.c
aarch64-elf-strip $(STRIPFLAGS) mykernel.aarch64.elf
aarch64-elf-readelf -hls mykernel.aarch64.elf >mykernel.aarch64.txt
mykernel.riscv64.elf: kernel.c
riscv64-elf-gcc $(CFLAGS) -c kernel.c -o kernel.o
@# fuck you GNU ld, not possible to set correct elf header flags
riscv64-elf-ld -r -b binary -o font.o font.psf
@echo -ne '\005' | dd conv=notrunc of=font.o bs=1 seek=48 1>/dev/null 2>/dev/null
riscv64-elf-ld $(LDFLAGS) kernel.o font.o -o mykernel.riscv64.elf
riscv64-elf-strip $(STRIPFLAGS) mykernel.riscv64.elf
riscv64-elf-readelf -hls mykernel.riscv64.elf >mykernel.riscv64.txt
clean:
rm *.o *.elf *.txt || true

10
risc64-icicle/Makefile Normal file
View File

@ -0,0 +1,10 @@
TARGET=../dist/bootbootcb.rv64
all: $(TARGET)
$(TARGET):
@dd if=/dev/zero of=$(TARGET) bs=8192 count=1 2>&1 >/dev/null || true
clean:
rm -f $(TARGET)

View File

@ -0,0 +1,6 @@
BOOTBOOT MicroChip Icicle Risc-V64 Implementáció
================================================
Általános leírásért lásd a [BOOTBOOT Protokoll](https://gitlab.com/bztsrc/bootboot)t.
Jelenleg __FEJLESZTÉS ALATT__.

6
risc64-icicle/README.md Normal file
View File

@ -0,0 +1,6 @@
BOOTBOOT MicroChip Icicle Risc-V64 Implementation
=================================================
See [BOOTBOOT Protocol](https://gitlab.com/bztsrc/bootboot) for common details.
Currently __EXPERIMENTAL__.