"Das U-Boot" Source Tree
at master 148 lines 3.5 kB view raw
1// SPDX-License-Identifier: GPL-2.0+ 2 3#include <env.h> 4#include <part.h> 5#include <spl.h> 6#include <spl_load.h> 7#include <ext4fs.h> 8#include <errno.h> 9#include <image.h> 10 11static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, 12 ulong size, void *buf) 13{ 14 int ret; 15 loff_t actlen; 16 17 ret = ext4fs_read(buf, file_offset, size, &actlen); 18 if (ret) 19 return ret; 20 return actlen; 21} 22 23int spl_load_image_ext(struct spl_image_info *spl_image, 24 struct spl_boot_device *bootdev, 25 struct blk_desc *block_dev, int partition, 26 const char *filename) 27{ 28 s32 err; 29 loff_t filelen; 30 struct disk_partition part_info = {}; 31 struct spl_load_info load; 32 33 if (part_get_info(block_dev, partition, &part_info)) { 34 printf("spl: no partition table found\n"); 35 return -1; 36 } 37 38 ext4fs_set_blk_dev(block_dev, &part_info); 39 40 err = ext4fs_mount(); 41 if (!err) { 42#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 43 printf("%s: ext4fs mount err - %d\n", __func__, err); 44#endif 45 return -1; 46 } 47 48 err = ext4fs_open(filename, &filelen); 49 if (err < 0) { 50 puts("spl: ext4fs_open failed\n"); 51 goto end; 52 } 53 54 spl_load_init(&load, spl_fit_read, NULL, 1); 55 err = spl_load(spl_image, bootdev, &load, filelen, 0); 56 57end: 58#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 59 if (err < 0) 60 printf("%s: error reading image %s, err - %d\n", 61 __func__, filename, err); 62#endif 63 64 return err < 0; 65} 66 67#if CONFIG_IS_ENABLED(OS_BOOT) 68int spl_load_image_ext_os(struct spl_image_info *spl_image, 69 struct spl_boot_device *bootdev, 70 struct blk_desc *block_dev, int partition) 71{ 72 int err; 73 __maybe_unused loff_t filelen, actlen; 74 struct disk_partition part_info = {}; 75 __maybe_unused char *file; 76 77 if (part_get_info(block_dev, partition, &part_info)) { 78 printf("spl: no partition table found\n"); 79 return -1; 80 } 81 82 ext4fs_set_blk_dev(block_dev, &part_info); 83 84 err = ext4fs_mount(); 85 if (!err) { 86#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 87 printf("%s: ext4fs mount err - %d\n", __func__, err); 88#endif 89 return -1; 90 } 91#if defined(CONFIG_SPL_ENV_SUPPORT) 92 file = env_get("falcon_args_file"); 93 if (file) { 94 err = ext4fs_open(file, &filelen); 95 if (err < 0) { 96 puts("spl: ext4fs_open failed\n"); 97 goto defaults; 98 } 99 err = ext4fs_read((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, 0, filelen, &actlen); 100 if (err < 0) { 101 printf("spl: error reading image %s, err - %d, falling back to default\n", 102 file, err); 103 goto defaults; 104 } 105 file = env_get("falcon_image_file"); 106 if (file) { 107 err = spl_load_image_ext(spl_image, bootdev, block_dev, 108 partition, file); 109 if (err != 0) { 110 puts("spl: falling back to default\n"); 111 goto defaults; 112 } 113 114 return 0; 115 } else { 116 puts("spl: falcon_image_file not set in environment, falling back to default\n"); 117 } 118 } else { 119 puts("spl: falcon_args_file not set in environment, falling back to default\n"); 120 } 121 122defaults: 123#endif 124 125 err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME, &filelen); 126 if (err < 0) 127 puts("spl: ext4fs_open failed\n"); 128 129 err = ext4fs_read((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, 0, filelen, &actlen); 130 if (err < 0) { 131#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 132 printf("%s: error reading image %s, err - %d\n", 133 __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err); 134#endif 135 return -1; 136 } 137 138 return spl_load_image_ext(spl_image, bootdev, block_dev, partition, 139 CONFIG_SPL_FS_LOAD_KERNEL_NAME); 140} 141#else 142int spl_load_image_ext_os(struct spl_image_info *spl_image, 143 struct spl_boot_device *bootdev, 144 struct blk_desc *block_dev, int partition) 145{ 146 return -ENOSYS; 147} 148#endif