summaryrefslogtreecommitdiffstats
path: root/bsps/arm/raspberrypi/start/cmdline.c
blob: 222b21eb63e471c66b5ac98828660d5923e04fae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
 * @file
 *
 * @ingroup raspberrypi
 *
 * @brief mailbox support.
 */
/*
 * Copyright (c) 2015 Yang Qiao
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *
 *  http://www.rtems.org/license/LICENSE
 *
 */

#include <bsp.h>
#include <bsp/vc.h>

#include <string.h>

#define MAX_CMDLINE_LENGTH 1024
static int rpi_cmdline_ready = -1;
static char rpi_cmdline_cached[MAX_CMDLINE_LENGTH] = "force .data placement";
static bcm2835_get_cmdline_entries rpi_cmdline_entries;

const char *rpi_cmdline_get_raw(void)
{
  memset(&rpi_cmdline_entries, 0, sizeof(rpi_cmdline_entries));
  if (bcm2835_mailbox_get_cmdline(&rpi_cmdline_entries) < 0)
     return NULL;
  return rpi_cmdline_entries.cmdline;
}

const char *rpi_cmdline_get_cached(void)
{
  if (rpi_cmdline_ready <= 0) {
    const char *line = rpi_cmdline_get_raw();
    if (line != NULL)
      strncpy(rpi_cmdline_cached, line, MAX_CMDLINE_LENGTH - 1);
    rpi_cmdline_cached[MAX_CMDLINE_LENGTH - 1] = 0;
    rpi_cmdline_ready = 1;
  }
  return rpi_cmdline_cached;
}

const char *rpi_cmdline_get_arg(const char* arg)
{
  const char *opt_data;
  opt_data = strstr(rpi_cmdline_get_cached(), arg);
  if (opt_data)
    opt_data += strlen(arg);
  return opt_data;
}