Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2011 Andes Technology Corporation |
| 4 | * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com> |
| 5 | * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com> |
| 6 | * Rick Chen, Andes Technology Corporation <rick@andestech.com> |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <command.h> |
| 11 | #include <image.h> |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 12 | #include <asm/byteorder.h> |
Bin Meng | ed49ba4 | 2018-09-26 06:55:16 -0700 | [diff] [blame] | 13 | #include <asm/csr.h> |
Bin Meng | b1893a9 | 2018-10-15 02:20:59 -0700 | [diff] [blame^] | 14 | #include <dm/device.h> |
| 15 | #include <dm/root.h> |
| 16 | #include <u-boot/zlib.h> |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Alexander Graf | b66babd | 2018-04-23 07:59:46 +0200 | [diff] [blame] | 20 | __weak void board_quiesce_devices(void) |
| 21 | { |
| 22 | } |
| 23 | |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 24 | int arch_fixup_fdt(void *blob) |
| 25 | { |
| 26 | return 0; |
| 27 | } |
| 28 | |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 29 | int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) |
| 30 | { |
Bin Meng | 4afeedf | 2018-09-26 06:55:08 -0700 | [diff] [blame] | 31 | void (*kernel)(ulong hart, void *dtb); |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 32 | |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 33 | /* |
| 34 | * allow the PREP bootm subcommand, it is required for bootm to work |
| 35 | */ |
| 36 | if (flag & BOOTM_STATE_OS_PREP) |
| 37 | return 0; |
| 38 | |
| 39 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 40 | return 1; |
| 41 | |
Bin Meng | 4afeedf | 2018-09-26 06:55:08 -0700 | [diff] [blame] | 42 | kernel = (void (*)(ulong, void *))images->ep; |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 43 | |
| 44 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 45 | |
| 46 | debug("## Transferring control to Linux (at address %08lx) ...\n", |
Bin Meng | 4afeedf | 2018-09-26 06:55:08 -0700 | [diff] [blame] | 47 | (ulong)kernel); |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 48 | |
| 49 | if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { |
| 50 | #ifdef CONFIG_OF_LIBFDT |
| 51 | debug("using: FDT\n"); |
| 52 | if (image_setup_linux(images)) { |
| 53 | printf("FDT creation failed! hanging..."); |
| 54 | hang(); |
| 55 | } |
| 56 | #endif |
Rick Chen | 22b7e6f | 2018-03-13 14:59:41 +0800 | [diff] [blame] | 57 | } |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 58 | |
| 59 | /* we assume that the kernel is in place */ |
| 60 | printf("\nStarting kernel ...\n\n"); |
| 61 | |
Bin Meng | b1893a9 | 2018-10-15 02:20:59 -0700 | [diff] [blame^] | 62 | /* |
| 63 | * Call remove function of all devices with a removal flag set. |
| 64 | * This may be useful for last-stage operations, like cancelling |
| 65 | * of DMA operation or releasing device internal buffers. |
| 66 | */ |
| 67 | dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL); |
| 68 | |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 69 | cleanup_before_linux(); |
Bin Meng | ed49ba4 | 2018-09-26 06:55:16 -0700 | [diff] [blame] | 70 | |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 71 | if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) |
Bin Meng | ed49ba4 | 2018-09-26 06:55:16 -0700 | [diff] [blame] | 72 | kernel(csr_read(mhartid), images->ft_addr); |
Rick Chen | 22b7e6f | 2018-03-13 14:59:41 +0800 | [diff] [blame] | 73 | |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 74 | /* does not return */ |
| 75 | |
| 76 | return 1; |
| 77 | } |