Commit eeaef5e4305497537bd47308724de39c7d6cbf19
Committed by
Tom Rini
1 parent
041bca5ba3
Exists in
master
and in
53 other branches
cmd_bootm: Add command line arguments to Plan 9
This patch introduces support for command line arguments to Plan 9. Plan 9 generally dedicates a small region of kernel memory (known as CONFADDR) for runtime configuration. A new environment variable named confaddr was introduced to indicate this location when copying arguments. Signed-off-by: Steven Stallion <sstallion@gmail.com> [trini: Adapt for Simon's changes about correcting argc, no need to bump by 2 now] Signed-off-by: Tom Rini <trini@ti.com>
Showing 2 changed files with 47 additions and 7 deletions Side-by-side Diff
common/cmd_bootm.c
... | ... | @@ -1393,7 +1393,20 @@ |
1393 | 1393 | } |
1394 | 1394 | #endif /* CONFIG_SILENT_CONSOLE */ |
1395 | 1395 | |
1396 | +#if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9) | |
1397 | +static void copy_args(char *dest, int argc, char * const argv[], char delim) | |
1398 | +{ | |
1399 | + int i; | |
1396 | 1400 | |
1401 | + for (i = 0; i < argc; i++) { | |
1402 | + if (i > 0) | |
1403 | + *dest++ = delim; | |
1404 | + strcpy(dest, argv[i]); | |
1405 | + dest += strlen(argv[i]); | |
1406 | + } | |
1407 | +} | |
1408 | +#endif | |
1409 | + | |
1397 | 1410 | /*******************************************************************/ |
1398 | 1411 | /* OS booting routines */ |
1399 | 1412 | /*******************************************************************/ |
... | ... | @@ -1455,13 +1468,7 @@ |
1455 | 1468 | for (i = 0, len = 0; i < argc; i += 1) |
1456 | 1469 | len += strlen(argv[i]) + 1; |
1457 | 1470 | cmdline = malloc(len); |
1458 | - | |
1459 | - for (i = 0, len = 0; i < argc; i += 1) { | |
1460 | - if (i > 0) | |
1461 | - cmdline[len++] = ' '; | |
1462 | - strcpy(&cmdline[len], argv[i]); | |
1463 | - len += strlen(argv[i]); | |
1464 | - } | |
1471 | + copy_args(cmdline, argc, argv, ' '); | |
1465 | 1472 | } else if ((cmdline = getenv("bootargs")) == NULL) { |
1466 | 1473 | cmdline = ""; |
1467 | 1474 | } |
... | ... | @@ -1580,6 +1587,7 @@ |
1580 | 1587 | bootm_headers_t *images) |
1581 | 1588 | { |
1582 | 1589 | void (*entry_point)(void); |
1590 | + char *s; | |
1583 | 1591 | |
1584 | 1592 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
1585 | 1593 | return 1; |
... | ... | @@ -1590,6 +1598,20 @@ |
1590 | 1598 | return 1; |
1591 | 1599 | } |
1592 | 1600 | #endif |
1601 | + | |
1602 | + /* See README.plan9 */ | |
1603 | + s = getenv("confaddr"); | |
1604 | + if (s != NULL) { | |
1605 | + char *confaddr = (char *)simple_strtoul(s, NULL, 16); | |
1606 | + | |
1607 | + if (argc > 0) { | |
1608 | + copy_args(confaddr, argc, argv, '\n'); | |
1609 | + } else { | |
1610 | + s = getenv("bootargs"); | |
1611 | + if (s != NULL) | |
1612 | + strcpy(confaddr, s); | |
1613 | + } | |
1614 | + } | |
1593 | 1615 | |
1594 | 1616 | entry_point = (void (*)(void))images->ep; |
1595 | 1617 |
doc/README.plan9
1 | +Plan 9 from Bell Labs kernel images require additional setup to pass | |
2 | +configuration information to the kernel. An environment variable named | |
3 | +confaddr must be defined with the same value as CONFADDR (see mem.h). | |
4 | +Use of this facility is optional, but should be preferable to manual | |
5 | +configuration. | |
6 | + | |
7 | +When booting an image, arguments supplied to the bootm command will be | |
8 | +copied to CONFADDR. If no arguments are specified, the contents of the | |
9 | +bootargs environment variable will be copied. | |
10 | + | |
11 | +If no command line arguments or bootargs are defined, CONFADDR is left | |
12 | +uninitialized to permit manual configuration. For example, PC-style | |
13 | +configuration could be simulated by issuing a fatload in bootcmd: | |
14 | + | |
15 | + # setenv bootcmd fatload mmc 0 $confaddr plan9.ini; ...; bootm | |
16 | + | |
17 | +Steven Stallion | |
18 | +June 2013 |