18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * bootstr.c: Boot string/argument acquisition from the PROM. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright(C) 1995 David S. Miller (davem@caip.rutgers.edu) 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/string.h> 98c2ecf20Sopenharmony_ci#include <asm/oplib.h> 108c2ecf20Sopenharmony_ci#include <linux/init.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#define BARG_LEN 256 138c2ecf20Sopenharmony_cistatic char barg_buf[BARG_LEN] = { 0 }; 148c2ecf20Sopenharmony_cistatic char fetched __initdata = 0; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cichar * __init 178c2ecf20Sopenharmony_ciprom_getbootargs(void) 188c2ecf20Sopenharmony_ci{ 198c2ecf20Sopenharmony_ci int iter; 208c2ecf20Sopenharmony_ci char *cp, *arg; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci /* This check saves us from a panic when bootfd patches args. */ 238c2ecf20Sopenharmony_ci if (fetched) { 248c2ecf20Sopenharmony_ci return barg_buf; 258c2ecf20Sopenharmony_ci } 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci switch (prom_vers) { 288c2ecf20Sopenharmony_ci case PROM_V0: 298c2ecf20Sopenharmony_ci cp = barg_buf; 308c2ecf20Sopenharmony_ci /* Start from 1 and go over fd(0,0,0)kernel */ 318c2ecf20Sopenharmony_ci for (iter = 1; iter < 8; iter++) { 328c2ecf20Sopenharmony_ci arg = (*(romvec->pv_v0bootargs))->argv[iter]; 338c2ecf20Sopenharmony_ci if (arg == NULL) 348c2ecf20Sopenharmony_ci break; 358c2ecf20Sopenharmony_ci while (*arg != 0) { 368c2ecf20Sopenharmony_ci /* Leave place for space and null. */ 378c2ecf20Sopenharmony_ci if (cp >= barg_buf + BARG_LEN - 2) 388c2ecf20Sopenharmony_ci /* We might issue a warning here. */ 398c2ecf20Sopenharmony_ci break; 408c2ecf20Sopenharmony_ci *cp++ = *arg++; 418c2ecf20Sopenharmony_ci } 428c2ecf20Sopenharmony_ci *cp++ = ' '; 438c2ecf20Sopenharmony_ci if (cp >= barg_buf + BARG_LEN - 1) 448c2ecf20Sopenharmony_ci /* We might issue a warning here. */ 458c2ecf20Sopenharmony_ci break; 468c2ecf20Sopenharmony_ci } 478c2ecf20Sopenharmony_ci *cp = 0; 488c2ecf20Sopenharmony_ci break; 498c2ecf20Sopenharmony_ci case PROM_V2: 508c2ecf20Sopenharmony_ci case PROM_V3: 518c2ecf20Sopenharmony_ci /* 528c2ecf20Sopenharmony_ci * V3 PROM cannot supply as with more than 128 bytes 538c2ecf20Sopenharmony_ci * of an argument. But a smart bootstrap loader can. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ci strlcpy(barg_buf, *romvec->pv_v2bootargs.bootargs, sizeof(barg_buf)); 568c2ecf20Sopenharmony_ci break; 578c2ecf20Sopenharmony_ci default: 588c2ecf20Sopenharmony_ci break; 598c2ecf20Sopenharmony_ci } 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci fetched = 1; 628c2ecf20Sopenharmony_ci return barg_buf; 638c2ecf20Sopenharmony_ci} 64