1
0
Fork 0
mirror of https://gitlab.com/bztsrc/bootboot.git synced 2023-02-13 20:54:32 -05:00

More icicle

This commit is contained in:
bzt 2021-01-20 04:32:40 +01:00
parent 046cf898d5
commit 5891ccae02
6 changed files with 56 additions and 19 deletions

View file

@ -163,14 +163,17 @@ void esp_makepart()
for(i = 0; i < NUMARCH && initrd_arch[i]; i++) for(i = 0; i < NUMARCH && initrd_arch[i]; i++)
boot |= (1 << (initrd_arch[i] - 1)); boot |= (1 << (initrd_arch[i] - 1));
/* add loader's directory */
ptr = esp_mkdir(rootdir, "BOOTBOOT", 0); rootdir += 32; ptr = esp_mkdir(rootdir, "BOOTBOOT", 0); rootdir += 32;
if(boot & (1 << 1)) { if(boot & (1 << 1)) {
/* x86 PC (BIOS) */ /*** x86 PC (BIOS) ***/
/* start address has to be saved in PMBR too */
esp_bbs = ((data + nextcluster * bpc)-esp) / 512; esp_bbs = ((data + nextcluster * bpc)-esp) / 512;
memcpy(esp + 0x1B0, &esp_bbs, 4); memcpy(esp + 0x1B0, &esp_bbs, 4);
ptr = esp_addfile(ptr, "LOADER", binary_bootboot_bin, sizeof(binary_bootboot_bin)); ptr = esp_addfile(ptr, "LOADER", binary_bootboot_bin, sizeof(binary_bootboot_bin));
} }
ptr = esp_addfile(ptr, "CONFIG", (unsigned char*)config, strlen(config)); ptr = esp_addfile(ptr, "CONFIG", (unsigned char*)config, strlen(config));
/* add INITRDs */
if(!initrd_arch[1]) { if(!initrd_arch[1]) {
ptr = esp_addfile(ptr, initrdnames[0], initrd_buf[0], initrd_size[0]); ptr = esp_addfile(ptr, initrdnames[0], initrd_buf[0], initrd_size[0]);
} else { } else {
@ -178,21 +181,33 @@ void esp_makepart()
ptr = esp_addfile(ptr, initrdnames[(int)initrd_arch[i]], initrd_buf[i], initrd_size[i]); ptr = esp_addfile(ptr, initrdnames[(int)initrd_arch[i]], initrd_buf[i], initrd_size[i]);
} }
} }
if(boot & (1 << 6)) {
/* additional platform */
}
if(boot & (1 << 5)) {
/* additional platform */
}
if(boot & (1 << 4)) {
/* additional platform */
}
if(boot & (1 << 3)) { if(boot & (1 << 3)) {
/* additional platform */ /* additional platform */
} }
if(boot & (1 << 2)) { if(boot & (1 << 2)) {
/* Risc-V 64 */ /*** Risc-V 64 Microchip Icicle ***/
ptr = esp_addfile(rootdir, "KERNEL.IMG", binary_bootboot_rv64, sizeof(binary_bootboot_rv64)); /* start and end address has to be added to the GPT too in a special partition */
bbp_start = ((data + nextcluster * bpc)-esp) / 512;
rootdir = esp_addfile(rootdir, "PAYLOAD.BIN", binary_bootboot_rv64, sizeof(binary_bootboot_rv64));
bbp_end = (((data + nextcluster * bpc)-esp) / 512) - 1;
} }
if(boot & (1 << 1)) { if(boot & (1 << 1)) {
/* x86 PC (UEFI) */ /*** x86 PC (UEFI) ***/
ptr = esp_mkdir(rootdir, "EFI", 0); rootdir += 32; ptr = esp_mkdir(rootdir, "EFI", 0); rootdir += 32;
ptr = esp_mkdir(ptr, "BOOT", lastcluster); ptr = esp_mkdir(ptr, "BOOT", lastcluster);
ptr = esp_addfile(ptr, "BOOTX64.EFI", binary_bootboot_efi, sizeof(binary_bootboot_efi)); ptr = esp_addfile(ptr, "BOOTX64.EFI", binary_bootboot_efi, sizeof(binary_bootboot_efi));
} }
if(boot & (1 << 0)) { if(boot & (1 << 0)) {
/* Raspberry Pi */ /*** Raspberry Pi ***/
ptr = esp_addfile(rootdir, "KERNEL8.IMG", binary_bootboot_img, sizeof(binary_bootboot_img)); ptr = esp_addfile(rootdir, "KERNEL8.IMG", binary_bootboot_img, sizeof(binary_bootboot_img));
ptr = esp_addfile(ptr, "BOOTCODE.BIN", binary_bootcode_bin, sizeof(binary_bootcode_bin)); ptr = esp_addfile(ptr, "BOOTCODE.BIN", binary_bootcode_bin, sizeof(binary_bootcode_bin));
ptr = esp_addfile(ptr, "FIXUP.DAT", binary_fixup_dat, sizeof(binary_fixup_dat)); ptr = esp_addfile(ptr, "FIXUP.DAT", binary_fixup_dat, sizeof(binary_fixup_dat));

View file

@ -61,7 +61,6 @@ fsdrv_t fsdrv[] = {
{ "ufs", { 0x516E7CB6, 0x6ECF, 0x11D6, { 0x8F,0xF8,0x00,0x02,0x2D,0x09,0x71,0x2B} }, NULL, NULL, NULL }, { "ufs", { 0x516E7CB6, 0x6ECF, 0x11D6, { 0x8F,0xF8,0x00,0x02,0x2D,0x09,0x71,0x2B} }, NULL, NULL, NULL },
{ "p9", { 0xC91818F9, 0x8025, 0x47AF, { 0x89,0xD2,0xF0,0x30,0xD7,0x00,0x0C,0x2C} }, NULL, NULL, NULL }, { "p9", { 0xC91818F9, 0x8025, 0x47AF, { 0x89,0xD2,0xF0,0x30,0xD7,0x00,0x0C,0x2C} }, NULL, NULL, NULL },
{ "Intel Fast Flash", { 0xD3BFE2DE, 0x3DAF, 0x11DF, { 0xBA,0x40,0xE3,0xA5,0x56,0xD8,0x95,0x93} }, NULL, NULL, NULL }, { "Intel Fast Flash", { 0xD3BFE2DE, 0x3DAF, 0x11DF, { 0xBA,0x40,0xE3,0xA5,0x56,0xD8,0x95,0x93} }, NULL, NULL, NULL },
{ "BIOS boot", { 0x21686148, 0x6449, 0x6E6F, { 0x74,0x4E,0x65,0x65,0x64,0x45,0x46,0x49} }, NULL, NULL, NULL },
{ "Sony boot partition", { 0xF4019732, 0x066E, 0x4E12, { 0x82,0x73,0x34,0x6C,0x56,0x41,0x49,0x4F} }, NULL, NULL, NULL }, { "Sony boot partition", { 0xF4019732, 0x066E, 0x4E12, { 0x82,0x73,0x34,0x6C,0x56,0x41,0x49,0x4F} }, NULL, NULL, NULL },
{ "Lenovo boot partition", { 0xBFBFAFE7, 0xA34F, 0x448A, { 0x9A,0x5B,0x62,0x13,0xEB,0x73,0x6C,0x22} }, NULL, NULL, NULL }, { "Lenovo boot partition", { 0xBFBFAFE7, 0xA34F, 0x448A, { 0x9A,0x5B,0x62,0x13,0xEB,0x73,0x6C,0x22} }, NULL, NULL, NULL },
{ "PowerPC PReP boot", { 0x9E1A2D38, 0xC612, 0x4316, { 0xAA,0x26,0x8B,0x49,0x52,0x1E,0x5A,0x8B} }, NULL, NULL, NULL }, { "PowerPC PReP boot", { 0x9E1A2D38, 0xC612, 0x4316, { 0xAA,0x26,0x8B,0x49,0x52,0x1E,0x5A,0x8B} }, NULL, NULL, NULL },

View file

@ -30,9 +30,10 @@
#include "main.h" #include "main.h"
guid_t efiguid = { 0xC12A7328, 0xF81F, 0x11D2, { 0xBA,0x4B,0x00,0xA0,0xC9,0x3E,0xC9,0x3B} }; guid_t efiguid = { 0xC12A7328, 0xF81F, 0x11D2, { 0xBA,0x4B,0x00,0xA0,0xC9,0x3E,0xC9,0x3B} };
guid_t bbpguid = { 0x21686148, 0x6449, 0x6E6F, { 0x74,0x4E,0x65,0x65,0x64,0x45,0x46,0x49} };
unsigned char *gpt = NULL, gpt2[512]; unsigned char *gpt = NULL, gpt2[512];
unsigned long int gpt_parts[248]; unsigned long int gpt_parts[248];
int np = 0; int np = 0, bbp_start = 0, bbp_end = 0;
/** /**
* Set integers in byte arrays * Set integers in byte arrays
@ -61,6 +62,7 @@ void gpt_maketable()
total = (2*es + esiz) * 512; total = (2*es + esiz) * 512;
memset(gpt_parts, 0, sizeof(gpt_parts)); memset(gpt_parts, 0, sizeof(gpt_parts));
for(np = 1; np < 248; np++) { for(np = 1; np < 248; np++) {
/* get type, either fsname or GUID */
sprintf(key, "partitions.%d.%s", np, "type"); sprintf(key, "partitions.%d.%s", np, "type");
tmp = json_get(json, key); tmp = json_get(json, key);
if(!tmp || !*tmp) break; if(!tmp || !*tmp) break;
@ -68,11 +70,11 @@ void gpt_maketable()
for(i = 0; fsdrv[i].name; i++) for(i = 0; fsdrv[i].name; i++)
if(fsdrv[i].type.Data1 && !strcmp(tmp, fsdrv[i].name)) { memcpy(&typeguid, &fsdrv[i].type, sizeof(guid_t)); break; } if(fsdrv[i].type.Data1 && !strcmp(tmp, fsdrv[i].name)) { memcpy(&typeguid, &fsdrv[i].type, sizeof(guid_t)); break; }
free(tmp); free(tmp);
if(!typeguid.Data1 && !typeguid.Data2 && !typeguid.Data3 && !typeguid.Data4[0]) { /* override with specific GUID if type was an fsname */
sprintf(key, "partitions.%d.%s", np, "typeguid"); sprintf(key, "partitions.%d.%s", np, "typeguid");
tmp = json_get(json, key); tmp = json_get(json, key);
if(tmp && *tmp) { getguid(tmp, &typeguid); free(tmp); } if(tmp && *tmp) { getguid(tmp, &typeguid); free(tmp); }
} /* if there's still no type GUID */
if(!typeguid.Data1 && !typeguid.Data2 && !typeguid.Data3 && !typeguid.Data4[0]) { if(!typeguid.Data1 && !typeguid.Data2 && !typeguid.Data3 && !typeguid.Data4[0]) {
fprintf(stderr,"mkbootimg: partition #%d %s. %s:\r\n", np+1, lang[ERR_TYPE], lang[ERR_ACCEPTVALUES]); fprintf(stderr,"mkbootimg: partition #%d %s. %s:\r\n", np+1, lang[ERR_TYPE], lang[ERR_ACCEPTVALUES]);
for(i = 0; fsdrv[i].name; i++) for(i = 0; fsdrv[i].name; i++)
@ -85,10 +87,12 @@ void gpt_maketable()
fprintf(stderr," ...%s \"%%08X-%%04X-%%04X-%%04X-%%12X\"\r\n",lang[ERR_GUIDFMT]); fprintf(stderr," ...%s \"%%08X-%%04X-%%04X-%%04X-%%12X\"\r\n",lang[ERR_GUIDFMT]);
exit(1); exit(1);
} }
/* partition's name */
sprintf(key, "partitions.%d.%s", np, "name"); sprintf(key, "partitions.%d.%s", np, "name");
tmp = json_get(json, key); tmp = json_get(json, key);
if(!tmp || !*tmp) { fprintf(stderr,"mkbootimg: partition #%d %s\r\n", np+1, lang[ERR_NONAME]); exit(1); } if(!tmp || !*tmp) { fprintf(stderr,"mkbootimg: partition #%d %s\r\n", np+1, lang[ERR_NONAME]); exit(1); }
free(tmp); free(tmp);
/* size and/or image file's size */
sprintf(key, "partitions.%d.%s", np, "size"); sprintf(key, "partitions.%d.%s", np, "size");
tmp = json_get(json, key); if(tmp) { size = atoi(tmp) * 1024UL * 1024UL; } else { size = 0; } free(tmp); tmp = json_get(json, key); if(tmp) { size = atoi(tmp) * 1024UL * 1024UL; } else { size = 0; } free(tmp);
sprintf(key, "partitions.%d.%s", np, "file"); sprintf(key, "partitions.%d.%s", np, "file");
@ -173,6 +177,20 @@ void gpt_maketable()
for(i = 0; name[i]; i++) p[56+i*2] = name[i]; for(i = 0; name[i]; i++) p[56+i*2] = name[i];
p += 128; p += 128;
/* BIOS BOOT Partition (needed for Risc-V64 Icicle firmware, not mounted, binary blob) */
if(bbp_start && bbp_end && bbp_start <= bbp_end) {
/* it would have been more fortunate if Microchip had choosen its own Microchip boot partition type guid */
memcpy(p, &bbpguid, sizeof(guid_t)); /* entry type */
diskguid.Data1++;
memcpy(p+16, &diskguid, sizeof(guid_t)); /* partition UUID */
setint(bbp_start,p+32); /* start LBA */
setint(bbp_end,p+40); /* end LBA */
name = "BOOTBOOT RISC-V"; /* name */
for(i = 0; name[i]; i++) p[56+i*2] = name[i];
p += 128;
}
/* add user defined partitions */
for(k = 1; k < np; k++) { for(k = 1; k < np; k++) {
sprintf(key, "partitions.%d.%s", k, "type"); sprintf(key, "partitions.%d.%s", k, "type");
tmp = json_get(json, key); tmp = json_get(json, key);

View file

@ -434,7 +434,7 @@ int main(int argc, char **argv)
" ./mkbootimg <%s> <%s>\r\n\r\n",lang[HELP3],lang[HELP4], " ./mkbootimg <%s> <%s>\r\n\r\n",lang[HELP3],lang[HELP4],
lang[HELP4],lang[HELP4],lang[HELP5]); lang[HELP4],lang[HELP4],lang[HELP5]);
printf( "%s:\n" printf( "%s:\n"
" ./mkbootimg check mykernel/mykernel.x86_64.elf\r\n" " ./mkbootimg check mykernel/c/mykernel.x86_64.elf\r\n"
" ./mkbootimg myos.json initrd.rom\r\n" " ./mkbootimg myos.json initrd.rom\r\n"
" ./mkbootimg myos.json bootpart.bin\r\n" " ./mkbootimg myos.json bootpart.bin\r\n"
" ./mkbootimg myos.json myos.img\r\n", " ./mkbootimg myos.json myos.img\r\n",

View file

@ -185,7 +185,7 @@ extern time_t t;
extern struct tm *ts; extern struct tm *ts;
extern guid_t diskguid; extern guid_t diskguid;
extern char *json, *config, *kernelname, *initrd_dir[NUMARCH], initrd_arch[NUMARCH]; extern char *json, *config, *kernelname, *initrd_dir[NUMARCH], initrd_arch[NUMARCH];
extern int fs_len, initrd_size[NUMARCH], initrd_gzip, boot_size, boot_fat, disk_size, esp_size, esp_bbs; extern int fs_len, initrd_size[NUMARCH], initrd_gzip, boot_size, boot_fat, disk_size, esp_size, esp_bbs, bbp_start, bbp_end;
extern int iso9660, skipbytes, np; extern int iso9660, skipbytes, np;
extern unsigned char *esp, *gpt, gpt2[512], *fs_base, *initrd_buf[NUMARCH]; extern unsigned char *esp, *gpt, gpt2[512], *fs_base, *initrd_buf[NUMARCH];
extern unsigned long int tsize, es, esiz, disk_align, gpt_parts[248]; extern unsigned long int tsize, es, esiz, disk_align, gpt_parts[248];

View file

@ -4,3 +4,8 @@ BOOTBOOT MicroChip Icicle Risc-V64 Implementation
See [BOOTBOOT Protocol](https://gitlab.com/bztsrc/bootboot) for common details. See [BOOTBOOT Protocol](https://gitlab.com/bztsrc/bootboot) for common details.
Currently __EXPERIMENTAL__. Currently __EXPERIMENTAL__.
Generates dist/bootboot.rv64, should include Risc-V hart config and bootboot.elf and use the same format as
https://github.com/polarfire-soc/hart-software-services/tree/master/tools/hss-payload-generator
mkbootimg already knows what to do with that file, but currently installs an empty blob.