2017-07-12 15:49:51 +03:00
|
|
|
/*
|
|
|
|
* S390 virtio-ccw network boot loading program
|
|
|
|
*
|
|
|
|
* Copyright 2017 Thomas Huth, Red Hat Inc.
|
|
|
|
*
|
|
|
|
* Based on the S390 virtio-ccw loading program (main.c)
|
|
|
|
* Copyright (c) 2013 Alexander Graf <agraf@suse.de>
|
|
|
|
*
|
2017-07-12 15:49:53 +03:00
|
|
|
* And based on the network loading code from SLOF (netload.c)
|
|
|
|
* Copyright (c) 2004, 2008 IBM Corporation
|
|
|
|
*
|
2017-07-12 15:49:51 +03:00
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2017-07-12 15:49:53 +03:00
|
|
|
|
|
|
|
#include <tftp.h>
|
|
|
|
#include <ethernet.h>
|
|
|
|
#include <dhcp.h>
|
|
|
|
#include <dhcpv6.h>
|
|
|
|
#include <ipv4.h>
|
|
|
|
#include <ipv6.h>
|
|
|
|
#include <dns.h>
|
2017-07-12 15:49:51 +03:00
|
|
|
#include <time.h>
|
2018-05-22 12:37:29 +03:00
|
|
|
#include <pxelinux.h>
|
2017-07-12 15:49:51 +03:00
|
|
|
|
|
|
|
#include "s390-ccw.h"
|
2019-04-04 17:34:24 +03:00
|
|
|
#include "cio.h"
|
2017-07-12 15:49:51 +03:00
|
|
|
#include "virtio.h"
|
2020-06-24 10:52:16 +03:00
|
|
|
#include "s390-time.h"
|
2017-07-12 15:49:51 +03:00
|
|
|
|
2017-07-12 15:49:53 +03:00
|
|
|
#define DEFAULT_BOOT_RETRIES 10
|
|
|
|
#define DEFAULT_TFTP_RETRIES 20
|
|
|
|
|
2017-07-12 15:49:51 +03:00
|
|
|
extern char _start[];
|
2020-03-04 14:42:31 +03:00
|
|
|
void write_iplb_location(void) {}
|
2017-07-12 15:49:51 +03:00
|
|
|
|
2018-04-18 15:02:37 +03:00
|
|
|
#define KERNEL_ADDR ((void *)0L)
|
|
|
|
#define KERNEL_MAX_SIZE ((long)_start)
|
2018-05-22 12:37:29 +03:00
|
|
|
#define ARCH_COMMAND_LINE_SIZE 896 /* Taken from Linux kernel */
|
2018-04-18 15:02:37 +03:00
|
|
|
|
2018-05-22 12:53:51 +03:00
|
|
|
/* STSI 3.2.2 offset of first vmdb + offset of uuid inside vmdb */
|
|
|
|
#define STSI322_VMDB_UUID_OFFSET ((8 + 12) * 4)
|
|
|
|
|
2017-07-12 15:49:51 +03:00
|
|
|
char stack[PAGE_SIZE * 8] __attribute__((aligned(PAGE_SIZE)));
|
|
|
|
IplParameterBlock iplb __attribute__((aligned(PAGE_SIZE)));
|
2018-04-18 15:02:37 +03:00
|
|
|
static char cfgbuf[2048];
|
2017-07-12 15:49:51 +03:00
|
|
|
|
|
|
|
static SubChannelId net_schid = { .one = 1 };
|
2018-05-22 12:37:29 +03:00
|
|
|
static uint8_t mac[6];
|
2017-07-12 15:49:51 +03:00
|
|
|
static uint64_t dest_timer;
|
|
|
|
|
|
|
|
void set_timer(int val)
|
|
|
|
{
|
2020-06-24 10:52:16 +03:00
|
|
|
dest_timer = get_time_ms() + val;
|
2017-07-12 15:49:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_timer(void)
|
|
|
|
{
|
2020-06-24 10:52:16 +03:00
|
|
|
return dest_timer - get_time_ms();
|
2017-07-12 15:49:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_sec_ticks(void)
|
|
|
|
{
|
|
|
|
return 1000; /* number of ticks in 1 second */
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:49:53 +03:00
|
|
|
/**
|
|
|
|
* Obtain IP and configuration info from DHCP server (either IPv4 or IPv6).
|
|
|
|
* @param fn_ip contains the following configuration information:
|
|
|
|
* client MAC, client IP, TFTP-server MAC, TFTP-server IP,
|
|
|
|
* boot file name
|
|
|
|
* @param retries Number of DHCP attempts
|
|
|
|
* @return 0 : IP and configuration info obtained;
|
|
|
|
* non-0 : error condition occurred.
|
|
|
|
*/
|
|
|
|
static int dhcp(struct filename_ip *fn_ip, int retries)
|
|
|
|
{
|
|
|
|
int i = retries + 1;
|
|
|
|
int rc = -1;
|
|
|
|
|
|
|
|
printf(" Requesting information via DHCP: ");
|
|
|
|
|
|
|
|
dhcpv4_generate_transaction_id();
|
|
|
|
dhcpv6_generate_transaction_id();
|
|
|
|
|
|
|
|
do {
|
|
|
|
printf("\b\b\b%03d", i - 1);
|
|
|
|
if (!--i) {
|
|
|
|
printf("\nGiving up after %d DHCP requests\n", retries);
|
|
|
|
return -1;
|
|
|
|
}
|
2018-05-18 12:31:27 +03:00
|
|
|
fn_ip->ip_version = 4;
|
2017-07-12 15:49:53 +03:00
|
|
|
rc = dhcpv4(NULL, fn_ip);
|
|
|
|
if (rc == -1) {
|
2018-05-18 12:31:27 +03:00
|
|
|
fn_ip->ip_version = 6;
|
2017-07-12 15:49:53 +03:00
|
|
|
set_ipv6_address(fn_ip->fd, 0);
|
|
|
|
rc = dhcpv6(NULL, fn_ip);
|
|
|
|
if (rc == 0) {
|
|
|
|
memcpy(&fn_ip->own_ip6, get_ipv6_address(), 16);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rc != -1) { /* either success or non-dhcp failure */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
printf("\b\b\b\bdone\n");
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Seed the random number generator with our mac and current timestamp
|
|
|
|
*/
|
|
|
|
static void seed_rng(uint8_t mac[])
|
|
|
|
{
|
|
|
|
uint64_t seed;
|
|
|
|
|
|
|
|
asm volatile(" stck %0 " : : "Q"(seed) : "memory");
|
|
|
|
seed ^= (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5];
|
|
|
|
srand(seed);
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:36:10 +03:00
|
|
|
static int tftp_load(filename_ip_t *fnip, void *buffer, int len)
|
2017-07-12 15:49:53 +03:00
|
|
|
{
|
|
|
|
tftp_err_t tftp_err;
|
|
|
|
int rc;
|
|
|
|
|
2018-05-18 12:31:27 +03:00
|
|
|
rc = tftp(fnip, buffer, len, DEFAULT_TFTP_RETRIES, &tftp_err);
|
2017-07-12 15:49:53 +03:00
|
|
|
|
2018-04-18 15:02:37 +03:00
|
|
|
if (rc < 0) {
|
|
|
|
/* Make sure that error messages are put into a new line */
|
|
|
|
printf("\n ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc > 1024) {
|
|
|
|
printf(" TFTP: Received %s (%d KBytes)\n", fnip->filename, rc / 1024);
|
|
|
|
} else if (rc > 0) {
|
|
|
|
printf(" TFTP: Received %s (%d Bytes)\n", fnip->filename, rc);
|
2018-05-18 12:31:27 +03:00
|
|
|
} else {
|
|
|
|
const char *errstr = NULL;
|
|
|
|
int ecode;
|
|
|
|
tftp_get_error_info(fnip, &tftp_err, rc, &errstr, &ecode);
|
|
|
|
printf("TFTP error: %s\n", errstr ? errstr : "unknown error");
|
2017-07-12 15:49:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:36:10 +03:00
|
|
|
static int net_init(filename_ip_t *fn_ip)
|
2017-07-12 15:49:53 +03:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2018-04-17 08:36:10 +03:00
|
|
|
memset(fn_ip, 0, sizeof(filename_ip_t));
|
2017-07-12 15:49:53 +03:00
|
|
|
|
|
|
|
rc = virtio_net_init(mac);
|
|
|
|
if (rc < 0) {
|
|
|
|
puts("Could not initialize network device");
|
|
|
|
return -101;
|
|
|
|
}
|
2018-04-17 08:36:10 +03:00
|
|
|
fn_ip->fd = rc;
|
2017-07-12 15:49:53 +03:00
|
|
|
|
|
|
|
printf(" Using MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
|
|
|
|
|
|
set_mac_address(mac); /* init ethernet layer */
|
|
|
|
seed_rng(mac);
|
|
|
|
|
2018-04-17 08:36:10 +03:00
|
|
|
rc = dhcp(fn_ip, DEFAULT_BOOT_RETRIES);
|
2017-07-12 15:49:53 +03:00
|
|
|
if (rc >= 0) {
|
2018-05-18 12:31:27 +03:00
|
|
|
if (fn_ip->ip_version == 4) {
|
2018-04-17 08:36:10 +03:00
|
|
|
set_ipv4_address(fn_ip->own_ip);
|
2017-07-12 15:49:53 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
puts("Could not get IP address");
|
|
|
|
return -101;
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:31:27 +03:00
|
|
|
if (fn_ip->ip_version == 4) {
|
2017-07-12 15:49:53 +03:00
|
|
|
printf(" Using IPv4 address: %d.%d.%d.%d\n",
|
2018-04-17 08:36:10 +03:00
|
|
|
(fn_ip->own_ip >> 24) & 0xFF, (fn_ip->own_ip >> 16) & 0xFF,
|
|
|
|
(fn_ip->own_ip >> 8) & 0xFF, fn_ip->own_ip & 0xFF);
|
2018-05-18 12:31:27 +03:00
|
|
|
} else if (fn_ip->ip_version == 6) {
|
2017-07-12 15:49:53 +03:00
|
|
|
char ip6_str[40];
|
2018-04-17 08:36:10 +03:00
|
|
|
ipv6_to_str(fn_ip->own_ip6.addr, ip6_str);
|
2017-07-12 15:49:53 +03:00
|
|
|
printf(" Using IPv6 address: %s\n", ip6_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc == -2) {
|
|
|
|
printf("ARP request to TFTP server (%d.%d.%d.%d) failed\n",
|
2018-04-17 08:36:10 +03:00
|
|
|
(fn_ip->server_ip >> 24) & 0xFF, (fn_ip->server_ip >> 16) & 0xFF,
|
|
|
|
(fn_ip->server_ip >> 8) & 0xFF, fn_ip->server_ip & 0xFF);
|
2017-07-12 15:49:53 +03:00
|
|
|
return -102;
|
|
|
|
}
|
|
|
|
if (rc == -4 || rc == -3) {
|
|
|
|
puts("Can't obtain TFTP server IP address");
|
|
|
|
return -107;
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:36:10 +03:00
|
|
|
printf(" Using TFTP server: ");
|
2018-05-18 12:31:27 +03:00
|
|
|
if (fn_ip->ip_version == 4) {
|
2018-04-17 08:36:10 +03:00
|
|
|
printf("%d.%d.%d.%d\n",
|
|
|
|
(fn_ip->server_ip >> 24) & 0xFF, (fn_ip->server_ip >> 16) & 0xFF,
|
|
|
|
(fn_ip->server_ip >> 8) & 0xFF, fn_ip->server_ip & 0xFF);
|
2018-05-18 12:31:27 +03:00
|
|
|
} else if (fn_ip->ip_version == 6) {
|
2017-07-12 15:49:53 +03:00
|
|
|
char ip6_str[40];
|
2018-04-17 08:36:10 +03:00
|
|
|
ipv6_to_str(fn_ip->server_ip6.addr, ip6_str);
|
2017-07-12 15:49:53 +03:00
|
|
|
printf("%s\n", ip6_str);
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:31:27 +03:00
|
|
|
if (strlen(fn_ip->filename) > 0) {
|
2018-04-17 08:36:10 +03:00
|
|
|
printf(" Bootfile name: '%s'\n", fn_ip->filename);
|
2017-07-12 15:49:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:36:10 +03:00
|
|
|
static void net_release(filename_ip_t *fn_ip)
|
|
|
|
{
|
2018-05-18 12:31:27 +03:00
|
|
|
if (fn_ip->ip_version == 4) {
|
2018-04-17 08:36:10 +03:00
|
|
|
dhcp_send_release(fn_ip->fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 12:53:51 +03:00
|
|
|
/**
|
|
|
|
* Retrieve the Universally Unique Identifier of the VM.
|
|
|
|
* @return UUID string, or NULL in case of errors
|
|
|
|
*/
|
|
|
|
static const char *get_uuid(void)
|
|
|
|
{
|
|
|
|
register int r0 asm("0");
|
|
|
|
register int r1 asm("1");
|
|
|
|
uint8_t *mem, *buf, uuid[16];
|
|
|
|
int i, cc, chk = 0;
|
|
|
|
static char uuid_str[37];
|
|
|
|
|
|
|
|
mem = malloc(2 * PAGE_SIZE);
|
|
|
|
if (!mem) {
|
|
|
|
puts("Out of memory ... can not get UUID.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
buf = (uint8_t *)(((uint64_t)mem + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1));
|
|
|
|
memset(buf, 0, PAGE_SIZE);
|
|
|
|
|
|
|
|
/* Get SYSIB 3.2.2 */
|
|
|
|
r0 = (3 << 28) | 2;
|
|
|
|
r1 = 2;
|
|
|
|
asm volatile(" stsi 0(%[addr])\n"
|
|
|
|
" ipm %[cc]\n"
|
|
|
|
" srl %[cc],28\n"
|
|
|
|
: [cc] "=d" (cc)
|
|
|
|
: "d" (r0), "d" (r1), [addr] "a" (buf)
|
|
|
|
: "cc", "memory");
|
|
|
|
if (cc) {
|
2019-08-14 09:14:26 +03:00
|
|
|
free(mem);
|
2018-05-22 12:53:51 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
uuid[i] = buf[STSI322_VMDB_UUID_OFFSET + i];
|
|
|
|
chk |= uuid[i];
|
|
|
|
}
|
|
|
|
free(mem);
|
|
|
|
if (!chk) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(uuid_str, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
|
|
|
|
"%02x%02x%02x%02x%02x%02x", uuid[0], uuid[1], uuid[2], uuid[3],
|
|
|
|
uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10],
|
|
|
|
uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
|
|
|
|
|
|
|
|
return uuid_str;
|
|
|
|
}
|
|
|
|
|
2018-05-22 12:37:29 +03:00
|
|
|
/**
|
|
|
|
* Load a kernel with initrd (i.e. with the information that we've got from
|
|
|
|
* a pxelinux.cfg config file)
|
|
|
|
*/
|
|
|
|
static int load_kernel_with_initrd(filename_ip_t *fn_ip,
|
|
|
|
struct pl_cfg_entry *entry)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
printf("Loading pxelinux.cfg entry '%s'\n", entry->label);
|
|
|
|
|
|
|
|
if (!entry->kernel) {
|
|
|
|
printf("Kernel entry is missing!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(fn_ip->filename, entry->kernel, sizeof(fn_ip->filename));
|
|
|
|
rc = tftp_load(fn_ip, KERNEL_ADDR, KERNEL_MAX_SIZE);
|
|
|
|
if (rc < 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry->initrd) {
|
|
|
|
uint64_t iaddr = (rc + 0xfff) & ~0xfffUL;
|
|
|
|
|
|
|
|
strncpy(fn_ip->filename, entry->initrd, sizeof(fn_ip->filename));
|
|
|
|
rc = tftp_load(fn_ip, (void *)iaddr, KERNEL_MAX_SIZE - iaddr);
|
|
|
|
if (rc < 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
/* Patch location and size: */
|
|
|
|
*(uint64_t *)0x10408 = iaddr;
|
|
|
|
*(uint64_t *)0x10410 = rc;
|
|
|
|
rc += iaddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry->append) {
|
|
|
|
strncpy((char *)0x10480, entry->append, ARCH_COMMAND_LINE_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_PXELINUX_ENTRIES 16
|
|
|
|
|
|
|
|
static int net_try_pxelinux_cfg(filename_ip_t *fn_ip)
|
|
|
|
{
|
|
|
|
struct pl_cfg_entry entries[MAX_PXELINUX_ENTRIES];
|
|
|
|
int num_ent, def_ent = 0;
|
|
|
|
|
2018-05-22 12:53:51 +03:00
|
|
|
num_ent = pxelinux_load_parse_cfg(fn_ip, mac, get_uuid(),
|
|
|
|
DEFAULT_TFTP_RETRIES,
|
2018-05-22 12:37:29 +03:00
|
|
|
cfgbuf, sizeof(cfgbuf),
|
|
|
|
entries, MAX_PXELINUX_ENTRIES, &def_ent);
|
|
|
|
if (num_ent > 0) {
|
|
|
|
return load_kernel_with_initrd(fn_ip, &entries[def_ent]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-04-18 15:02:37 +03:00
|
|
|
/**
|
|
|
|
* Load via information from a .INS file (which can be found on CD-ROMs
|
|
|
|
* for example)
|
|
|
|
*/
|
|
|
|
static int handle_ins_cfg(filename_ip_t *fn_ip, char *cfg, int cfgsize)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
int rc = -1, llen;
|
|
|
|
void *destaddr;
|
|
|
|
char *insbuf = cfg;
|
|
|
|
|
|
|
|
ptr = strchr(insbuf, '\n');
|
|
|
|
if (!ptr) {
|
|
|
|
puts("Does not seem to be a valid .INS file");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ptr = 0;
|
|
|
|
printf("\nParsing .INS file:\n %s\n", &insbuf[2]);
|
|
|
|
|
|
|
|
insbuf = ptr + 1;
|
|
|
|
while (*insbuf && insbuf < cfg + cfgsize) {
|
|
|
|
ptr = strchr(insbuf, '\n');
|
|
|
|
if (ptr) {
|
|
|
|
*ptr = 0;
|
|
|
|
}
|
|
|
|
llen = strlen(insbuf);
|
|
|
|
if (!llen) {
|
|
|
|
insbuf = ptr + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ptr = strchr(insbuf, ' ');
|
|
|
|
if (!ptr) {
|
|
|
|
puts("Missing space separator in .INS file");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*ptr = 0;
|
2018-05-18 12:31:27 +03:00
|
|
|
strncpy(fn_ip->filename, insbuf, sizeof(fn_ip->filename));
|
2018-04-18 15:02:37 +03:00
|
|
|
destaddr = (char *)atol(ptr + 1);
|
|
|
|
rc = tftp_load(fn_ip, destaddr, (long)_start - (long)destaddr);
|
|
|
|
if (rc <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
insbuf += llen + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int net_try_direct_tftp_load(filename_ip_t *fn_ip)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
void *loadaddr = (void *)0x2000; /* Load right after the low-core */
|
|
|
|
|
|
|
|
rc = tftp_load(fn_ip, loadaddr, KERNEL_MAX_SIZE - (long)loadaddr);
|
|
|
|
if (rc < 0) {
|
|
|
|
return rc;
|
|
|
|
} else if (rc < 8) {
|
|
|
|
printf("'%s' is too small (%i bytes only).\n", fn_ip->filename, rc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether it is a configuration file instead of a kernel */
|
|
|
|
if (rc < sizeof(cfgbuf) - 1) {
|
|
|
|
memcpy(cfgbuf, loadaddr, rc);
|
|
|
|
cfgbuf[rc] = 0; /* Make sure that it is NUL-terminated */
|
|
|
|
if (!strncmp("* ", cfgbuf, 2)) {
|
|
|
|
return handle_ins_cfg(fn_ip, cfgbuf, rc);
|
|
|
|
}
|
2018-05-22 12:37:29 +03:00
|
|
|
/*
|
|
|
|
* pxelinux.cfg support via bootfile name is just here for developers'
|
|
|
|
* convenience (it eases testing with the built-in DHCP server of QEMU
|
|
|
|
* that does not support RFC 5071). The official way to configure a
|
|
|
|
* pxelinux.cfg file name is to use DHCP options 209 and 210 instead.
|
|
|
|
* So only use the pxelinux.cfg parser here for files that start with
|
|
|
|
* a magic comment string.
|
|
|
|
*/
|
|
|
|
if (!strncasecmp("# pxelinux", cfgbuf, 10)) {
|
|
|
|
struct pl_cfg_entry entries[MAX_PXELINUX_ENTRIES];
|
|
|
|
int num_ent, def_ent = 0;
|
|
|
|
|
|
|
|
num_ent = pxelinux_parse_cfg(cfgbuf, sizeof(cfgbuf), entries,
|
|
|
|
MAX_PXELINUX_ENTRIES, &def_ent);
|
|
|
|
if (num_ent <= 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return load_kernel_with_initrd(fn_ip, &entries[def_ent]);
|
|
|
|
}
|
2018-04-18 15:02:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Move kernel to right location */
|
|
|
|
memmove(KERNEL_ADDR, loadaddr, rc);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-04-20 12:30:42 +03:00
|
|
|
void write_subsystem_identification(void)
|
|
|
|
{
|
|
|
|
SubChannelId *schid = (SubChannelId *) 184;
|
|
|
|
uint32_t *zeroes = (uint32_t *) 188;
|
|
|
|
|
|
|
|
*schid = net_schid;
|
|
|
|
*zeroes = 0;
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:49:51 +03:00
|
|
|
static bool find_net_dev(Schib *schib, int dev_no)
|
|
|
|
{
|
|
|
|
int i, r;
|
|
|
|
|
|
|
|
for (i = 0; i < 0x10000; i++) {
|
|
|
|
net_schid.sch_no = i;
|
|
|
|
r = stsch_err(net_schid, schib);
|
|
|
|
if (r == 3 || r == -EIO) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!schib->pmcw.dnv) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-04 17:34:32 +03:00
|
|
|
enable_subchannel(net_schid);
|
2017-07-12 15:49:51 +03:00
|
|
|
if (!virtio_is_supported(net_schid)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (virtio_get_device_type() != VIRTIO_ID_NET) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (dev_no < 0 || schib->pmcw.dev == dev_no) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_setup(void)
|
|
|
|
{
|
|
|
|
Schib schib;
|
|
|
|
int ssid;
|
|
|
|
bool found = false;
|
|
|
|
uint16_t dev_no;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We unconditionally enable mss support. In every sane configuration,
|
|
|
|
* this will succeed; and even if it doesn't, stsch_err() can deal
|
|
|
|
* with the consequences.
|
|
|
|
*/
|
|
|
|
enable_mss_facility();
|
|
|
|
|
|
|
|
if (store_iplb(&iplb)) {
|
|
|
|
IPL_assert(iplb.pbt == S390_IPL_TYPE_CCW, "IPL_TYPE_CCW expected");
|
|
|
|
dev_no = iplb.ccw.devno;
|
|
|
|
debug_print_int("device no. ", dev_no);
|
|
|
|
net_schid.ssid = iplb.ccw.ssid & 0x3;
|
|
|
|
debug_print_int("ssid ", net_schid.ssid);
|
|
|
|
found = find_net_dev(&schib, dev_no);
|
|
|
|
} else {
|
|
|
|
for (ssid = 0; ssid < 0x3; ssid++) {
|
|
|
|
net_schid.ssid = ssid;
|
|
|
|
found = find_net_dev(&schib, -1);
|
|
|
|
if (found) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IPL_assert(found, "No virtio net device found");
|
|
|
|
}
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
2018-04-17 08:36:10 +03:00
|
|
|
filename_ip_t fn_ip;
|
2018-04-18 15:02:37 +03:00
|
|
|
int rc, fnlen;
|
2017-07-12 15:49:53 +03:00
|
|
|
|
2017-07-12 15:49:51 +03:00
|
|
|
sclp_setup();
|
|
|
|
sclp_print("Network boot starting...\n");
|
|
|
|
|
|
|
|
virtio_setup();
|
|
|
|
|
2018-04-17 08:36:10 +03:00
|
|
|
rc = net_init(&fn_ip);
|
|
|
|
if (rc) {
|
|
|
|
panic("Network initialization failed. Halting.\n");
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:31:27 +03:00
|
|
|
fnlen = strlen(fn_ip.filename);
|
2018-04-18 15:02:37 +03:00
|
|
|
if (fnlen > 0 && fn_ip.filename[fnlen - 1] != '/') {
|
|
|
|
rc = net_try_direct_tftp_load(&fn_ip);
|
|
|
|
}
|
2018-05-22 12:37:29 +03:00
|
|
|
if (rc <= 0) {
|
|
|
|
rc = net_try_pxelinux_cfg(&fn_ip);
|
|
|
|
}
|
2018-04-17 08:36:10 +03:00
|
|
|
|
|
|
|
net_release(&fn_ip);
|
|
|
|
|
2017-07-12 15:49:53 +03:00
|
|
|
if (rc > 0) {
|
|
|
|
sclp_print("Network loading done, starting kernel...\n");
|
2018-04-20 12:30:42 +03:00
|
|
|
jump_to_low_kernel();
|
2017-07-12 15:49:53 +03:00
|
|
|
}
|
|
|
|
|
2017-07-12 15:49:51 +03:00
|
|
|
panic("Failed to load OS from network\n");
|
|
|
|
}
|