summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/raspberrypi/startup/cmdline.c
blob: f8a7182c659f0460ac7c17897fdf3eda0f849c38 (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
/**
 * @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>

#define MAX_CMDLINE_LENGTH 1024
static int rpi_cmdline_ready;
static char rpi_cmdline_cached[MAX_CMDLINE_LENGTH];
static bcm2835_get_cmdline_entries rpi_cmdline_entries;

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

const char *rpi_cmdline_get_cached(void)
{
  if (!rpi_cmdline_ready) {
    const char *line = rpi_cmdline_get_raw();
    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)
{
  return strstr (rpi_cmdline_get_cached(), arg);
}