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++)
boot |= (1 << (initrd_arch[i] - 1));
/* add loader's directory */
ptr = esp_mkdir(rootdir, "BOOTBOOT", 0); rootdir += 32;
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;
memcpy(esp + 0x1B0, &esp_bbs, 4);
ptr = esp_addfile(ptr, "LOADER", binary_bootboot_bin, sizeof(binary_bootboot_bin));
}
ptr = esp_addfile(ptr, "CONFIG", (unsigned char*)config, strlen(config));
/* add INITRDs */
if(!initrd_arch[1]) {
ptr = esp_addfile(ptr, initrdnames[0], initrd_buf[0], initrd_size[0]);
} else {
@ -178,21 +181,33 @@ void esp_makepart()
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)) {
/* additional platform */
}
if(boot & (1 << 2)) {
/* Risc-V 64 */
ptr = esp_addfile(rootdir, "KERNEL.IMG", binary_bootboot_rv64, sizeof(binary_bootboot_rv64));
/*** Risc-V 64 Microchip Icicle ***/
/* 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)) {
/* x86 PC (UEFI) */
/*** x86 PC (UEFI) ***/
ptr = esp_mkdir(rootdir, "EFI", 0); rootdir += 32;
ptr = esp_mkdir(ptr, "BOOT", lastcluster);
ptr = esp_addfile(ptr, "BOOTX64.EFI", binary_bootboot_efi, sizeof(binary_bootboot_efi));
}
if(boot & (1 << 0)) {
/* Raspberry Pi */
/*** Raspberry Pi ***/
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, "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 },
{ "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 },
{ "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 },
{ "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 },

View File

@ -30,9 +30,10 @@
#include "main.h"
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 long int gpt_parts[248];
int np = 0;
int np = 0, bbp_start = 0, bbp_end = 0;
/**
* Set integers in byte arrays
@ -61,6 +62,7 @@ void gpt_maketable()
total = (2*es + esiz) * 512;
memset(gpt_parts, 0, sizeof(gpt_parts));
for(np = 1; np < 248; np++) {
/* get type, either fsname or GUID */
sprintf(key, "partitions.%d.%s", np, "type");
tmp = json_get(json, key);
if(!tmp || !*tmp) break;
@ -68,11 +70,11 @@ void gpt_maketable()
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; }
free(tmp);
if(!typeguid.Data1 && !typeguid.Data2 && !typeguid.Data3 && !typeguid.Data4[0]) {
sprintf(key, "partitions.%d.%s", np, "typeguid");
tmp = json_get(json, key);
if(tmp && *tmp) { getguid(tmp, &typeguid); free(tmp); }
}
/* override with specific GUID if type was an fsname */
sprintf(key, "partitions.%d.%s", np, "typeguid");
tmp = json_get(json, key);
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]) {
fprintf(stderr,"mkbootimg: partition #%d %s. %s:\r\n", np+1, lang[ERR_TYPE], lang[ERR_ACCEPTVALUES]);
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]);
exit(1);
}
/* partition's name */
sprintf(key, "partitions.%d.%s", np, "name");
tmp = json_get(json, key);
if(!tmp || !*tmp) { fprintf(stderr,"mkbootimg: partition #%d %s\r\n", np+1, lang[ERR_NONAME]); exit(1); }
free(tmp);
/* size and/or image file's 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);
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];
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++) {
sprintf(key, "partitions.%d.%s", k, "type");
tmp = json_get(json, key);
@ -181,15 +199,15 @@ void gpt_maketable()
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; }
free(tmp);
memcpy(p, &typeguid, sizeof(guid_t)); /* entry type */
memcpy(p, &typeguid, sizeof(guid_t)); /* entry type */
diskguid.Data1++;
memcpy(p+16, &diskguid, sizeof(guid_t)); /* partition UUID */
setint(l+1,p+32); /* start LBA */
memcpy(p+16, &diskguid, sizeof(guid_t)); /* partition UUID */
setint(l+1,p+32); /* start LBA */
l += gpt_parts[k] / 512;
setint(l,p+40); /* end LBA */
setint(l,p+40); /* end LBA */
sprintf(key, "partitions.%d.%s", k, "name"); tmp = name = json_get(json, key);
u = (uint16_t*)(p+56);
for(i = 0; i < 35 && *name; name++, i++) { /* name, utf8 to unicode16 */
for(i = 0; i < 35 && *name; name++, i++) { /* name, utf8 to unicode16 */
u[i] = *name;
if((*name & 128) != 0) {
if(!(*name & 32)) { u[i] = ((*name & 0x1F)<<6)|(name[1] & 0x3F); name += 1; } else

View File

@ -434,7 +434,7 @@ int main(int argc, char **argv)
" ./mkbootimg <%s> <%s>\r\n\r\n",lang[HELP3],lang[HELP4],
lang[HELP4],lang[HELP4],lang[HELP5]);
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 bootpart.bin\r\n"
" ./mkbootimg myos.json myos.img\r\n",

View File

@ -185,7 +185,7 @@ extern time_t t;
extern struct tm *ts;
extern guid_t diskguid;
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 unsigned char *esp, *gpt, gpt2[512], *fs_base, *initrd_buf[NUMARCH];
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.
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.