summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-05-04 12:45:11 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-05-17 08:29:42 +0200
commit7000b90984a0ca50443f1bd84c058e129c05f229 (patch)
tree54a04e62cf2156af635ed4a4f7982f79a83bc584
parent9174376cd08e1e3e638cd852525cc529d25fde47 (diff)
downloadbarebox-7000b90984a0ca50443f1bd84c058e129c05f229.tar.gz
barebox-7000b90984a0ca50443f1bd84c058e129c05f229.tar.xz
bootm: move ARM64 Linux image parsing to common directory
Linux on RISC-V adopts the same structure as on ARM64 for both 32- and 64-bit kernel images and it's likely future architectures will as well. In preparation for adding RISC-V Linux boot support, move the bulk of the code to a common location for reusability. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210504104513.2640-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--arch/arm/lib64/armlinux.c74
-rw-r--r--common/Makefile2
-rw-r--r--common/booti.c66
-rw-r--r--include/bootm.h2
4 files changed, 74 insertions, 70 deletions
diff --git a/arch/arm/lib64/armlinux.c b/arch/arm/lib64/armlinux.c
index a5f122edcd..0ba4d30b8e 100644
--- a/arch/arm/lib64/armlinux.c
+++ b/arch/arm/lib64/armlinux.c
@@ -1,90 +1,26 @@
// SPDX-License-Identifier: GPL-2.0-only
// SPDX-FileCopyrightText: 2018 Sascha Hauer <s.hauer@pengutronix.de>
-#include <boot.h>
#include <common.h>
-#include <environment.h>
-#include <image.h>
-#include <fs.h>
-#include <xfuncs.h>
-#include <malloc.h>
-#include <fcntl.h>
-#include <errno.h>
#include <memory.h>
-#include <of.h>
#include <init.h>
#include <bootm.h>
-#include <linux/list.h>
-#include <asm/byteorder.h>
-#include <asm/setup.h>
-#include <asm/barebox-arm.h>
-#include <asm/armlinux.h>
-#include <asm/system.h>
static int do_bootm_linux(struct image_data *data)
{
- const void *kernel_header =
- data->os_fit ? data->fit_kernel : data->os_header;
void (*fn)(unsigned long dtb, unsigned long x1, unsigned long x2,
unsigned long x3);
- resource_size_t start, end;
- unsigned long text_offset, image_size, devicetree, kernel;
- unsigned long image_end;
- int ret;
- void *fdt;
-
- text_offset = le64_to_cpup(kernel_header + 8);
- image_size = le64_to_cpup(kernel_header+ 16);
-
- ret = memory_bank_first_find_space(&start, &end);
- if (ret)
- goto out;
-
- kernel = ALIGN(start, SZ_2M) + text_offset;
-
- ret = bootm_load_os(data, kernel);
- if (ret)
- goto out;
-
- image_end = PAGE_ALIGN(kernel + image_size);
-
- if (bootm_has_initrd(data)) {
- ret = bootm_load_initrd(data, image_end);
- if (ret)
- return ret;
-
- image_end += resource_size(data->initrd_res);
- image_end = PAGE_ALIGN(image_end);
- }
+ phys_addr_t devicetree;
- devicetree = image_end;
-
- fdt = bootm_get_devicetree(data);
- if (IS_ERR(fdt)) {
- ret = PTR_ERR(fdt);
- goto out;
- }
-
- ret = bootm_load_devicetree(data, fdt, devicetree);
-
- free(fdt);
-
- if (ret)
- goto out;
-
- printf("Loaded kernel to 0x%08lx, devicetree at 0x%08lx\n",
- kernel, devicetree);
+ fn = booti_load_image(data, &devicetree);
+ if (IS_ERR(fn))
+ return PTR_ERR(fn);
shutdown_barebox();
- fn = (void *)kernel;
-
fn(devicetree, 0, 0, 0);
- ret = -EINVAL;
-
-out:
- return ret;
+ return -EINVAL;
}
static struct image_handler aarch64_linux_handler = {
diff --git a/common/Makefile b/common/Makefile
index c0b45d263e..2c679090a0 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -20,7 +20,7 @@ obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
obj-$(CONFIG_BINFMT) += binfmt.o
obj-$(CONFIG_BLOCK) += block.o
obj-$(CONFIG_BLSPEC) += blspec.o
-obj-$(CONFIG_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o booti.o
obj-$(CONFIG_CMD_LOADS) += s_record.o
obj-$(CONFIG_CMD_MEMTEST) += memtest.o
obj-$(CONFIG_COMMAND_SUPPORT) += command.o
diff --git a/common/booti.c b/common/booti.c
new file mode 100644
index 0000000000..a2d63d8c31
--- /dev/null
+++ b/common/booti.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: 2018 Sascha Hauer <s.hauer@pengutronix.de>
+
+#include <common.h>
+#include <memory.h>
+#include <bootm.h>
+#include <linux/sizes.h>
+
+void *booti_load_image(struct image_data *data, phys_addr_t *oftree)
+{
+ const void *kernel_header =
+ data->os_fit ? data->fit_kernel : data->os_header;
+ resource_size_t start, end;
+ unsigned long text_offset, image_size, devicetree, kernel;
+ unsigned long image_end;
+ int ret;
+ void *fdt;
+
+ text_offset = le64_to_cpup(kernel_header + 8);
+ image_size = le64_to_cpup(kernel_header + 16);
+
+ ret = memory_bank_first_find_space(&start, &end);
+ if (ret)
+ return ERR_PTR(ret);
+
+ kernel = ALIGN(start, SZ_2M) + text_offset;
+
+ ret = bootm_load_os(data, kernel);
+ if (ret)
+ return ERR_PTR(ret);
+
+ image_end = PAGE_ALIGN(kernel + image_size);
+
+ if (oftree) {
+ if (bootm_has_initrd(data)) {
+ ret = bootm_load_initrd(data, image_end);
+ if (ret)
+ return ERR_PTR(ret);
+
+ image_end += resource_size(data->initrd_res);
+ image_end = PAGE_ALIGN(image_end);
+ }
+
+ devicetree = image_end;
+
+ fdt = bootm_get_devicetree(data);
+ if (IS_ERR(fdt))
+ return fdt;
+
+ ret = bootm_load_devicetree(data, fdt, devicetree);
+
+ free(fdt);
+
+ if (ret)
+ return ERR_PTR(ret);
+
+ *oftree = devicetree;
+ }
+
+ printf("Loaded kernel to 0x%08lx", kernel);
+ if (oftree)
+ printf(", devicetree at 0x%08lx", devicetree);
+ printf("\n");
+
+ return (void *)kernel;
+}
diff --git a/include/bootm.h b/include/bootm.h
index 51e9b3d71a..655c5152d9 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -148,4 +148,6 @@ enum bootm_verify bootm_get_verify_mode(void);
#define UIMAGE_SOME_ADDRESS (UIMAGE_INVALID_ADDRESS - 1)
+void *booti_load_image(struct image_data *data, phys_addr_t *oftree);
+
#endif /* __BOOTM_H */