Coverage Report

Created: 2026-10-13 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/barebox/commands/bootm.c
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
// SPDX-FileCopyrightText: © 2000-2006 Wolfgang Denk <wd@denx.de>, DENX Software Engineering
3
4
/*
5
 * Boot support
6
 */
7
#include <common.h>
8
#include <driver.h>
9
#include <command.h>
10
#include <image.h>
11
#include <malloc.h>
12
#include <environment.h>
13
#include <asm/byteorder.h>
14
#include <xfuncs.h>
15
#include <getopt.h>
16
#include <fcntl.h>
17
#include <fs.h>
18
#include <errno.h>
19
#include <bootm.h>
20
#include <rtc.h>
21
#include <init.h>
22
#include <of.h>
23
#include <uncompress.h>
24
#include <memory.h>
25
#include <filetype.h>
26
#include <binfmt.h>
27
#include <globalvar.h>
28
#include <magicvar.h>
29
#include <asm-generic/memory_layout.h>
30
31
0
#define BOOTM_OPTS_COMMON "a:e:vo:fd"
32
33
#ifdef CONFIG_BOOTM_INITRD
34
#define BOOTM_OPTS BOOTM_OPTS_COMMON "L:r:"
35
#else
36
0
#define BOOTM_OPTS BOOTM_OPTS_COMMON
37
#endif
38
39
static unsigned command_attempts;
40
41
unsigned bootm_command_attempts(void)
42
0
{
43
0
  return command_attempts;
44
0
}
45
46
static int do_bootm(int argc, char *argv[])
47
0
{
48
0
  int opt;
49
0
  struct bootm_data data = {};
50
0
  int ret = 1;
51
52
0
  bootm_data_init_defaults(&data);
53
54
0
  command_attempts++;
55
56
0
  while ((opt = getopt(argc, argv, BOOTM_OPTS)) > 0) {
57
0
    switch(opt) {
58
#ifdef CONFIG_BOOTM_INITRD
59
    case 'L':
60
      data.initrd_address = simple_strtoul(optarg, NULL, 0);
61
      break;
62
    case 'r':
63
      data.initrd_file = optarg;
64
      break;
65
#endif
66
0
    case 'a':
67
0
      data.os_address = simple_strtoul(optarg, NULL, 0);
68
0
      break;
69
0
    case 'e':
70
0
      data.os_entry = simple_strtoul(optarg, NULL, 0);
71
0
      break;
72
0
    case 'v':
73
0
      data.verbose++;
74
0
      break;
75
0
    case 'o':
76
0
      data.oftree_file = optarg;
77
0
      break;
78
0
    case 'f':
79
0
      data.force = 1;
80
0
      break;
81
0
    case 'd':
82
0
      data.dryrun = 1;
83
0
      break;
84
0
    default:
85
0
      return COMMAND_ERROR_USAGE;
86
0
    }
87
0
  }
88
89
0
  if (optind != argc)
90
0
    data.os_file = argv[optind];
91
92
0
  if (!data.os_file) {
93
0
    printf("no boot image given\n");
94
0
    goto err_out;
95
0
  }
96
97
0
  ret = bootm_boot(&data);
98
0
  if (ret) {
99
0
    printf("handler failed with: %pe\n", ERR_PTR(ret));
100
0
    goto err_out;
101
0
  }
102
103
0
err_out:
104
0
  return ret ? 1 : 0;
105
0
}
106
107
BAREBOX_CMD_HELP_START(bootm)
108
BAREBOX_CMD_HELP_TEXT("Options:")
109
BAREBOX_CMD_HELP_OPT ("-d\t",  "dry run: check data, but do not run")
110
BAREBOX_CMD_HELP_OPT ("-f\t",  "load images even if type is undetectable")
111
#ifdef CONFIG_BOOTM_INITRD
112
BAREBOX_CMD_HELP_OPT ("-r INITRD","specify an initrd image")
113
BAREBOX_CMD_HELP_OPT ("-L ADDR\t","specify initrd load address")
114
#endif
115
BAREBOX_CMD_HELP_OPT ("-a ADDR\t","specify os load address")
116
BAREBOX_CMD_HELP_OPT ("-e OFFS\t","entry point to the image relative to start (0)")
117
#ifdef CONFIG_OFTREE
118
BAREBOX_CMD_HELP_OPT ("-o DTB\t","specify open firmware device tree")
119
#endif
120
#ifdef CONFIG_BOOTM_VERBOSE
121
BAREBOX_CMD_HELP_OPT ("-v\t","verbose")
122
#endif
123
BAREBOX_CMD_HELP_END
124
125
BAREBOX_CMD_START(bootm)
126
  .cmd    = do_bootm,
127
  BAREBOX_CMD_DESC("boot an application image")
128
  BAREBOX_CMD_OPTS("[-df"
129
#ifdef CONFIG_BOOTM_INITRD
130
            "rL"
131
#endif
132
            "ae"
133
#ifdef CONFIG_OFTREE
134
            "o"
135
#endif
136
#ifdef CONFIG_BOOTM_VERBOSE
137
            "v"
138
#endif
139
            "] IMAGE")
140
  BAREBOX_CMD_GROUP(CMD_GRP_BOOT)
141
  BAREBOX_CMD_HELP(cmd_bootm_help)
142
BAREBOX_CMD_END
143
144
static struct binfmt_hook binfmt_uimage_hook = {
145
  .type = filetype_uimage,
146
  .exec = "bootm",
147
};
148
149
static int binfmt_uimage_init(void)
150
26
{
151
26
  return binfmt_register(&binfmt_uimage_hook);
152
26
}
153
fs_initcall(binfmt_uimage_init);