loader: Move ramdisk export to md.c

Move the common routine to md.c and use it where we do memdisks today.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59417
This commit is contained in:
Warner Losh committed 2026-09-10 22:15:27 -06:00
1 parent 4f7475ab5b
commit 7055aa7a07
5 files changed
+26 -16

No files matched your search

+3
View File
@@ -381,4 +381,7 @@ int gen_setcurrdev(struct env_var *ev, int flags, const void *value);
int mount_currdev(struct env_var *, int, const void *);
void set_currdev(const char *devname);
/* md.c */
void md_export_to_kernel(uint64_t start, uint64_t len);
#endif /* !_BOOTSTRAP_H_ */
+19
View File
@@ -34,6 +34,25 @@
#define MD_BLOCK_SIZE 512
/*
* The kernel can accept a MD inline in the metadata, or out-of-line via
* hints, like when memory disks are passed to us in, for example, UEFI.
*/
void
md_export_to_kernel(uint64_t start, uint64_t len)
{
char key[32], value[32];
static int unit = 0; /* Note: loader unit and kernel unit may differ */
snprintf(key, sizeof(key), "hint.md.%d.physaddr", unit);
snprintf(value, sizeof(value), "0x%016jx", (uintmax_t)start);
setenv(key, value, 1);
snprintf(key, sizeof(key), "hint.md.%d.len", unit);
snprintf(value, sizeof(value), "%jd", (uintmax_t)len);
setenv(key, value, 1);
unit++;
}
#ifdef MD_IMAGE_SIZE
#if (MD_IMAGE_SIZE == 0 || MD_IMAGE_SIZE % MD_BLOCK_SIZE)
+1 -7
View File
@@ -1278,7 +1278,6 @@ efiblk_memdisk_preload(void)
MEDIA_RAM_DISK_DEVICE_PATH *ram;
uint64_t start, end;
pdinfo_t *md;
char key[32], value[32];
int i;
STAILQ_FOREACH(md, &pdinfo, pd_link) {
@@ -1288,11 +1287,6 @@ efiblk_memdisk_preload(void)
i = ram->Instance;
start = ((uint64_t)ram->StartingAddr[1] << 32) | ram->StartingAddr[0];
end = ((uint64_t)ram->EndingAddr[1] << 32) | ram->EndingAddr[0];
snprintf(key, sizeof(key), "hint.md.%d.physaddr", i);
snprintf(value, sizeof(value), "0x%016x", start);
setenv(key, value, 1);
snprintf(key, sizeof(key), "hint.md.%d.len", i);
snprintf(value, sizeof(value), "%d", end - start + 1);
setenv(key, value, 1);
md_export_to_kernel(start, end - start + 1);
}
}
+2 -9
View File
@@ -66,8 +66,7 @@ struct safe_13h_hook {
void
biosmemdisk_detect(void)
{
char line[80], scratch[80];
int hook = 0, count = 0, sector_size;
int hook = 0, sector_size;
uint16_t segment, offset;
struct safe_13h_hook *probe;
ACPI_TABLE_HEADER *mbft;
@@ -125,13 +124,7 @@ biosmemdisk_detect(void)
mdi->mdi_major, mdi->mdi_minor, mdi->mdi_disk_ptr,
mdi->mdi_disk_sectors, mdi->mdi_disk_sectors * sector_size);
snprintf(line, sizeof(line), "hint.md.%d.physaddr", count);
snprintf(scratch, sizeof(scratch), "0x%08x", mdi->mdi_disk_ptr);
setenv(line, scratch, 1);
snprintf(line, sizeof(line), "hint.md.%d.len", count);
snprintf(scratch, sizeof(scratch), "%d", mdi->mdi_disk_sectors * sector_size);
setenv(line, scratch, 1);
count++;
md_export_to_kernel(mdi->mdi_disk_ptr, mdi->mdi_disk_sectors * sector_size);
end_of_loop:
hook++;
offset = probe->sh_next_offset;
+1
View File
@@ -10,6 +10,7 @@ LOADER_UFS_SUPPORT?= yes
LOADER_GZIP_SUPPORT?= yes
LOADER_BZIP2_SUPPORT?= yes
LOADER_XZ_SUPPORT?= yes
LOADER_MD_SUPPORT?= yes
.include <bsd.init.mk>