wok rev 20333

linux: read default cmdline from EFI\BOOT\linux.cmdline
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jun 02 13:53:27 2018 +0200 (2018-06-02)
parents f582dbc28a10
children 02ed2446b480
files linux/receipt linux/stuff/linux-efi.u
line diff
     1.1 --- a/linux/receipt	Wed May 30 11:10:35 2018 +0200
     1.2 +++ b/linux/receipt	Sat Jun 02 13:53:27 2018 +0200
     1.3 @@ -222,6 +222,7 @@
     1.4  $PACKAGE-subroot.u
     1.5  $PACKAGE-romfs.u
     1.6  $PACKAGE-tcp_stealth.u
     1.7 +$PACKAGE-efi.u
     1.8  aufs3-base.patch
     1.9  aufs3-standalone.patch
    1.10  aufs3-loopback.patch
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/linux/stuff/linux-efi.u	Sat Jun 02 13:53:27 2018 +0200
     2.3 @@ -0,0 +1,187 @@
     2.4 +--- linux-3.16.53/drivers/firmware/efi/efi-stub-helper.c
     2.5 ++++ linux-3.16.53/drivers/firmware/efi/efi-stub-helper.c
     2.6 +@@ -321,6 +321,77 @@
     2.7 + 
     2.8 + 
     2.9 + /*
    2.10 ++ *
    2.11 ++ */
    2.12 ++static efi_status_t get_file_size(efi_system_table_t *sys_table_arg,
    2.13 ++				  efi_loaded_image_t *image,
    2.14 ++				  efi_char16_t *filename_16,
    2.15 ++				  struct file_info *file)
    2.16 ++{
    2.17 ++	efi_status_t status;
    2.18 ++	efi_file_handle_t *fh = NULL;
    2.19 ++#ifdef CONFIG_X86_64
    2.20 ++	efi_char16_t *p, c;
    2.21 ++#endif
    2.22 ++
    2.23 ++	/* Only open the volume once. */
    2.24 ++	if (!fh) {
    2.25 ++		status = efi_open_volume(sys_table_arg, image,
    2.26 ++					 (void **)&fh);
    2.27 ++		if (status != EFI_SUCCESS)
    2.28 ++			return status;
    2.29 ++	}
    2.30 ++#ifdef CONFIG_X86_64
    2.31 ++	for (p = filename_16; *p != '\0'; p++);
    2.32 ++	c = p[-2];
    2.33 ++	while (1) {
    2.34 ++#endif
    2.35 ++		status = efi_file_size(sys_table_arg, fh, filename_16,
    2.36 ++				       (void **)&file->handle, &file->size);
    2.37 ++#ifdef CONFIG_X86_64
    2.38 ++		if (status != EFI_SUCCESS && p[-2] != '\0') {
    2.39 ++			p[-2] = '\0';
    2.40 ++			continue;
    2.41 ++		}
    2.42 ++		break;
    2.43 ++	}
    2.44 ++	p[-2] = c;
    2.45 ++#endif
    2.46 ++	return status;
    2.47 ++}
    2.48 ++
    2.49 ++/*
    2.50 ++ *
    2.51 ++ */
    2.52 ++static efi_status_t read_efi_file(efi_system_table_t *sys_table_arg,
    2.53 ++			      struct file_info *file,
    2.54 ++			      unsigned long addr,
    2.55 ++			      unsigned long size)
    2.56 ++{
    2.57 ++	efi_status_t status;
    2.58 ++
    2.59 ++	while (size) {
    2.60 ++		unsigned long chunksize;
    2.61 ++		if (size > EFI_READ_CHUNK_SIZE)
    2.62 ++			chunksize = EFI_READ_CHUNK_SIZE;
    2.63 ++		else
    2.64 ++			chunksize = size;
    2.65 ++
    2.66 ++		status = efi_file_read(file->handle,
    2.67 ++				       &chunksize,
    2.68 ++				       (void *)addr);
    2.69 ++		if (status != EFI_SUCCESS) {
    2.70 ++			pr_efi_err(sys_table_arg, "Failed to read file\n");
    2.71 ++			break;
    2.72 ++		}
    2.73 ++		addr += chunksize;
    2.74 ++		size -= chunksize;
    2.75 ++	}
    2.76 ++	efi_file_close(file->handle);
    2.77 ++	return status;
    2.78 ++}
    2.79 ++
    2.80 ++/*
    2.81 +  * Check the cmdline for a LILO-style file= arguments.
    2.82 +  *
    2.83 +  * We only support loading a file from the same filesystem as
    2.84 +@@ -414,18 +485,14 @@
    2.85 + 			}
    2.86 + 		}
    2.87 + 
    2.88 ++#ifdef CONFIG_X86_64
    2.89 ++		*p++ = '6';
    2.90 ++		*p++ = '4';
    2.91 ++#endif
    2.92 + 		*p = '\0';
    2.93 + 
    2.94 +-		/* Only open the volume once. */
    2.95 +-		if (!i) {
    2.96 +-			status = efi_open_volume(sys_table_arg, image,
    2.97 +-						 (void **)&fh);
    2.98 +-			if (status != EFI_SUCCESS)
    2.99 +-				goto free_files;
   2.100 +-		}
   2.101 +-
   2.102 +-		status = efi_file_size(sys_table_arg, fh, filename_16,
   2.103 +-				       (void **)&file->handle, &file->size);
   2.104 ++		status = get_file_size(sys_table_arg,image,filename_16,file);
   2.105 ++	
   2.106 + 		if (status != EFI_SUCCESS)
   2.107 + 			goto close_handles;
   2.108 + 
   2.109 +@@ -433,8 +500,6 @@
   2.110 + 	}
   2.111 + 
   2.112 + 	if (file_size_total) {
   2.113 +-		unsigned long addr;
   2.114 +-
   2.115 + 		/*
   2.116 + 		 * Multiple files need to be at consecutive addresses in memory,
   2.117 + 		 * so allocate enough memory for all the files.  This is used
   2.118 +@@ -454,30 +519,10 @@
   2.119 + 			goto free_file_total;
   2.120 + 		}
   2.121 + 
   2.122 +-		addr = file_addr;
   2.123 + 		for (j = 0; j < nr_files; j++) {
   2.124 +-			unsigned long size;
   2.125 +-
   2.126 +-			size = files[j].size;
   2.127 +-			while (size) {
   2.128 +-				unsigned long chunksize;
   2.129 +-				if (size > EFI_READ_CHUNK_SIZE)
   2.130 +-					chunksize = EFI_READ_CHUNK_SIZE;
   2.131 +-				else
   2.132 +-					chunksize = size;
   2.133 +-
   2.134 +-				status = efi_file_read(files[j].handle,
   2.135 +-						       &chunksize,
   2.136 +-						       (void *)addr);
   2.137 +-				if (status != EFI_SUCCESS) {
   2.138 +-					pr_efi_err(sys_table_arg, "Failed to read file\n");
   2.139 +-					goto free_file_total;
   2.140 +-				}
   2.141 +-				addr += chunksize;
   2.142 +-				size -= chunksize;
   2.143 +-			}
   2.144 +-
   2.145 +-			efi_file_close(files[j].handle);
   2.146 ++			status = read_efi_file(sys_table_arg, &files[j], file_addr, files[j].size);
   2.147 ++			if (status != EFI_SUCCESS)
   2.148 ++				goto free_file_total;
   2.149 + 		}
   2.150 + 
   2.151 + 	}
   2.152 +@@ -649,6 +694,30 @@
   2.153 + 	}
   2.154 + 
   2.155 + 	if (!options_chars) {
   2.156 ++		/* No command line options, look for linux.cmdline */
   2.157 ++#ifdef CONFIG_X86_64
   2.158 ++#define cmdline_name L"EFI\\BOOT\\linux.cmdline64"
   2.159 ++#else
   2.160 ++#define cmdline_name L"EFI\\BOOT\\linux.cmdline"
   2.161 ++#endif
   2.162 ++		struct file_info file;
   2.163 ++		efi_char16_t filename_16[sizeof(cmdline_name)];
   2.164 ++
   2.165 ++		memcpy((void *)filename_16, (void *)cmdline_name, sizeof(cmdline_name));
   2.166 ++		if (get_file_size(sys_table_arg, image, filename_16, &file) != EFI_SUCCESS)
   2.167 ++			goto no_cmdline_file;
   2.168 ++
   2.169 ++		options_bytes = file.size+1;
   2.170 ++		if (efi_low_alloc(sys_table_arg, options_bytes, 0, &cmdline_addr) != EFI_SUCCESS)
   2.171 ++			goto no_cmdline_file;
   2.172 ++
   2.173 ++		*((u8 *)cmdline_addr + file.size) = '\0';
   2.174 ++		if (read_efi_file(sys_table_arg, &file, cmdline_addr, file.size) == EFI_SUCCESS)
   2.175 ++			goto return_cmdline;
   2.176 ++	}
   2.177 ++	no_cmdline_file:
   2.178 ++
   2.179 ++	if (!options_chars) {
   2.180 + 		/* No command line options, so return empty string*/
   2.181 + 		options = &zero;
   2.182 + 	}
   2.183 +@@ -665,6 +734,7 @@
   2.184 + 	s1 = efi_utf16_to_utf8(s1, s2, options_chars);
   2.185 + 	*s1 = '\0';
   2.186 + 
   2.187 ++return_cmdline:
   2.188 + 	*cmd_line_len = options_bytes;
   2.189 + 	return (char *)cmdline_addr;
   2.190 + }