Wed Jan 29 19:04:41 2020 UTC ()
Do not compare a char array to NULL, test for empty string instead.


(martin)
diff -r1.14 -r1.15 src/usr.sbin/sysinst/arch/evbarm/md.c

cvs diff -r1.14 -r1.15 src/usr.sbin/sysinst/arch/evbarm/md.c (switch to unified diff)

--- src/usr.sbin/sysinst/arch/evbarm/md.c 2020/01/27 21:21:22 1.14
+++ src/usr.sbin/sysinst/arch/evbarm/md.c 2020/01/29 19:04:40 1.15
@@ -1,362 +1,362 @@ @@ -1,362 +1,362 @@
1/* $NetBSD: md.c,v 1.14 2020/01/27 21:21:22 martin Exp $ */ 1/* $NetBSD: md.c,v 1.15 2020/01/29 19:04:40 martin Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 Piermont Information Systems Inc. 4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Based on code written by Philip A. Nelson for Piermont Information 7 * Based on code written by Philip A. Nelson for Piermont Information
8 * Systems Inc. 8 * Systems Inc.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of Piermont Information Systems Inc. may not be used to endorse 18 * 3. The name of Piermont Information Systems Inc. may not be used to endorse
19 * or promote products derived from this software without specific prior 19 * or promote products derived from this software without specific prior
20 * written permission. 20 * written permission.
21 * 21 *
22 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 22 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE 25 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE. 32 * THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35/* md.c -- shark machine specific routines */ 35/* md.c -- shark machine specific routines */
36 36
37#include <stdio.h> 37#include <stdio.h>
38#include <curses.h> 38#include <curses.h>
39#include <unistd.h> 39#include <unistd.h>
40#include <fcntl.h> 40#include <fcntl.h>
41#include <util.h> 41#include <util.h>
42#include <sys/types.h> 42#include <sys/types.h>
43#include <sys/ioctl.h> 43#include <sys/ioctl.h>
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/sysctl.h> 45#include <sys/sysctl.h>
46 46
47#include "defs.h" 47#include "defs.h"
48#include "md.h" 48#include "md.h"
49#include "msg_defs.h" 49#include "msg_defs.h"
50#include "menu_defs.h" 50#include "menu_defs.h"
51 51
52int boardtype = BOARD_TYPE_NORMAL; 52int boardtype = BOARD_TYPE_NORMAL;
53 53
54#define SBSA_MODEL_STR "netbsd,generic-acpi" 54#define SBSA_MODEL_STR "netbsd,generic-acpi"
55#define RPI_MODEL_STR "raspberrypi," 55#define RPI_MODEL_STR "raspberrypi,"
56 56
57void 57void
58md_init(void) 58md_init(void)
59{ 59{
60 static const int mib[2] = {CTL_HW, HW_MODEL}; 60 static const int mib[2] = {CTL_HW, HW_MODEL};
61 size_t len; 61 size_t len;
62 char *cpu_model; 62 char *cpu_model;
63 63
64 sysctl(mib, 2, NULL, &len, NULL, 0); 64 sysctl(mib, 2, NULL, &len, NULL, 0);
65 cpu_model = malloc(len); 65 cpu_model = malloc(len);
66 sysctl(mib, 2, cpu_model, &len, NULL, 0); 66 sysctl(mib, 2, cpu_model, &len, NULL, 0);
67 67
68 if (strstr(cpu_model, RPI_MODEL_STR) != NULL) 68 if (strstr(cpu_model, RPI_MODEL_STR) != NULL)
69 /* this is some kind of Raspberry Pi */ 69 /* this is some kind of Raspberry Pi */
70 boardtype = BOARD_TYPE_RPI; 70 boardtype = BOARD_TYPE_RPI;
71 else if (strstr(cpu_model, SBSA_MODEL_STR) != NULL) 71 else if (strstr(cpu_model, SBSA_MODEL_STR) != NULL)
72 /* some SBSA compatible machine */ 72 /* some SBSA compatible machine */
73 boardtype = BOARD_TYPE_ACPI; 73 boardtype = BOARD_TYPE_ACPI;
74 else 74 else
75 /* unknown, assume u-boot + dtb */ 75 /* unknown, assume u-boot + dtb */
76 boardtype = BOARD_TYPE_NORMAL; 76 boardtype = BOARD_TYPE_NORMAL;
77 77
78 free(cpu_model); 78 free(cpu_model);
79} 79}
80 80
81void 81void
82md_init_set_status(int flags) 82md_init_set_status(int flags)
83{ 83{
84 84
85 /* 85 /*
86 * we will extract kernel variants and DTB files piecwise 86 * we will extract kernel variants and DTB files piecwise
87 * manually later, just fetch the kernel set, do not 87 * manually later, just fetch the kernel set, do not
88 * unpack it. 88 * unpack it.
89 */ 89 */
90 set_noextract_set(SET_KERNEL_1); 90 set_noextract_set(SET_KERNEL_1);
91} 91}
92 92
93bool 93bool
94md_get_info(struct install_partition_desc *install) 94md_get_info(struct install_partition_desc *install)
95{ 95{
96 96
97 if (pm->no_mbr || pm->no_part) 97 if (pm->no_mbr || pm->no_part)
98 return true; 98 return true;
99 99
100 if (pm->parts == NULL) { 100 if (pm->parts == NULL) {
101 101
102 const struct disk_partitioning_scheme *ps = 102 const struct disk_partitioning_scheme *ps =
103 select_part_scheme(pm, NULL, true, NULL); 103 select_part_scheme(pm, NULL, true, NULL);
104 104
105 if (!ps) 105 if (!ps)
106 return false; 106 return false;
107 107
108 struct disk_partitions *parts = 108 struct disk_partitions *parts =
109 (*ps->create_new_for_disk)(pm->diskdev, 109 (*ps->create_new_for_disk)(pm->diskdev,
110 0, pm->dlsize, true, NULL); 110 0, pm->dlsize, true, NULL);
111 if (!parts) 111 if (!parts)
112 return false; 112 return false;
113 113
114 pm->parts = parts; 114 pm->parts = parts;
115 if (ps->size_limit > 0 && pm->dlsize > ps->size_limit) 115 if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
116 pm->dlsize = ps->size_limit; 116 pm->dlsize = ps->size_limit;
117 } 117 }
118 118
119 return edit_outer_parts(pm->parts); 119 return edit_outer_parts(pm->parts);
120} 120}
121 121
122/* 122/*
123 * md back-end code for menu-driven BSD disklabel editor. 123 * md back-end code for menu-driven BSD disklabel editor.
124 */ 124 */
125bool 125bool
126md_make_bsd_partitions(struct install_partition_desc *install) 126md_make_bsd_partitions(struct install_partition_desc *install)
127{ 127{
128 return make_bsd_partitions(install); 128 return make_bsd_partitions(install);
129} 129}
130 130
131/* 131/*
132 * any additional partition validation 132 * any additional partition validation
133 */ 133 */
134bool 134bool
135md_check_partitions(struct install_partition_desc *install) 135md_check_partitions(struct install_partition_desc *install)
136{ 136{
137 size_t i; 137 size_t i;
138 138
139 for (i = 0; i < install->num; i++) 139 for (i = 0; i < install->num; i++)
140 if (install->infos[i].fs_type == FS_MSDOS) 140 if (install->infos[i].fs_type == FS_MSDOS)
141 return true; 141 return true;
142 142
143 msg_display(MSG_nomsdospart); 143 msg_display(MSG_nomsdospart);
144 process_menu(MENU_ok, NULL); 144 process_menu(MENU_ok, NULL);
145 145
146 return false; 146 return false;
147} 147}
148 148
149/* 149/*
150 * hook called before writing new disklabel. 150 * hook called before writing new disklabel.
151 */ 151 */
152bool 152bool
153md_pre_disklabel(struct install_partition_desc *install, 153md_pre_disklabel(struct install_partition_desc *install,
154 struct disk_partitions *parts) 154 struct disk_partitions *parts)
155{ 155{
156 156
157 if (parts->parent == NULL) 157 if (parts->parent == NULL)
158 return true; /* no outer partitions */ 158 return true; /* no outer partitions */
159 159
160 parts = parts->parent; 160 parts = parts->parent;
161 161
162 msg_display_subst(MSG_dofdisk, 3, parts->disk, 162 msg_display_subst(MSG_dofdisk, 3, parts->disk,
163 msg_string(parts->pscheme->name), 163 msg_string(parts->pscheme->name),
164 msg_string(parts->pscheme->short_name)); 164 msg_string(parts->pscheme->short_name));
165 165
166 /* write edited "MBR" onto disk. */ 166 /* write edited "MBR" onto disk. */
167 if (!parts->pscheme->write_to_disk(parts)) { 167 if (!parts->pscheme->write_to_disk(parts)) {
168 msg_display(MSG_wmbrfail); 168 msg_display(MSG_wmbrfail);
169 process_menu(MENU_ok, NULL); 169 process_menu(MENU_ok, NULL);
170 return false; 170 return false;
171 } 171 }
172 return true; 172 return true;
173} 173}
174 174
175/* 175/*
176 * hook called after writing disklabel to new target disk. 176 * hook called after writing disklabel to new target disk.
177 */ 177 */
178bool 178bool
179md_post_disklabel(struct install_partition_desc *install, 179md_post_disklabel(struct install_partition_desc *install,
180 struct disk_partitions *parts) 180 struct disk_partitions *parts)
181{ 181{
182 return true; 182 return true;
183} 183}
184 184
185/* 185/*
186 * hook called after upgrade() or install() has finished setting 186 * hook called after upgrade() or install() has finished setting
187 * up the target disk but immediately before the user is given the 187 * up the target disk but immediately before the user is given the
188 * ``disks are now set up'' message. 188 * ``disks are now set up'' message.
189 */ 189 */
190int 190int
191md_post_newfs(struct install_partition_desc *install) 191md_post_newfs(struct install_partition_desc *install)
192{ 192{
193 return 0; 193 return 0;
194} 194}
195 195
196int 196int
197evbarm_extract_finalize(int update) 197evbarm_extract_finalize(int update)
198{ 198{
199 distinfo *dist; 199 distinfo *dist;
200 char kernelbin[100]; 200 char kernelbin[100];
201 int (*saved_fetch_fn)(const char *); 201 int (*saved_fetch_fn)(const char *);
202#ifdef _LP64 202#ifdef _LP64
203#define EFIBOOT "/usr/mdec/bootaa64.efi" 203#define EFIBOOT "/usr/mdec/bootaa64.efi"
204#else 204#else
205#define EFIBOOT "/usr/mdec/bootarm.efi" 205#define EFIBOOT "/usr/mdec/bootarm.efi"
206#endif 206#endif
207 207
208 dist = get_set_distinfo(SET_KERNEL_1); 208 dist = get_set_distinfo(SET_KERNEL_1);
209 if (dist == NULL) 209 if (dist == NULL)
210 return 0; 210 return 0;
211 211
212 saved_fetch_fn = fetch_fn; 212 saved_fetch_fn = fetch_fn;
213 extract_file_to(dist, false, "/", "./netbsd", false); 213 extract_file_to(dist, false, "/", "./netbsd", false);
214 fetch_fn = NULL; 214 fetch_fn = NULL;
215 make_target_dir("/boot/EFI/boot"); 215 make_target_dir("/boot/EFI/boot");
216 if (target_file_exists_p(EFIBOOT)) 216 if (target_file_exists_p(EFIBOOT))
217 cp_within_target(EFIBOOT, "/boot/EFI/boot", 0); 217 cp_within_target(EFIBOOT, "/boot/EFI/boot", 0);
218 218
219 if (boardtype == BOARD_TYPE_ACPI) { 219 if (boardtype == BOARD_TYPE_ACPI) {
220 fetch_fn = saved_fetch_fn; 220 fetch_fn = saved_fetch_fn;
221 return 0; 221 return 0;
222 } 222 }
223 if (boardtype == BOARD_TYPE_NORMAL) { 223 if (boardtype == BOARD_TYPE_NORMAL) {
224 make_target_dir("/boot/dtb"); 224 make_target_dir("/boot/dtb");
225 extract_file_to(dist, false, "/boot/dtb", "*.dt*", false); 225 extract_file_to(dist, false, "/boot/dtb", "*.dt*", false);
226 extract_file_to(dist, false, "/boot", "./netbsd.ub", false); 226 extract_file_to(dist, false, "/boot", "./netbsd.ub", false);
227 fetch_fn = saved_fetch_fn; 227 fetch_fn = saved_fetch_fn;
228 return 0; 228 return 0;
229 } 229 }
230 if (boardtype == BOARD_TYPE_RPI) { 230 if (boardtype == BOARD_TYPE_RPI) {
231 extract_file_to(dist, false, "/boot", "./netbsd.img", false); 231 extract_file_to(dist, false, "/boot", "./netbsd.img", false);
232 extract_file_to(dist, false, "/boot", "./bcm*.dtb", false); 232 extract_file_to(dist, false, "/boot", "./bcm*.dtb", false);
233 fetch_fn = saved_fetch_fn; 233 fetch_fn = saved_fetch_fn;
234 snprintf(kernelbin, 100, "%s/netbsd.img", targetroot_mnt); 234 snprintf(kernelbin, 100, "%s/netbsd.img", targetroot_mnt);
235 if (file_exists_p(kernelbin)) { 235 if (file_exists_p(kernelbin)) {
236 run_program(RUN_DISPLAY, 236 run_program(RUN_DISPLAY,
237 "/bin/cp %s /targetroot/boot/kernel.img", kernelbin); 237 "/bin/cp %s /targetroot/boot/kernel.img", kernelbin);
238 } else { 238 } else {
239 msg_display(MSG_rpikernelmissing); 239 msg_display(MSG_rpikernelmissing);
240 process_menu(MENU_ok, NULL); 240 process_menu(MENU_ok, NULL);
241 return 1; 241 return 1;
242 } 242 }
243 } 243 }
244 fetch_fn = saved_fetch_fn; 244 fetch_fn = saved_fetch_fn;
245 return 0; 245 return 0;
246} 246}
247 247
248int 248int
249md_post_extract(struct install_partition_desc *install) 249md_post_extract(struct install_partition_desc *install)
250{ 250{
251 251
252 return 0; 252 return 0;
253} 253}
254 254
255void 255void
256md_cleanup_install(struct install_partition_desc *install) 256md_cleanup_install(struct install_partition_desc *install)
257{ 257{
258#ifndef DEBUG 258#ifndef DEBUG
259 enable_rc_conf(); 259 enable_rc_conf();
260 add_rc_conf("sshd=YES\n"); 260 add_rc_conf("sshd=YES\n");
261 add_rc_conf("dhcpcd=YES\n"); 261 add_rc_conf("dhcpcd=YES\n");
262#endif 262#endif
263} 263}
264 264
265int 265int
266md_pre_update(struct install_partition_desc *install) 266md_pre_update(struct install_partition_desc *install)
267{ 267{
268 return 1; 268 return 1;
269} 269}
270 270
271/* Upgrade support */ 271/* Upgrade support */
272int 272int
273md_update(struct install_partition_desc *install) 273md_update(struct install_partition_desc *install)
274{ 274{
275 md_post_newfs(install); 275 md_post_newfs(install);
276 return 1; 276 return 1;
277} 277}
278 278
279int 279int
280md_pre_mount(struct install_partition_desc *install, size_t ndx) 280md_pre_mount(struct install_partition_desc *install, size_t ndx)
281{ 281{
282 return 0; 282 return 0;
283} 283}
284 284
285int 285int
286md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet) 286md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
287{ 287{
288 mbr_info_t *ext; 288 mbr_info_t *ext;
289 struct mbr_partition *part; 289 struct mbr_partition *part;
290 int i, hasboot=0; 290 int i, hasboot=0;
291 291
292 for (ext = mbri; ext; ext = ext->extended) { 292 for (ext = mbri; ext; ext = ext->extended) {
293 part = ext->mbr.mbr_parts; 293 part = ext->mbr.mbr_parts;
294 for (i=0, hasboot=0; i < MBR_PART_COUNT; part++, i++) { 294 for (i=0, hasboot=0; i < MBR_PART_COUNT; part++, i++) {
295 if (part->mbrp_type != MBR_PTYPE_FAT16L && 295 if (part->mbrp_type != MBR_PTYPE_FAT16L &&
296 part->mbrp_type != MBR_PTYPE_FAT32L) 296 part->mbrp_type != MBR_PTYPE_FAT32L)
297 continue; 297 continue;
298 hasboot = 1; 298 hasboot = 1;
299 break; 299 break;
300 } 300 }
301 } 301 }
302 if (!hasboot) { 302 if (!hasboot) {
303 if (quiet) 303 if (quiet)
304 return 2; 304 return 2;
305 msg_display(MSG_nomsdospart); 305 msg_display(MSG_nomsdospart);
306 return ask_reedit(parts); 306 return ask_reedit(parts);
307 } 307 }
308 308
309 return 2; 309 return 2;
310} 310}
311 311
312bool 312bool
313md_parts_use_wholedisk(struct disk_partitions *parts) 313md_parts_use_wholedisk(struct disk_partitions *parts)
314{ 314{
315 struct disk_part_info boot_part = { 315 struct disk_part_info boot_part = {
316 .size = boardtype == BOARD_TYPE_NORMAL ?  316 .size = boardtype == BOARD_TYPE_NORMAL ?
317 PART_BOOT_LARGE/512 : PART_BOOT/512, 317 PART_BOOT_LARGE/512 : PART_BOOT/512,
318 .fs_type = PART_BOOT_TYPE, .fs_sub_type = MBR_PTYPE_FAT16L, 318 .fs_type = PART_BOOT_TYPE, .fs_sub_type = MBR_PTYPE_FAT16L,
319 }; 319 };
320 320
321 return parts_use_wholedisk(parts, 1, &boot_part); 321 return parts_use_wholedisk(parts, 1, &boot_part);
322} 322}
323 323
324/* returns false if no write-back of parts is required */ 324/* returns false if no write-back of parts is required */
325bool 325bool
326md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri) 326md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
327{ 327{
328 return false; 328 return false;
329} 329}
330 330
331#ifdef HAVE_GPT 331#ifdef HAVE_GPT
332/* 332/*
333 * New GPT partitions have been written, update bootloader or remember 333 * New GPT partitions have been written, update bootloader or remember
334 * data untill needed in md_post_newfs 334 * data untill needed in md_post_newfs
335 */ 335 */
336bool 336bool
337md_gpt_post_write(struct disk_partitions *parts, part_id root_id, 337md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
338 bool root_is_new, part_id efi_id, bool efi_is_new) 338 bool root_is_new, part_id efi_id, bool efi_is_new)
339{ 339{
340 return true; 340 return true;
341} 341}
342#endif 342#endif
343 343
344void 344void
345evbarm_part_defaults(struct pm_devs *my_pm, struct part_usage_info *infos, 345evbarm_part_defaults(struct pm_devs *my_pm, struct part_usage_info *infos,
346 size_t num_usage_infos) 346 size_t num_usage_infos)
347{ 347{
348 size_t i; 348 size_t i;
349 349
350 if (boardtype != BOARD_TYPE_NORMAL) 350 if (boardtype != BOARD_TYPE_NORMAL)
351 return; 351 return;
352 352
353 for (i = 0; i < num_usage_infos; i++) { 353 for (i = 0; i < num_usage_infos; i++) {
354 if (infos[i].fs_type == PART_BOOT_TYPE && 354 if (infos[i].fs_type == PART_BOOT_TYPE &&
355 infos[i].mount != NULL && 355 infos[i].mount[0] != 0 &&
356 strcmp(infos[i].mount, PART_BOOT_MOUNT) == 0) { 356 strcmp(infos[i].mount, PART_BOOT_MOUNT) == 0) {
357 infos[i].size = PART_BOOT_LARGE; 357 infos[i].size = PART_BOOT_LARGE;
358 return; 358 return;
359 } 359 }
360 } 360 }
361} 361}
362 362