fdt_boot.c revision 1.1 1 1.1 skrll /* $NetBSD: fdt_boot.c,v 1.1 2023/04/22 09:53:45 skrll Exp $ */
2 1.1 skrll
3 1.1 skrll /*-
4 1.1 skrll * Copyright (c) 2015-2017 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1 skrll * All rights reserved.
6 1.1 skrll *
7 1.1 skrll * Redistribution and use in source and binary forms, with or without
8 1.1 skrll * modification, are permitted provided that the following conditions
9 1.1 skrll * are met:
10 1.1 skrll * 1. Redistributions of source code must retain the above copyright
11 1.1 skrll * notice, this list of conditions and the following disclaimer.
12 1.1 skrll * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 skrll * notice, this list of conditions and the following disclaimer in the
14 1.1 skrll * documentation and/or other materials provided with the distribution.
15 1.1 skrll *
16 1.1 skrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 skrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 skrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 skrll * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 skrll * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 skrll * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 skrll * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 skrll * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 skrll * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 skrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 skrll * SUCH DAMAGE.
27 1.1 skrll */
28 1.1 skrll
29 1.1 skrll /*-
30 1.1 skrll * Copyright (c) 2022 The NetBSD Foundation, Inc.
31 1.1 skrll * All rights reserved.
32 1.1 skrll *
33 1.1 skrll * This code is derived from software contributed to The NetBSD Foundation
34 1.1 skrll * by Nick Hudson
35 1.1 skrll *
36 1.1 skrll * Redistribution and use in source and binary forms, with or without
37 1.1 skrll * modification, are permitted provided that the following conditions
38 1.1 skrll * are met:
39 1.1 skrll * 1. Redistributions of source code must retain the above copyright
40 1.1 skrll * notice, this list of conditions and the following disclaimer.
41 1.1 skrll * 2. Redistributions in binary form must reproduce the above copyright
42 1.1 skrll * notice, this list of conditions and the following disclaimer in the
43 1.1 skrll * documentation and/or other materials provided with the distribution.
44 1.1 skrll *
45 1.1 skrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
46 1.1 skrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
47 1.1 skrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48 1.1 skrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
49 1.1 skrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50 1.1 skrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51 1.1 skrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52 1.1 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53 1.1 skrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 1.1 skrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55 1.1 skrll * POSSIBILITY OF SUCH DAMAGE.
56 1.1 skrll */
57 1.1 skrll
58 1.1 skrll #include <sys/cdefs.h>
59 1.1 skrll __KERNEL_RCSID(0, "$NetBSD: fdt_boot.c,v 1.1 2023/04/22 09:53:45 skrll Exp $");
60 1.1 skrll
61 1.1 skrll #include <sys/param.h>
62 1.1 skrll
63 1.1 skrll #include <sys/optstr.h>
64 1.1 skrll
65 1.1 skrll #include <libfdt.h>
66 1.1 skrll
67 1.1 skrll #include <dev/fdt/fdtvar.h>
68 1.1 skrll #include <dev/fdt/fdt_boot.h>
69 1.1 skrll
70 1.1 skrll void
71 1.1 skrll fdt_update_stdout_path(void *fdt, const char *boot_args)
72 1.1 skrll {
73 1.1 skrll const char *stdout_path;
74 1.1 skrll char buf[256];
75 1.1 skrll
76 1.1 skrll const int chosen_off = fdt_path_offset(fdt, "/chosen");
77 1.1 skrll if (chosen_off == -1)
78 1.1 skrll return;
79 1.1 skrll
80 1.1 skrll if (optstr_get_string(boot_args, "stdout-path", &stdout_path) == false)
81 1.1 skrll return;
82 1.1 skrll
83 1.1 skrll const char *ep = strchr(stdout_path, ' ');
84 1.1 skrll size_t stdout_path_len = ep ? (ep - stdout_path) : strlen(stdout_path);
85 1.1 skrll if (stdout_path_len >= sizeof(buf))
86 1.1 skrll return;
87 1.1 skrll
88 1.1 skrll strncpy(buf, stdout_path, stdout_path_len);
89 1.1 skrll buf[stdout_path_len] = '\0';
90 1.1 skrll fdt_setprop(fdt, chosen_off, "stdout-path",
91 1.1 skrll buf, stdout_path_len + 1);
92 1.1 skrll }
93