From nobody Mon Apr 29 08:59:24 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511816310720634.0255794980308; Mon, 27 Nov 2017 12:58:30 -0800 (PST) Received: from localhost ([::1]:34729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJQTl-00058F-OJ for importer@patchew.org; Mon, 27 Nov 2017 15:58:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJQRw-0003Wb-BS for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eJQRs-0003Vf-DM for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:20 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:48998 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eJQRs-0003UK-7W for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:16 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vARKsIId043122 for ; Mon, 27 Nov 2017 15:56:13 -0500 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0b-001b2d01.pphosted.com with ESMTP id 2egsng191f-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Nov 2017 15:56:13 -0500 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Nov 2017 15:56:12 -0500 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Nov 2017 15:56:10 -0500 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vARKuAMR43974854; Mon, 27 Nov 2017 20:56:10 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3173728057; Mon, 27 Nov 2017 15:55:37 -0500 (EST) Received: from collin-ThinkPad-W541.pok.ibm.com (unknown [9.56.58.42]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 24B8628046; Mon, 27 Nov 2017 15:55:37 -0500 (EST) From: "Collin L. Walling" To: borntraeger@de.ibm.com, frankja@linux.vnet.ibm.com, qemu-s390x@nongnu.org, qemu-devel@nongnu.org Date: Mon, 27 Nov 2017 15:55:32 -0500 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511816136-30068-1-git-send-email-walling@linux.vnet.ibm.com> References: <1511816136-30068-1-git-send-email-walling@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112720-2213-0000-0000-00000241FCC4 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008121; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000241; SDB=6.00952101; UDB=6.00480947; IPR=6.00732182; BA=6.00005715; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018212; XFM=3.00000015; UTC=2017-11-27 20:56:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112720-2214-0000-0000-00005847D3E6 Message-Id: <1511816136-30068-2-git-send-email-walling@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-27_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711270279 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v1 1/5] s390-ccw: update libc.h X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Moved: memcmp from bootmap.h to libc.h (renamed from _memcmp) strlen from sclp.c to libc.h (renamed from _strlen) Added C standard functions: isdigit atoi Added non-C standard function: itostr Signed-off-by: Collin L. Walling Acked-by: Christian Borntraeger Reviewed-by: frankja@linux.vnet.ibm.com --- pc-bios/s390-ccw/bootmap.c | 4 +- pc-bios/s390-ccw/bootmap.h | 16 +------- pc-bios/s390-ccw/libc.h | 94 ++++++++++++++++++++++++++++++++++++++++++= ++++ pc-bios/s390-ccw/main.c | 17 +-------- pc-bios/s390-ccw/sclp.c | 10 +---- 5 files changed, 99 insertions(+), 42 deletions(-) diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index 67a6123..6f8e30f 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -512,7 +512,7 @@ static bool is_iso_bc_entry_compatible(IsoBcSection *s) "Failed to read image sector 0"); =20 /* Checking bytes 8 - 32 for S390 Linux magic */ - return !_memcmp(magic_sec + 8, linux_s390_magic, 24); + return !memcmp(magic_sec + 8, linux_s390_magic, 24); } =20 /* Location of the current sector of the directory */ @@ -641,7 +641,7 @@ static uint32_t find_iso_bc(void) if (vd->type =3D=3D VOL_DESC_TYPE_BOOT) { IsoVdElTorito *et =3D &vd->vd.boot; =20 - if (!_memcmp(&et->el_torito[0], el_torito_magic, 32)) { + if (!memcmp(&et->el_torito[0], el_torito_magic, 32)) { return bswap32(et->bc_offset); } } diff --git a/pc-bios/s390-ccw/bootmap.h b/pc-bios/s390-ccw/bootmap.h index cf99a4c..4980838 100644 --- a/pc-bios/s390-ccw/bootmap.h +++ b/pc-bios/s390-ccw/bootmap.h @@ -310,20 +310,6 @@ static inline bool magic_match(const void *data, const= void *magic) return *((uint32_t *)data) =3D=3D *((uint32_t *)magic); } =20 -static inline int _memcmp(const void *s1, const void *s2, size_t n) -{ - int i; - const uint8_t *p1 =3D s1, *p2 =3D s2; - - for (i =3D 0; i < n; i++) { - if (p1[i] !=3D p2[i]) { - return p1[i] > p2[i] ? 1 : -1; - } - } - - return 0; -} - static inline uint32_t iso_733_to_u32(uint64_t x) { return (uint32_t)x; @@ -416,7 +402,7 @@ const uint8_t vol_desc_magic[] =3D "CD001"; =20 static inline bool is_iso_vd_valid(IsoVolDesc *vd) { - return !_memcmp(&vd->ident[0], vol_desc_magic, 5) && + return !memcmp(&vd->ident[0], vol_desc_magic, 5) && vd->version =3D=3D 0x1 && vd->type <=3D VOL_DESC_TYPE_PARTITION; } diff --git a/pc-bios/s390-ccw/libc.h b/pc-bios/s390-ccw/libc.h index 0142ea8..703c34d 100644 --- a/pc-bios/s390-ccw/libc.h +++ b/pc-bios/s390-ccw/libc.h @@ -42,4 +42,98 @@ static inline void *memcpy(void *s1, const void *s2, siz= e_t n) return s1; } =20 +static inline int memcmp(const void *s1, const void *s2, size_t n) +{ + int i; + const uint8_t *p1 =3D s1, *p2 =3D s2; + + for (i =3D 0; i < n; i++) { + if (p1[i] !=3D p2[i]) { + return p1[i] > p2[i] ? 1 : -1; + } + } + + return 0; +} + +static inline size_t strlen(const char *str) +{ + size_t i; + for (i =3D 0; *str; i++) { + str++; + } + return i; +} + +static inline int isdigit(int c) +{ + return (c >=3D '0') && (c <=3D '9'); +} + +/* atoi + * + * Given a string, convert it to an integer. Any + * non-numerical value will end the conversion. + * + * @str - the string to be converted + * + * @return - an integer converted from the string str + */ +static inline int atoi(const char *str) +{ + int i; + int val =3D 0; + + for (i =3D 0; str[i]; i++) { + char c =3D str[i]; + if (!isdigit(c)) { + break; + } + val *=3D 10; + val +=3D c - '0'; + } + + return val; +} + +/* itostr + * + * Given an integer, convert it to a string. The string must be allocated + * beforehand. The resulting string will be null terminated and returned. + * + * @str - the integer to be converted + * @num - a pointer to a string to store the conversion + * + * @return - the string of the converted integer + */ +static inline char *itostr(int num, char *str) +{ + int i; + int len =3D 0; + long tens =3D 1; + + /* Handle 0 */ + if (num =3D=3D 0) { + str[0] =3D '0'; + str[1] =3D '\0'; + return str; + } + + /* Count number of digits */ + while (num / tens !=3D 0) { + tens *=3D 10; + len++; + } + + /* Convert int -> string */ + for (i =3D 0; i < len; i++) { + tens /=3D 10; + str[i] =3D num / tens % 10 + '0'; + } + + str[i] =3D '\0'; + + return str; +} + #endif diff --git a/pc-bios/s390-ccw/main.c b/pc-bios/s390-ccw/main.c index 401e9db..a8ef120 100644 --- a/pc-bios/s390-ccw/main.c +++ b/pc-bios/s390-ccw/main.c @@ -40,22 +40,7 @@ void panic(const char *string) =20 unsigned int get_loadparm_index(void) { - const char *lp =3D loadparm; - int i; - unsigned int idx =3D 0; - - for (i =3D 0; i < 8; i++) { - char c =3D lp[i]; - - if (c < '0' || c > '9') { - break; - } - - idx *=3D 10; - idx +=3D c - '0'; - } - - return idx; + return atoi(loadparm); } =20 static bool find_dev(Schib *schib, int dev_no) diff --git a/pc-bios/s390-ccw/sclp.c b/pc-bios/s390-ccw/sclp.c index b1fc8ff..486fce1 100644 --- a/pc-bios/s390-ccw/sclp.c +++ b/pc-bios/s390-ccw/sclp.c @@ -65,14 +65,6 @@ void sclp_setup(void) sclp_set_write_mask(); } =20 -static int _strlen(const char *str) -{ - int i; - for (i =3D 0; *str; i++) - str++; - return i; -} - long write(int fd, const void *str, size_t len) { WriteEventData *sccb =3D (void *)_sccb; @@ -95,7 +87,7 @@ long write(int fd, const void *str, size_t len) =20 void sclp_print(const char *str) { - write(1, str, _strlen(str)); + write(1, str, strlen(str)); } =20 void sclp_get_loadparm_ascii(char *loadparm) --=20 2.7.4 From nobody Mon Apr 29 08:59:24 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511816315624777.5437438443201; Mon, 27 Nov 2017 12:58:35 -0800 (PST) Received: from localhost ([::1]:34730 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJQTl-00058J-Sb for importer@patchew.org; Mon, 27 Nov 2017 15:58:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJQRv-0003WT-Ps for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eJQRr-0003Ta-Gy for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:19 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:59696 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eJQRr-0003Sd-BX for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:15 -0500 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vARKsZc6009274 for ; Mon, 27 Nov 2017 15:56:13 -0500 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0b-001b2d01.pphosted.com with ESMTP id 2egp8k2tnd-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Nov 2017 15:56:12 -0500 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Nov 2017 15:56:12 -0500 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Nov 2017 15:56:10 -0500 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vARKuArH49414262; Mon, 27 Nov 2017 20:56:10 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 33EA928058; Mon, 27 Nov 2017 15:55:37 -0500 (EST) Received: from collin-ThinkPad-W541.pok.ibm.com (unknown [9.56.58.42]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 27E7628048; Mon, 27 Nov 2017 15:55:37 -0500 (EST) From: "Collin L. Walling" To: borntraeger@de.ibm.com, frankja@linux.vnet.ibm.com, qemu-s390x@nongnu.org, qemu-devel@nongnu.org Date: Mon, 27 Nov 2017 15:55:33 -0500 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511816136-30068-1-git-send-email-walling@linux.vnet.ibm.com> References: <1511816136-30068-1-git-send-email-walling@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112720-2213-0000-0000-00000241FCC0 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008121; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000241; SDB=6.00952101; UDB=6.00480947; IPR=6.00732182; BA=6.00005715; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018212; XFM=3.00000015; UTC=2017-11-27 20:56:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112720-2214-0000-0000-00005847D3E7 Message-Id: <1511816136-30068-3-git-send-email-walling@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-27_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711270279 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v1 2/5] s390-ccw: ipl structs for eckd cdl/ldl X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" ECKD DASDs have different IPL structures for CDL and LDL formats. The current Ipl1 and Ipl2 structs follow the CDL format, so we prepend "EckdCdl" to them. A new struct, EckdLdlIpl1 is introduced and contains boot info for LDL. Also introduce structs for IPL stages 1 and 1b and for disk geometry. Signed-off-by: Collin L. Walling Acked-by: Janosch Frank --- pc-bios/s390-ccw/bootmap.c | 24 ++++++++++---------- pc-bios/s390-ccw/bootmap.h | 55 +++++++++++++++++++++++++++++++++---------= ---- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index 6f8e30f..5546b79 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -221,9 +221,9 @@ static void run_eckd_boot_script(block_number_t mbr_blo= ck_nr) static void ipl_eckd_cdl(void) { XEckdMbr *mbr; - Ipl2 *ipl2 =3D (void *)sec; + EckdCdlIpl2 *ipl2 =3D (void *)sec; IplVolumeLabel *vlbl =3D (void *)sec; - block_number_t block_nr; + block_number_t mbr_block_nr; =20 /* we have just read the block #0 and recognized it as "IPL1" */ sclp_print("CDL\n"); @@ -231,7 +231,7 @@ static void ipl_eckd_cdl(void) memset(sec, FREE_SPACE_FILLER, sizeof(sec)); read_block(1, ipl2, "Cannot read IPL2 record at block 1"); =20 - mbr =3D &ipl2->u.x.mbr; + mbr =3D &ipl2->mbr; IPL_assert(magic_match(mbr, ZIPL_MAGIC), "No zIPL section in IPL2 reco= rd."); IPL_assert(block_size_ok(mbr->blockptr.xeckd.bptr.size), "Bad block size in zIPL section of IPL2 record."); @@ -239,7 +239,7 @@ static void ipl_eckd_cdl(void) "Non-ECKD device type in zIPL section of IPL2 record."); =20 /* save pointer to Boot Script */ - block_nr =3D eckd_block_num((void *)&(mbr->blockptr)); + mbr_block_nr =3D eckd_block_num((void *)&(mbr->blockptr)); =20 memset(sec, FREE_SPACE_FILLER, sizeof(sec)); read_block(2, vlbl, "Cannot read Volume Label at block 2"); @@ -249,7 +249,7 @@ static void ipl_eckd_cdl(void) "Invalid magic of volser block"); print_volser(vlbl->f.volser); =20 - run_eckd_boot_script(block_nr); + run_eckd_boot_script(mbr_block_nr); /* no return */ } =20 @@ -280,8 +280,8 @@ static void print_eckd_ldl_msg(ECKD_IPL_mode_t mode) =20 static void ipl_eckd_ldl(ECKD_IPL_mode_t mode) { - block_number_t block_nr; - BootInfo *bip =3D (void *)(sec + 0x70); /* BootInfo is MBR for LDL */ + block_number_t mbr_block_nr; + EckdLdlIpl1 *ipl1 =3D (void *)sec; =20 if (mode !=3D ECKD_LDL_UNLABELED) { print_eckd_ldl_msg(mode); @@ -292,15 +292,17 @@ static void ipl_eckd_ldl(ECKD_IPL_mode_t mode) memset(sec, FREE_SPACE_FILLER, sizeof(sec)); read_block(0, sec, "Cannot read block 0 to grab boot info."); if (mode =3D=3D ECKD_LDL_UNLABELED) { - if (!magic_match(bip->magic, ZIPL_MAGIC)) { + if (!magic_match(ipl1->boot_info.magic, ZIPL_MAGIC)) { return; /* not applicable layout */ } sclp_print("unlabeled LDL.\n"); } - verify_boot_info(bip); + verify_boot_info(&ipl1->boot_info); + + mbr_block_nr =3D + eckd_block_num((void *)&(ipl1->boot_info.bp.ipl.bm_ptr.eckd.bptr)); =20 - block_nr =3D eckd_block_num((void *)&(bip->bp.ipl.bm_ptr.eckd.bptr)); - run_eckd_boot_script(block_nr); + run_eckd_boot_script(mbr_block_nr); /* no return */ } =20 diff --git a/pc-bios/s390-ccw/bootmap.h b/pc-bios/s390-ccw/bootmap.h index 4980838..a2b4695 100644 --- a/pc-bios/s390-ccw/bootmap.h +++ b/pc-bios/s390-ccw/bootmap.h @@ -226,22 +226,47 @@ typedef struct BootInfo { /* @ 0x70, record = #0 */ } bp; } __attribute__ ((packed)) BootInfo; /* see also XEckdMbr */ =20 -typedef struct Ipl1 { - unsigned char key[4]; /* =3D=3D "IPL1" */ - unsigned char data[24]; -} __attribute__((packed)) Ipl1; +/* + * Structs for IPL + */ +#define STAGE2_BLK_CNT_MAX 24 /* Stage 1b can load up to 24 blocks */ =20 -typedef struct Ipl2 { - unsigned char key[4]; /* =3D=3D "IPL2" */ - union { - unsigned char data[144]; - struct { - unsigned char reserved1[92-4]; - XEckdMbr mbr; - unsigned char reserved2[144-(92-4)-sizeof(XEckdMbr)]; - } x; - } u; -} __attribute__((packed)) Ipl2; +typedef struct EckdCdlIpl1 { + uint8_t key[4]; /* =3D=3D "IPL1" */ + uint8_t data[24]; +} __attribute__((packed)) EckdCdlIpl1; + +typedef struct BootEckdSeekarg { + uint16_t pad; + uint16_t cyl; + uint16_t head; + uint8_t sec; + uint8_t pad2; +} __attribute__ ((packed)) BootEckdSeekarg; + +typedef struct BootEckdStage1b { + uint8_t reserved[32 * STAGE2_BLK_CNT_MAX]; + struct BootEckdSeekarg seek[STAGE2_BLK_CNT_MAX]; + uint8_t unused[64]; +} __attribute__ ((packed)) BootEckdStage1b; + +typedef struct BootEckdStage1 { + uint8_t reserved[72]; + struct BootEckdSeekarg seek[2]; +} __attribute__ ((packed)) BootEckdStage1; + +typedef struct EckdCdlIpl2 { + uint8_t key[4]; /* =3D=3D "IPL2" */ + struct BootEckdStage1 stage1; + XEckdMbr mbr; + uint8_t reserved2[24]; +} __attribute__((packed)) EckdCdlIpl2; + +typedef struct EckdLdlIpl1 { + uint8_t reserved[24]; + struct BootEckdStage1 stage1; + BootInfo boot_info; /* BootInfo is MBR for LDL */ +} __attribute__((packed)) EckdLdlIpl1; =20 typedef struct IplVolumeLabel { unsigned char key[4]; /* =3D=3D "VOL1" */ --=20 2.7.4 From nobody Mon Apr 29 08:59:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511816427676404.32152446148996; Mon, 27 Nov 2017 13:00:27 -0800 (PST) Received: from localhost ([::1]:34740 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJQVk-0006Zt-8I for importer@patchew.org; Mon, 27 Nov 2017 16:00:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJQRw-0003Wh-Fk for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eJQRt-0003Yy-9j for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:20 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:48168) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eJQRt-0003Vp-2L for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:17 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vARKsA4m034370 for ; Mon, 27 Nov 2017 15:56:13 -0500 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2egpygrsay-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Nov 2017 15:56:13 -0500 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Nov 2017 15:56:11 -0500 Received: from b01cxnp22034.gho.pok.ibm.com (9.57.198.24) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Nov 2017 15:56:10 -0500 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vARKuApv52559942; Mon, 27 Nov 2017 20:56:10 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2D6D62803A; Mon, 27 Nov 2017 15:55:37 -0500 (EST) Received: from collin-ThinkPad-W541.pok.ibm.com (unknown [9.56.58.42]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 2AD062804A; Mon, 27 Nov 2017 15:55:37 -0500 (EST) From: "Collin L. Walling" To: borntraeger@de.ibm.com, frankja@linux.vnet.ibm.com, qemu-s390x@nongnu.org, qemu-devel@nongnu.org Date: Mon, 27 Nov 2017 15:55:34 -0500 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511816136-30068-1-git-send-email-walling@linux.vnet.ibm.com> References: <1511816136-30068-1-git-send-email-walling@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112720-0008-0000-0000-000002A6F726 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008121; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000241; SDB=6.00952101; UDB=6.00480947; IPR=6.00732182; BA=6.00005715; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018212; XFM=3.00000015; UTC=2017-11-27 20:56:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112720-0009-0000-0000-0000376E6659 Message-Id: <1511816136-30068-4-git-send-email-walling@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-27_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711270279 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v1 3/5] s390-ccw: parse and set boot menu options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Set boot menu options for an s390 guest and store them in the iplb. These options are set via the QEMU command line option: -boot menu=3Don|off[,splash-time=3DX] or via the libvirt domain xml: Where X represents some positive integer representing milliseconds. Signed-off-by: Collin L. Walling Reviewed-by: Janosch Frank --- hw/s390x/ipl.c | 23 +++++++++++++++++++++++ hw/s390x/ipl.h | 8 ++++++-- pc-bios/s390-ccw/iplb.h | 8 ++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index 0d06fc1..0ca9e37 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -23,6 +23,8 @@ #include "hw/s390x/ebcdic.h" #include "ipl.h" #include "qemu/error-report.h" +#include "qemu/config-file.h" +#include "qemu/cutils.h" =20 #define KERN_IMAGE_START 0x010000UL #define KERN_PARM_AREA 0x010480UL @@ -219,6 +221,23 @@ static Property s390_ipl_properties[] =3D { DEFINE_PROP_END_OF_LIST(), }; =20 +static void s390_ipl_set_boot_menu(uint8_t *boot_menu_enabled, + uint16_t *boot_menu_timeout) +{ + QemuOptsList *plist =3D qemu_find_opts("boot-opts"); + QemuOpts *opts =3D QTAILQ_FIRST(&plist->head); + const char *p; + long result =3D 0; + + *boot_menu_enabled =3D qemu_opt_get_bool(opts, "menu", false); + + if (*boot_menu_enabled) { + p =3D qemu_opt_get(opts, "splash-time"); + qemu_strtol(p, NULL, 10, &result); + *boot_menu_timeout =3D result; + } +} + static bool s390_gen_initial_iplb(S390IPLState *ipl) { DeviceState *dev_st; @@ -245,6 +264,8 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl) ipl->iplb.pbt =3D S390_IPL_TYPE_CCW; ipl->iplb.ccw.devno =3D cpu_to_be16(ccw_dev->sch->devno); ipl->iplb.ccw.ssid =3D ccw_dev->sch->ssid & 3; + s390_ipl_set_boot_menu(&ipl->iplb.ccw.boot_menu_enabled, + &ipl->iplb.ccw.boot_menu_timeout); } else if (sd) { SCSIBus *bus =3D scsi_bus_from_device(sd); VirtIOSCSI *vdev =3D container_of(bus, VirtIOSCSI, bus); @@ -266,6 +287,8 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl) ipl->iplb.scsi.channel =3D cpu_to_be16(sd->channel); ipl->iplb.scsi.devno =3D cpu_to_be16(ccw_dev->sch->devno); ipl->iplb.scsi.ssid =3D ccw_dev->sch->ssid & 3; + s390_ipl_set_boot_menu(&ipl->iplb.scsi.boot_menu_enabled, + &ipl->iplb.scsi.boot_menu_timeout); } else { return false; /* unknown device */ } diff --git a/hw/s390x/ipl.h b/hw/s390x/ipl.h index 8a705e0..7c960b1 100644 --- a/hw/s390x/ipl.h +++ b/hw/s390x/ipl.h @@ -17,7 +17,9 @@ =20 struct IplBlockCcw { uint64_t netboot_start_addr; - uint8_t reserved0[77]; + uint8_t reserved0[74]; + uint8_t boot_menu_enabled; + uint16_t boot_menu_timeout; uint8_t ssid; uint16_t devno; uint8_t vm_flags; @@ -51,7 +53,9 @@ struct IplBlockQemuScsi { uint32_t lun; uint16_t target; uint16_t channel; - uint8_t reserved0[77]; + uint8_t reserved0[74]; + uint8_t boot_menu_enabled; + uint16_t boot_menu_timeout; uint8_t ssid; uint16_t devno; } QEMU_PACKED; diff --git a/pc-bios/s390-ccw/iplb.h b/pc-bios/s390-ccw/iplb.h index 890aed9..658d163 100644 --- a/pc-bios/s390-ccw/iplb.h +++ b/pc-bios/s390-ccw/iplb.h @@ -14,7 +14,9 @@ =20 struct IplBlockCcw { uint64_t netboot_start_addr; - uint8_t reserved0[77]; + uint8_t reserved0[74]; + uint8_t boot_menu_enabled; + uint16_t boot_menu_timeout; uint8_t ssid; uint16_t devno; uint8_t vm_flags; @@ -48,7 +50,9 @@ struct IplBlockQemuScsi { uint32_t lun; uint16_t target; uint16_t channel; - uint8_t reserved0[77]; + uint8_t reserved0[74]; + uint8_t boot_menu_enabled; + uint16_t boot_menu_timeout; uint8_t ssid; uint16_t devno; } __attribute__ ((packed)); --=20 2.7.4 From nobody Mon Apr 29 08:59:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511816526469656.8474563498444; Mon, 27 Nov 2017 13:02:06 -0800 (PST) Received: from localhost ([::1]:34762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJQXG-0007f5-Oa for importer@patchew.org; Mon, 27 Nov 2017 16:01:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJQRx-0003XP-2R for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eJQRs-0003WT-K2 for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:21 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49540) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eJQRs-0003Tw-B2 for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:16 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vARKs1V5002451 for ; Mon, 27 Nov 2017 15:56:14 -0500 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2egnukvjsj-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Nov 2017 15:56:13 -0500 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Nov 2017 15:56:12 -0500 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Nov 2017 15:56:10 -0500 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vARKuAZH46399588; Mon, 27 Nov 2017 20:56:10 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4495C28046; Mon, 27 Nov 2017 15:55:37 -0500 (EST) Received: from collin-ThinkPad-W541.pok.ibm.com (unknown [9.56.58.42]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 2DE792804C; Mon, 27 Nov 2017 15:55:37 -0500 (EST) From: "Collin L. Walling" To: borntraeger@de.ibm.com, frankja@linux.vnet.ibm.com, qemu-s390x@nongnu.org, qemu-devel@nongnu.org Date: Mon, 27 Nov 2017 15:55:35 -0500 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511816136-30068-1-git-send-email-walling@linux.vnet.ibm.com> References: <1511816136-30068-1-git-send-email-walling@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112720-2213-0000-0000-00000241FCC2 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008121; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000241; SDB=6.00952101; UDB=6.00480947; IPR=6.00732182; BA=6.00005715; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018212; XFM=3.00000015; UTC=2017-11-27 20:56:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112720-2214-0000-0000-00005847D3E9 Message-Id: <1511816136-30068-5-git-send-email-walling@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-27_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711270279 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v1 4/5] s390-ccw: interactive boot menu for eckd dasd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When the boot menu options are present and the guest's disk has been configured by the zipl tool, then the user will be presented with an interactive boot menu with labeled entries. An example of what the menu might look like: zIPL v1.37.1-build-20170714 interactive boot menu. 0. default (default) 1. default 2. performance 3. kvm Please choose (default will boot in 10 seconds): If the user's input is empty or 0, the default zipl entry will be chosen. If the input is within the range presented by the menu, then the selection will be booted. Any erroneous input will cancel the timeout and prompt the user until correct input is given. Any value set for loadparm will override all boot menu options. If loadparm=3DPROMPT, then the menu prompt will continuously wait until correct user input is given. Signed-off-by: Collin L. Walling --- pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/bootmap.c | 77 +++++++++++++++++++++++++- pc-bios/s390-ccw/bootmap.h | 2 + pc-bios/s390-ccw/main.c | 18 +++++- pc-bios/s390-ccw/menu.c | 108 ++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/s390-ccw.h | 6 ++ pc-bios/s390-ccw/sclp.c | 132 ++++++++++++++++++++++++++++++++++++++++= ++++ 7 files changed, 340 insertions(+), 5 deletions(-) create mode 100644 pc-bios/s390-ccw/menu.c diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile index 6d0c2ee..f03096b 100644 --- a/pc-bios/s390-ccw/Makefile +++ b/pc-bios/s390-ccw/Makefile @@ -9,7 +9,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/s390-ccw) =20 .PHONY : all clean build-all =20 -OBJECTS =3D start.o main.o bootmap.o sclp.o virtio.o virtio-scsi.o virtio-= blkdev.o +OBJECTS =3D start.o main.o bootmap.o sclp.o virtio.o virtio-scsi.o virtio-= blkdev.o menu.o QEMU_CFLAGS :=3D $(filter -W%, $(QEMU_CFLAGS)) QEMU_CFLAGS +=3D -ffreestanding -fno-delete-null-pointer-checks -msoft-flo= at QEMU_CFLAGS +=3D -march=3Dz900 -fPIE -fno-strict-aliasing diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index 5546b79..3aea6e0 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -28,6 +28,7 @@ =20 /* Scratch space */ static uint8_t sec[MAX_SECTOR_SIZE*4] __attribute__((__aligned__(PAGE_SIZE= ))); +static uint8_t s2_area[STAGE2_MAX_SIZE] __attribute__((__aligned__(PAGE_SI= ZE))); =20 typedef struct ResetInfo { uint32_t ipl_mask; @@ -182,7 +183,66 @@ static block_number_t load_eckd_segments(block_number_= t blk, uint64_t *address) return block_nr; } =20 -static void run_eckd_boot_script(block_number_t mbr_block_nr) +static block_number_t chs(const BootEckdSeekarg seek) +{ + /* we cannot have a sector of 0 */ + if (seek.sec =3D=3D 0) { + return 0; + } + + const uint64_t sectors =3D virtio_get_sectors(); + const uint64_t heads =3D virtio_get_heads(); + + return (seek.cyl * heads + seek.head) * sectors + (seek.sec - 1); +} + +static void read_stage2(block_number_t s1b_block_nr, void **stage2_data) +{ + block_number_t s2_block_nr; + BootEckdStage1b *s1b =3D (void *)sec; + int i; + + /* Get Stage1b data */ + memset(sec, FREE_SPACE_FILLER, sizeof(sec)); + read_block(s1b_block_nr, s1b, "Cannot read stage1b boot loader."); + + /* Get Stage2 data */ + *stage2_data =3D (void *)s2_area; + memset(s2_area, FREE_SPACE_FILLER, sizeof(s2_area)); + + for (i =3D 0; i < STAGE2_MAX_SIZE / MAX_SECTOR_SIZE; i++) { + s2_block_nr =3D chs(s1b->seek[i]); + if (!s2_block_nr) { + break; + } + read_block(s2_block_nr, (*stage2_data + MAX_SECTOR_SIZE * i), + "Error reading Stage2 data"); + } +} + +static int zipl_boot_menu(block_number_t s1b_block_nr) +{ + void *stage2_data, *menu_offset; + + read_stage2(s1b_block_nr, &stage2_data); + menu_offset =3D stage2_data; + + /* Menu banner starts with "zIPL" */ + while (menu_offset < stage2_data + STAGE2_MAX_SIZE - 4) { + if (magic_match(menu_offset, ZIPL_MAGIC_EBCDIC)) { + return menu_get_zipl_boot_index(menu_offset); + } + menu_offset++; + } + + panic("\n! No menu data found !\n"); + + /* should not reach here */ + return 0; +} + +static void run_eckd_boot_script(block_number_t mbr_block_nr, + block_number_t s1b_block_nr) { int i; unsigned int loadparm =3D get_loadparm_index(); @@ -191,6 +251,10 @@ static void run_eckd_boot_script(block_number_t mbr_bl= ock_nr) ScsiMbr *bte =3D (void *)sec; /* Eckd bootmap table entry */ BootMapScript *bms =3D (void *)sec; =20 + if (menu_is_enabled()) { + loadparm =3D zipl_boot_menu(s1b_block_nr); + } + debug_print_int("loadparm", loadparm); IPL_assert(loadparm < 31, "loadparm value greater than" " maximum number of boot entries allowed"); @@ -224,6 +288,7 @@ static void ipl_eckd_cdl(void) EckdCdlIpl2 *ipl2 =3D (void *)sec; IplVolumeLabel *vlbl =3D (void *)sec; block_number_t mbr_block_nr; + block_number_t s1b_block_nr; =20 /* we have just read the block #0 and recognized it as "IPL1" */ sclp_print("CDL\n"); @@ -241,6 +306,9 @@ static void ipl_eckd_cdl(void) /* save pointer to Boot Script */ mbr_block_nr =3D eckd_block_num((void *)&(mbr->blockptr)); =20 + /* save pointer to Stage1b Data */ + s1b_block_nr =3D chs(ipl2->stage1.seek[0]); + memset(sec, FREE_SPACE_FILLER, sizeof(sec)); read_block(2, vlbl, "Cannot read Volume Label at block 2"); IPL_assert(magic_match(vlbl->key, VOL1_MAGIC), @@ -249,7 +317,7 @@ static void ipl_eckd_cdl(void) "Invalid magic of volser block"); print_volser(vlbl->f.volser); =20 - run_eckd_boot_script(mbr_block_nr); + run_eckd_boot_script(mbr_block_nr, s1b_block_nr); /* no return */ } =20 @@ -281,6 +349,7 @@ static void print_eckd_ldl_msg(ECKD_IPL_mode_t mode) static void ipl_eckd_ldl(ECKD_IPL_mode_t mode) { block_number_t mbr_block_nr; + block_number_t s1b_block_nr; EckdLdlIpl1 *ipl1 =3D (void *)sec; =20 if (mode !=3D ECKD_LDL_UNLABELED) { @@ -302,7 +371,9 @@ static void ipl_eckd_ldl(ECKD_IPL_mode_t mode) mbr_block_nr =3D eckd_block_num((void *)&(ipl1->boot_info.bp.ipl.bm_ptr.eckd.bptr)); =20 - run_eckd_boot_script(mbr_block_nr); + s1b_block_nr =3D chs(ipl1->stage1.seek[0]); + + run_eckd_boot_script(mbr_block_nr, s1b_block_nr); /* no return */ } =20 diff --git a/pc-bios/s390-ccw/bootmap.h b/pc-bios/s390-ccw/bootmap.h index a2b4695..005be6c 100644 --- a/pc-bios/s390-ccw/bootmap.h +++ b/pc-bios/s390-ccw/bootmap.h @@ -74,6 +74,7 @@ typedef struct ScsiMbr { } __attribute__ ((packed)) ScsiMbr; =20 #define ZIPL_MAGIC "zIPL" +#define ZIPL_MAGIC_EBCDIC "\xa9\xc9\xd7\xd3" #define IPL1_MAGIC "\xc9\xd7\xd3\xf1" /* =3D=3D "IPL1" in EBCDIC */ #define IPL2_MAGIC "\xc9\xd7\xd3\xf2" /* =3D=3D "IPL2" in EBCDIC */ #define VOL1_MAGIC "\xe5\xd6\xd3\xf1" /* =3D=3D "VOL1" in EBCDIC */ @@ -229,6 +230,7 @@ typedef struct BootInfo { /* @ 0x70, record #0= */ /* * Structs for IPL */ +#define STAGE2_MAX_SIZE 0x3000 #define STAGE2_BLK_CNT_MAX 24 /* Stage 1b can load up to 24 blocks */ =20 typedef struct EckdCdlIpl1 { diff --git a/pc-bios/s390-ccw/main.c b/pc-bios/s390-ccw/main.c index a8ef120..fd2b16f 100644 --- a/pc-bios/s390-ccw/main.c +++ b/pc-bios/s390-ccw/main.c @@ -12,6 +12,9 @@ #include "s390-ccw.h" #include "virtio.h" =20 +#define LOADPARM_EMPTY "........" +#define LOADPARM_PROMPT "PROMPT " + char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE))); static SubChannelId blk_schid =3D { .one =3D 1 }; IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE))); @@ -73,6 +76,16 @@ static bool find_dev(Schib *schib, int dev_no) return false; } =20 +static void set_boot_menu(uint8_t boot_menu_enabled, + uint16_t boot_menu_timeout) +{ + if (memcmp(loadparm, LOADPARM_EMPTY, 8) =3D=3D 0 && boot_menu_enabled)= { + menu_enable(boot_menu_timeout); + } else if (memcmp(loadparm, LOADPARM_PROMPT, 8) =3D=3D 0) { + menu_enable(0); + } +} + static void virtio_setup(void) { Schib schib; @@ -101,6 +114,8 @@ static void virtio_setup(void) blk_schid.ssid =3D iplb.ccw.ssid & 0x3; debug_print_int("ssid ", blk_schid.ssid); found =3D find_dev(&schib, dev_no); + set_boot_menu(iplb.ccw.boot_menu_enabled, + iplb.ccw.boot_menu_timeout); break; case S390_IPL_TYPE_QEMU_SCSI: vdev->scsi_device_selected =3D true; @@ -109,6 +124,8 @@ static void virtio_setup(void) vdev->selected_scsi_device.lun =3D iplb.scsi.lun; blk_schid.ssid =3D iplb.scsi.ssid & 0x3; found =3D find_dev(&schib, iplb.scsi.devno); + set_boot_menu(iplb.scsi.boot_menu_enabled, + iplb.scsi.boot_menu_timeout); break; default: panic("List-directed IPL not supported yet!\n"); @@ -122,7 +139,6 @@ static void virtio_setup(void) } } } - IPL_assert(found, "No virtio device found"); =20 if (virtio_get_device_type() =3D=3D VIRTIO_ID_NET) { diff --git a/pc-bios/s390-ccw/menu.c b/pc-bios/s390-ccw/menu.c new file mode 100644 index 0000000..0bd0be6 --- /dev/null +++ b/pc-bios/s390-ccw/menu.c @@ -0,0 +1,108 @@ +/* + * QEMU S390 Boot Menu + * + * Copyright 2017 IBM Corp. + * Author: Collin L. Walling + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ + +#include "libc.h" +#include "s390-ccw.h" + +static bool enabled; +static uint64_t timeout; + +static int menu_read_index(uint64_t timeout) +{ + char *inp; + int len; + int i; + + len =3D sclp_read(&inp, timeout); + + if (len =3D=3D 0) { + return 0; + } + + for (i =3D 0; i < len; i++) { + if (!isdigit(inp[i])) { + return -1; + } + } + + return atoi(inp); +} + +static int menu_get_boot_index(int entries) +{ + char tmp[4]; + int boot_index; + + /* Prompt User */ + if (timeout > 0) { + sclp_print("Please choose (default will boot in "); + sclp_print(itostr(timeout / 1000, tmp)); + sclp_print(" seconds):\n"); + } else { + sclp_print("Please choose:\n"); + } + + /* Get Menu Choice */ + boot_index =3D menu_read_index(timeout); + + while (boot_index < 0 || boot_index >=3D entries) { + sclp_print("\nError: undefined configuration" + "\nPlease choose:\n"); + boot_index =3D menu_read_index(0); + } + + sclp_print("\nBooting entry #"); + sclp_print(itostr(boot_index, tmp)); + + return boot_index; +} + +static void menu_println(const char *data, size_t len) +{ + char buf[len + 1]; + + ebcdic_to_ascii(data, buf, len); + buf[len] =3D '\n'; + buf[len + 1] =3D '\0'; + + sclp_print(buf); +} + +int menu_get_zipl_boot_index(const char *data) +{ + size_t len; + int i; + + /* Print all menu items, including the banner */ + for (i =3D 0; *data !=3D '\0'; i++) { + len =3D strlen(data); + menu_println(data, len); + if (i < 2) { + sclp_print("\n"); + } + data +=3D len + 1; + } + + sclp_print("\n"); + + return menu_get_boot_index(i - 1); +} + +void menu_enable(uint16_t boot_menu_timeout) +{ + timeout =3D boot_menu_timeout; + enabled =3D true; +} + +bool menu_is_enabled(void) +{ + return enabled; +} diff --git a/pc-bios/s390-ccw/s390-ccw.h b/pc-bios/s390-ccw/s390-ccw.h index 25d4d21..3a9c873 100644 --- a/pc-bios/s390-ccw/s390-ccw.h +++ b/pc-bios/s390-ccw/s390-ccw.h @@ -71,6 +71,7 @@ unsigned int get_loadparm_index(void); void sclp_print(const char *string); void sclp_setup(void); void sclp_get_loadparm_ascii(char *loadparm); +int sclp_read(char **buf_ptr, uint64_t timeout); =20 /* virtio.c */ unsigned long virtio_load_direct(ulong rec_list1, ulong rec_list2, @@ -84,6 +85,11 @@ ulong get_second(void); /* bootmap.c */ void zipl_load(void); =20 +/* menu.c */ +void menu_enable(uint16_t boot_menu_timeout); +int menu_is_enabled(void); +int menu_get_zipl_boot_index(const char *data); + static inline void fill_hex(char *out, unsigned char val) { const char hex[] =3D "0123456789abcdef"; diff --git a/pc-bios/s390-ccw/sclp.c b/pc-bios/s390-ccw/sclp.c index 486fce1..af64743 100644 --- a/pc-bios/s390-ccw/sclp.c +++ b/pc-bios/s390-ccw/sclp.c @@ -12,6 +12,11 @@ #include "s390-ccw.h" #include "sclp.h" =20 +#define KEYCODE_NO_INP '\0' +#define KEYCODE_ARROWS '\033' +#define KEYCODE_BACKSP '\177' +#define KEYCODE_ENTER '\r' + long write(int fd, const void *str, size_t len); =20 static char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096))); @@ -101,3 +106,130 @@ void sclp_get_loadparm_ascii(char *loadparm) ebcdic_to_ascii((char *) sccb->loadparm, loadparm, 8); } } + +static void read(char **str) +{ + ReadEventData *sccb =3D (void *)_sccb; + *str =3D (char *)(&sccb->ebh) + 7; + + sccb->h.length =3D SCCB_SIZE; + sccb->h.function_code =3D SCLP_UNCONDITIONAL_READ; + sccb->ebh.length =3D sizeof(EventBufferHeader); + sccb->ebh.type =3D SCLP_EVENT_ASCII_CONSOLE_DATA; + sccb->ebh.flags =3D 0; + + sclp_service_call(SCLP_CMD_READ_EVENT_DATA, sccb); +} + +static inline void enable_clock_int(void) +{ + uint64_t tmp =3D 0; + + asm volatile( + "stctg 0,0,%0\n" + "oi 6+%0, 0x8\n" + "lctlg 0,0,%0" + : : "Q" (tmp) + ); +} + +static inline void disable_clock_int(void) +{ + uint64_t tmp =3D 0; + + asm volatile( + "stctg 0,0,%0\n" + "ni 6+%0, 0xf7\n" + "lctlg 0,0,%0" + : : "Q" (tmp) + ); +} + +static inline bool check_clock_int(void) +{ + uint16_t code; + + consume_sclp_int(); + + asm volatile( + "lh 1, 0x86(0,0)\n" + "sth 1, %0" + : "=3Dr" (code) + ); + + return code =3D=3D 0x1004; +} + +static inline void set_clock_comparator(uint64_t time) +{ + asm volatile("sckc %0" : : "Q" (time)); +} + +/* sclp_read + * + * Reads user input from the sclp console into a buffer. The buffer + * is set and the length is returned only if the enter key was detected. + * + * @param buf_ptr - a pointer to the buffer + * + * @param timeout - time (in milliseconds) to wait before abruptly + * ending user-input read loop. if 0, then loop + * until an enter key is detected + * + * @return - the length of the data in the buffer + */ +int sclp_read(char **buf_ptr, uint64_t timeout) +{ + char *inp =3D NULL; + char buf[255]; + uint8_t len =3D 0; + uint64_t seconds; + + memset(buf, 0, sizeof(buf)); + + if (timeout) { + seconds =3D get_second() + timeout / 1000; + set_clock_comparator((seconds * 1000000) << 12); + enable_clock_int(); + } + + while (!check_clock_int()) { + read(&inp); + + switch (inp[0]) { + case KEYCODE_NO_INP: + case KEYCODE_ARROWS: + continue; + case KEYCODE_BACKSP: + if (len > 0) { + len--; + + /* Remove last character */ + buf[len] =3D ' '; + write(1, "\r", 1); + write(1, buf, len + 1); + + /* Reset cursor */ + buf[len] =3D 0; + write(1, "\r", 1); + write(1, buf, len); + } + continue; + case KEYCODE_ENTER: + disable_clock_int(); + + *buf_ptr =3D buf; + return len; + } + + /* Echo input and add to buffer */ + if (len < sizeof(buf)) { + buf[len] =3D inp[0]; + len++; + write(1, inp, 1); + } + } + + disable_clock_int(); + return 0; +} --=20 2.7.4 From nobody Mon Apr 29 08:59:24 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511816311153291.9484273864431; Mon, 27 Nov 2017 12:58:31 -0800 (PST) Received: from localhost ([::1]:34731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJQTn-00059W-CR for importer@patchew.org; Mon, 27 Nov 2017 15:58:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJQRw-0003Wj-GP for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eJQRt-0003af-RO for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:20 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49148) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eJQRt-0003Xc-I7 for qemu-devel@nongnu.org; Mon, 27 Nov 2017 15:56:17 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vARKsdE4032795 for ; Mon, 27 Nov 2017 15:56:14 -0500 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0a-001b2d01.pphosted.com with ESMTP id 2egp6nuaq3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Nov 2017 15:56:13 -0500 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Nov 2017 15:56:12 -0500 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Nov 2017 15:56:10 -0500 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vARKuAG549414266; Mon, 27 Nov 2017 20:56:10 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 48F8428041; Mon, 27 Nov 2017 15:55:37 -0500 (EST) Received: from collin-ThinkPad-W541.pok.ibm.com (unknown [9.56.58.42]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 3B58A2803E; Mon, 27 Nov 2017 15:55:37 -0500 (EST) From: "Collin L. Walling" To: borntraeger@de.ibm.com, frankja@linux.vnet.ibm.com, qemu-s390x@nongnu.org, qemu-devel@nongnu.org Date: Mon, 27 Nov 2017 15:55:36 -0500 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511816136-30068-1-git-send-email-walling@linux.vnet.ibm.com> References: <1511816136-30068-1-git-send-email-walling@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112720-0036-0000-0000-000002929884 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008121; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000241; SDB=6.00952101; UDB=6.00480947; IPR=6.00732182; BA=6.00005715; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018212; XFM=3.00000015; UTC=2017-11-27 20:56:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112720-0037-0000-0000-000042812563 Message-Id: <1511816136-30068-6-git-send-email-walling@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-27_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711270279 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v1 5/5] s390-ccw: interactive boot menu for scsi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Interactive boot menu for scsi. This follows the same procedure as the interactive menu for eckd dasd. An example follows: s390x Enumerated Boot Menu. 3 entries detected. Select from index 0 to 2. Please choose: Signed-off-by: Collin L. Walling --- pc-bios/s390-ccw/bootmap.c | 9 ++++++--- pc-bios/s390-ccw/menu.c | 14 ++++++++++++++ pc-bios/s390-ccw/s390-ccw.h | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index 3aea6e0..a917e9d 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -558,15 +558,18 @@ static void ipl_scsi(void) } =20 program_table_entries++; - if (program_table_entries =3D=3D loadparm + 1) { - break; /* selected entry found */ - } } =20 debug_print_int("program table entries", program_table_entries); =20 IPL_assert(program_table_entries !=3D 0, "Empty Program Table"); =20 + if (menu_is_enabled()) { + loadparm =3D menu_get_enum_boot_index(program_table_entries); + } + + prog_table_entry =3D (ScsiBlockPtr *)(sec + pte_len * (loadparm + 1)); + zipl_run(prog_table_entry); /* no return */ } =20 diff --git a/pc-bios/s390-ccw/menu.c b/pc-bios/s390-ccw/menu.c index 0bd0be6..cb82d61 100644 --- a/pc-bios/s390-ccw/menu.c +++ b/pc-bios/s390-ccw/menu.c @@ -96,6 +96,20 @@ int menu_get_zipl_boot_index(const char *data) return menu_get_boot_index(i - 1); } =20 +int menu_get_enum_boot_index(int entries) +{ + char tmp[4]; + + sclp_print("s390x Enumerated Boot Menu.\n\n"); + + sclp_print(itostr(entries, tmp)); + sclp_print(" entries detected. Select from boot index 0 to "); + sclp_print(itostr(entries - 1, tmp)); + sclp_print(".\n\n"); + + return menu_get_boot_index(entries); +} + void menu_enable(uint16_t boot_menu_timeout) { timeout =3D boot_menu_timeout; diff --git a/pc-bios/s390-ccw/s390-ccw.h b/pc-bios/s390-ccw/s390-ccw.h index 3a9c873..1a410a6 100644 --- a/pc-bios/s390-ccw/s390-ccw.h +++ b/pc-bios/s390-ccw/s390-ccw.h @@ -89,6 +89,7 @@ void zipl_load(void); void menu_enable(uint16_t boot_menu_timeout); int menu_is_enabled(void); int menu_get_zipl_boot_index(const char *data); +int menu_get_enum_boot_index(int entries); =20 static inline void fill_hex(char *out, unsigned char val) { --=20 2.7.4