board: stemmy: Copy atags for booting downstream/vendor kernel

The U-Boot "stemmy" board is mainly intended to simplify booting
mainline Linux on various smartphones from Samsung based on ST-Ericsson
Ux500. While the mainline kernel is working great, there are still some
features missing there. In particular, it is currently not possible to
charge the battery when using the mainline kernel.

This means that it is still necessary to boot the downstream/vendor
kernel from Samsung sometimes to charge the device. That kernel is
ancient, still uses board files + ATAGS instead of device trees and
relies on a strange very long kernel command line hardcoded in the
Samsung bootloader.

Actually, since mainline is booted with device trees there is a very
simple way to make the old downstream kernel work as well: We can
simply take most of the ATAGS passed to U-Boot from the Samsung
bootloader and copy them as-is when booting a kernel without device
tree. That way the long command line and other needed ATAGS are copied
as-is without having to bother with them.

The only exception is the ATAG_INITRD - since the initrd is loaded
by U-Boot, the atag for that should be generated in U-Boot so it points
to the correct address. All other ATAGS are copied as-is and not
generated in U-Boot.

Also use the chance and provide a serial# for U-Boot by parsing the
ATAG_SERIAL that is also passed by the Samsung bootloader.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
Stephan Gerhold 2021-07-07 12:58:55 +02:00 committed by Tom Rini
parent 03585d52fc
commit e2f82f93f8
3 changed files with 91 additions and 0 deletions

View file

@ -8,6 +8,7 @@ choice
config TARGET_STEMMY config TARGET_STEMMY
bool "Samsung (stemmy) board" bool "Samsung (stemmy) board"
select MISC_INIT_R
help help
The Samsung "stemmy" board supports Samsung smartphones released with The Samsung "stemmy" board supports Samsung smartphones released with
the ST-Ericsson NovaThor U8500 SoC, e.g. the ST-Ericsson NovaThor U8500 SoC, e.g.

View file

@ -3,8 +3,10 @@
* Copyright (C) 2019 Stephan Gerhold <stephan@gerhold.net> * Copyright (C) 2019 Stephan Gerhold <stephan@gerhold.net>
*/ */
#include <common.h> #include <common.h>
#include <env.h>
#include <init.h> #include <init.h>
#include <log.h> #include <log.h>
#include <stdlib.h>
#include <asm/global_data.h> #include <asm/global_data.h>
#include <asm/setup.h> #include <asm/setup.h>
#include <asm/system.h> #include <asm/system.h>
@ -15,6 +17,9 @@ DECLARE_GLOBAL_DATA_PTR;
static ulong fw_mach __section(".data"); static ulong fw_mach __section(".data");
static ulong fw_atags __section(".data"); static ulong fw_atags __section(".data");
static const struct tag *fw_atags_copy;
static uint fw_atags_size;
void save_boot_params(ulong r0, ulong r1, ulong r2, ulong r3) void save_boot_params(ulong r0, ulong r1, ulong r2, ulong r3)
{ {
fw_mach = r1; fw_mach = r1;
@ -78,3 +83,85 @@ int board_init(void)
gd->bd->bi_boot_params = fw_atags; gd->bd->bi_boot_params = fw_atags;
return 0; return 0;
} }
static void parse_serial(const struct tag_serialnr *serialnr)
{
char serial[17];
if (env_get("serial#"))
return;
sprintf(serial, "%08x%08x", serialnr->high, serialnr->low);
env_set("serial#", serial);
}
/*
* The downstream/vendor kernel (provided by Samsung) uses ATAGS for booting.
* It also requires an extremely long cmdline provided by the primary bootloader
* that is not suitable for booting mainline.
*
* Since downstream is the only user of ATAGS, we emulate the behavior of the
* Samsung bootloader by generating only the initrd atag in U-Boot, and copying
* all other ATAGS as-is from the primary bootloader.
*/
static inline bool skip_atag(u32 tag)
{
return (tag == ATAG_NONE || tag == ATAG_CORE ||
tag == ATAG_INITRD || tag == ATAG_INITRD2);
}
static void copy_atags(const struct tag *tags)
{
const struct tag *t;
struct tag *copy;
if (!tags)
return;
/* Calculate necessary size for tags we want to copy */
for_each_tag(t, tags) {
if (skip_atag(t->hdr.tag))
continue;
if (t->hdr.tag == ATAG_SERIAL)
parse_serial(&t->u.serialnr);
fw_atags_size += t->hdr.size * sizeof(u32);
}
if (!fw_atags_size)
return; /* No tags to copy */
copy = malloc(fw_atags_size);
if (!copy)
return;
fw_atags_copy = copy;
/* Copy tags */
for_each_tag(t, tags) {
if (skip_atag(t->hdr.tag))
continue;
memcpy(copy, t, t->hdr.size * sizeof(u32));
copy = tag_next(copy);
}
}
int misc_init_r(void)
{
copy_atags(fw_atags_get());
return 0;
}
void setup_board_tags(struct tag **in_params)
{
if (!fw_atags_copy)
return;
/*
* fw_atags_copy contains only full "struct tag" (plus data)
* so copying it bytewise here should be fine.
*/
memcpy(*in_params, fw_atags_copy, fw_atags_size);
*(u8 **)in_params += fw_atags_size;
}

View file

@ -23,4 +23,7 @@
#define CONFIG_SYS_L2_PL310 #define CONFIG_SYS_L2_PL310
#define CONFIG_SYS_PL310_BASE 0xa0412000 #define CONFIG_SYS_PL310_BASE 0xa0412000
/* Generate initrd atag for downstream kernel (others are copied in stemmy.c) */
#define CONFIG_INITRD_TAG
#endif #endif