pxe: add stivale2 pxe server info tag

This commit is contained in:
Matteo Semenzato 2020-12-10 14:10:47 +01:00
parent 18992d92ec
commit c5eebbd92c
10 changed files with 41 additions and 4 deletions

View File

@ -456,6 +456,17 @@ struct stivale2_smp_info {
} __attribute__((packed));
```
#### PXE server info structure tag
This tag reports that the kernel has been booted via PXE, and reports the server ip that it was booted from.
```c
struct stivale2_struct_tag_pxe_server_info {
struct stivale2_tag tag; // Identifier: 0x29d1e96239247032
uint32_t server_ip; // Server ip in network byte order
} __attribute__((packed));
```
#### MMIO32 UART tag
This tag reports that there is a memory mapped UART port and its address. To write to this port, write the character, zero extended to a 32 bit unsigned integer to the address provided.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -80,7 +80,7 @@ void entry(uint8_t _boot_drive, int pxe_boot) {
if (!strcmp(proto, "stivale")) {
stivale_load(config, cmdline);
} else if (!strcmp(proto, "stivale2")) {
stivale2_load(config, cmdline);
stivale2_load(config, cmdline, pxe_boot);
} else if (!strcmp(proto, "linux")) {
linux_load(config, cmdline);
} else if (!strcmp(proto, "chainload")) {

View File

@ -23,6 +23,7 @@
#include <fs/file.h>
#include <mm/pmm.h>
#include <stivale/stivale2.h>
#include <pxe/tftp.h>
#define KASLR_SLIDE_BITMASK 0x03FFFF000u
@ -50,7 +51,7 @@ static void append_tag(struct stivale2_struct *s, struct stivale2_tag *tag) {
s->tags = (uint64_t)(size_t)tag;
}
void stivale2_load(char *config, char *cmdline) {
void stivale2_load(char *config, char *cmdline, bool pxe) {
struct file_handle *kernel = conv_mem_alloc(sizeof(struct file_handle));
char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
@ -352,6 +353,15 @@ void stivale2_load(char *config, char *cmdline) {
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
}
{
if (pxe) {
struct stivale2_struct_tag_pxe_server_info *tag = conv_mem_alloc(sizeof(struct stivale2_struct_tag_pxe_server_info));
tag->tag.identifier = STIVALE2_STRUCT_TAG_PXE_SERVER_INFO;
tag->server_ip = get_boot_server_info();
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
}
}
stivale_spinup(bits, level5pg && level5pg_requested, pagemap,
entry_point, &stivale2_struct, stivale2_hdr.stack);
}

View File

@ -1,6 +1,6 @@
#ifndef __PROTOS__STIVALE2_H__
#define __PROTOS__STIVALE2_H__
void stivale2_load(char *config, char *cmdline);
void stivale2_load(char *config, char *cmdline, bool pxe);
#endif

View File

@ -6,7 +6,15 @@
#include <mm/pmm.h>
#include <lib/blib.h>
int tftp_open(struct tftp_file_handle* handle, uint32_t server_ip, uint16_t server_port, const char* name) {
uint32_t get_boot_server_info() {
struct pxenv_get_cached_info cachedinfo = { 0 };
cachedinfo.packet_type = 2;
pxe_call(PXENV_GET_CACHED_INFO, ((uint16_t)rm_seg(&cachedinfo)), (uint16_t)rm_off(&cachedinfo));
struct bootph *ph = (struct bootph*)(void *) (((((uint32_t)cachedinfo.buffer) >> 16) << 4) + (((uint32_t)cachedinfo.buffer) & 0xFFFF));
return ph->sip;
}
int tftp_open(struct tftp_file_handle *handle, uint32_t server_ip, uint16_t server_port, const char *name) {
int ret = 0;
if (!server_ip) {
struct pxenv_get_cached_info cachedinfo = { 0 };

View File

@ -47,5 +47,6 @@ struct pxenv_get_file_size {
//server_ip and server_port can be 0 for default
int tftp_open(struct tftp_file_handle* handle, uint32_t server_ip, uint16_t server_port, const char* name);
int tftp_read(void *fd, void *buf, uint64_t loc, uint64_t count);
uint32_t get_boot_server_info();
#endif

View File

@ -159,4 +159,11 @@ struct stivale2_struct_tag_smp {
struct stivale2_smp_info smp_info[];
} __attribute__((packed));
#define STIVALE2_STRUCT_TAG_PXE_SERVER_INFO 0x29d1e96239247032
struct stivale2_struct_tag_pxe_server_info {
struct stivale2_tag tag;
uint32_t server_ip;
} __attribute__((packed));
#endif