Skip to content

Commit

Permalink
hw/arm/bcm2835_property: Implement "get command line" message
Browse files Browse the repository at this point in the history
This query copies the kernel command line into the message buffer. It
was previously stubbed out to return empty, this commit makes it reflect
the arguments specified with `-append`.

I observed the following peculiarities on my Pi 3B+:
- If the buffer is shorter than the string, the response header gives
  the full length, but no data is actually copied.
- No NUL terminator is added: even if the buffer is long enough to fit
  one, the buffer's original contents are preserved past the string's
  end.
- The VC firmware adds the following extra parameters beside the
  user-supplied ones (via /boot/cmdline.txt): `video`, `vc_mem.mem_base`
  and `vc_mem.mem_size`. This is currently not implemented in qemu.

Signed-off-by: Daniel Bertalan <dani@danielbertalan.dev>
Message-id: 20230425103250.56653-1-dani@danielbertalan.dev
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[PMM: added comment about NUL and short-buffer behaviour]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
BertalanD authored and pm215 committed May 2, 2023
1 parent c94beef commit 007d567
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions hw/arm/bcm2835_peripherals.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ static void bcm2835_peripherals_init(Object *obj)
TYPE_BCM2835_PROPERTY);
object_property_add_alias(obj, "board-rev", OBJECT(&s->property),
"board-rev");
object_property_add_alias(obj, "command-line", OBJECT(&s->property),
"command-line");

object_property_add_const_link(OBJECT(&s->property), "fb",
OBJECT(&s->fb));
Expand Down
2 changes: 2 additions & 0 deletions hw/arm/bcm2836.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ static void bcm2836_init(Object *obj)
TYPE_BCM2835_PERIPHERALS);
object_property_add_alias(obj, "board-rev", OBJECT(&s->peripherals),
"board-rev");
object_property_add_alias(obj, "command-line", OBJECT(&s->peripherals),
"command-line");
object_property_add_alias(obj, "vcram-size", OBJECT(&s->peripherals),
"vcram-size");
}
Expand Down
2 changes: 2 additions & 0 deletions hw/arm/raspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ static void raspi_machine_init(MachineState *machine)
object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(machine->ram));
object_property_set_int(OBJECT(&s->soc), "board-rev", board_rev,
&error_abort);
object_property_set_str(OBJECT(&s->soc), "command-line",
machine->kernel_cmdline, &error_abort);
qdev_realize(DEVICE(&s->soc), NULL, &error_fatal);

/* Create and plug in the SD cards */
Expand Down
13 changes: 12 additions & 1 deletion hw/misc/bcm2835_property.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,17 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
break;

case 0x00050001: /* Get command line */
resplen = 0;
/*
* We follow the firmware behaviour: no NUL terminator is
* written to the buffer, and if the buffer is too short
* we report the required length in the response header
* and copy nothing to the buffer.
*/
resplen = strlen(s->command_line);
if (bufsize >= resplen)
address_space_write(&s->dma_as, value + 12,
MEMTXATTRS_UNSPECIFIED, s->command_line,
resplen);
break;

default:
Expand Down Expand Up @@ -420,6 +430,7 @@ static void bcm2835_property_realize(DeviceState *dev, Error **errp)

static Property bcm2835_property_props[] = {
DEFINE_PROP_UINT32("board-rev", BCM2835PropertyState, board_rev, 0),
DEFINE_PROP_STRING("command-line", BCM2835PropertyState, command_line),
DEFINE_PROP_END_OF_LIST()
};

Expand Down
1 change: 1 addition & 0 deletions include/hw/misc/bcm2835_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct BCM2835PropertyState {
MACAddr macaddr;
uint32_t board_rev;
uint32_t addr;
char *command_line;
bool pending;
};

Expand Down

0 comments on commit 007d567

Please sign in to comment.