[U-Boot] [RFC PATCH] rockchip: tinker: Add boot from capability

Michael Nazzareno Trimarchi michael at amarulasolutions.com
Tue Nov 12 18:48:51 UTC 2019


Hi Kever

Let me more clear

On Tue, Nov 12, 2019 at 11:02 AM Michael Nazzareno Trimarchi
<michael at amarulasolutions.com> wrote:
>
> Hi Kever
>
> On Tue, Nov 12, 2019 at 10:57 AM Kever Yang <kever.yang at rock-chips.com> wrote:
> >
> > Hi Michael,
> >
> > On 2019/11/12 下午4:14, Michael Trimarchi wrote:
> > > We need to know from what device we are booting
> >
> > Please make sure board_spl_was_booted_from() works for rk3288, which
> >
> > already work for rk3399, after that, we can move those functions from rk3399
> >
> > only into common code to make everything work.
> >
> > We are not going to add "spl-boot-device".
>
> That implementation has no sense in my use case. You need fit image. I
> don't need any special change

I don't re-allocate the dtb so the size in no-fit image is the same. I
think that we can use
some meta-tag for bootloader to store information from spl to second
stage. You need to keep
in the same size or you have -ENOSPACE. This can be generic but
depends what the maintair
think.

Michael

>
> Michael
> >
> >
> > Thanks,
> >
> > - Kever
> >
> > > in order
> > > to save the enviroment in right place
> > >
> > > Signed-off-by: Michael Trimarchi <michael at amarulasolutions.com>
> > > ---
> > >   arch/arm/dts/rk3288-tinker-s-u-boot.dtsi     |  1 +
> > >   arch/arm/mach-rockchip/rk3288/rk3288.c       | 46 ++++++++++++++++++++
> > >   board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +++++++++++++++++
> > >   configs/tinker-rk3288_defconfig              |  2 +
> > >   configs/tinker-s-rk3288_defconfig            |  2 +
> > >   5 files changed, 92 insertions(+)
> > >
> > > diff --git a/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi b/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi
> > > index 538593359a..2193127514 100644
> > > --- a/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi
> > > +++ b/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi
> > > @@ -10,6 +10,7 @@
> > >       chosen {
> > >               u-boot,spl-boot-order = \
> > >                       "same-as-spl", &sdmmc, &emmc;
> > > +             u-boot,spl-boot-device = "/dwmmc at ff0f0000";
> > >       };
> > >   };
> > >
> > > diff --git a/arch/arm/mach-rockchip/rk3288/rk3288.c b/arch/arm/mach-rockchip/rk3288/rk3288.c
> > > index 987b4e0d58..002d1508e5 100644
> > > --- a/arch/arm/mach-rockchip/rk3288/rk3288.c
> > > +++ b/arch/arm/mach-rockchip/rk3288/rk3288.c
> > > @@ -3,6 +3,8 @@
> > >    * Copyright (c) 2016 Rockchip Electronics Co., Ltd
> > >    */
> > >   #include <common.h>
> > > +#include <spl.h>
> > > +#include <fdt_support.h>
> > >   #include <dm.h>
> > >   #include <env.h>
> > >   #include <clk.h>
> > > @@ -26,6 +28,50 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
> > >       [BROM_BOOTSOURCE_SD] = "/dwmmc at ff0c0000",
> > >   };
> > >
> > > +#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
> > > +const char *spl_decode_boot_device(u32 boot_device)
> > > +{
> > > +     int i;
> > > +     static const struct {
> > > +             u32 boot_device;
> > > +             const char *ofpath;
> > > +     } spl_boot_devices_tbl[] = {
> > > +             { BOOT_DEVICE_MMC2, "/dwmmc at ff0f0000" },
> > > +             { BOOT_DEVICE_MMC1, "/dwmmc at ff0c0000" },
> > > +     };
> > > +
> > > +     for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
> > > +             if (spl_boot_devices_tbl[i].boot_device == boot_device)
> > > +                     return spl_boot_devices_tbl[i].ofpath;
> > > +
> > > +     return NULL;
> > > +}
> > > +
> > > +void spl_perform_fixups(struct spl_image_info *spl_image)
> > > +{
> > > +     void *blob = (void *)gd->fdt_blob;
> > > +     const char *boot_ofpath;
> > > +     int chosen;
> > > +
> > > +     if (!blob)
> > > +             return;
> > > +
> > > +     boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
> > > +     if (!boot_ofpath) {
> > > +             pr_err("%s: could not map boot_device to ofpath\n", __func__);
> > > +             return;
> > > +     }
> > > +
> > > +     chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
> > > +     if (chosen < 0) {
> > > +             pr_err("%s: could not find/create '/chosen'\n", __func__);
> > > +             return;
> > > +     }
> > > +     fdt_setprop_string(blob, chosen,
> > > +                        "u-boot,spl-boot-device", boot_ofpath);
> > > +}
> > > +#endif
> > > +
> > >   #ifdef CONFIG_SPL_BUILD
> > >   static void configure_l2ctlr(void)
> > >   {
> > > diff --git a/board/rockchip/tinker_rk3288/tinker-rk3288.c b/board/rockchip/tinker_rk3288/tinker-rk3288.c
> > > index 6c76c3c25c..66a7394d95 100644
> > > --- a/board/rockchip/tinker_rk3288/tinker-rk3288.c
> > > +++ b/board/rockchip/tinker_rk3288/tinker-rk3288.c
> > > @@ -9,6 +9,34 @@
> > >   #include <i2c_eeprom.h>
> > >   #include <netdev.h>
> > >
> > > +static int tinker_boot_device = CONFIG_SYS_MMC_ENV_DEV;
> > > +
> > > +/*
> > > + * Select the boot device according to what was set in spl step
> > > + */
> > > +static int setup_boottargets(void)
> > > +{
> > > +     const char *boot_device =
> > > +             ofnode_get_chosen_prop("u-boot,spl-boot-device");
> > > +
> > > +     if (!boot_device) {
> > > +             debug("%s: /chosen/u-boot,spl-boot-device not set\n",
> > > +                   __func__);
> > > +             return -1;
> > > +     }
> > > +     debug("%s: booted from %s\n", __func__, boot_device);
> > > +
> > > +     if (!strcmp(boot_device, "/dwmmc at ff0f0000")) {
> > > +             /* eMMC boot device */
> > > +             tinker_boot_device = 1;
> > > +     } else {
> > > +             /* sdcard boot device */
> > > +             tinker_boot_device = 0;
> > > +     }
> > > +
> > > +     return 0;
> > > +}
> > > +
> > >   static int get_ethaddr_from_eeprom(u8 *addr)
> > >   {
> > >       int ret;
> > > @@ -33,3 +61,16 @@ int rk3288_board_late_init(void)
> > >
> > >       return 0;
> > >   }
> > > +
> > > +int misc_init_r(void)
> > > +{
> > > +     setup_boottargets();
> > > +
> > > +     return 0;
> > > +}
> > > +
> > > +int mmc_get_env_dev(void)
> > > +{
> > > +     debug("boot device %d\n", tinker_boot_device);
> > > +     return tinker_boot_device;
> > > +}
> > > diff --git a/configs/tinker-rk3288_defconfig b/configs/tinker-rk3288_defconfig
> > > index c851a93f31..106e24e8ca 100644
> > > --- a/configs/tinker-rk3288_defconfig
> > > +++ b/configs/tinker-rk3288_defconfig
> > > @@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
> > >   CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
> > >   CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
> > >   CONFIG_SYS_MALLOC_F_LEN=0x4000
> > > +CONFIG_SPL_OF_LIBFDT=y
> > >   # CONFIG_ANDROID_BOOT_IMAGE is not set
> > > +CONFIG_MISC_INIT_R=y
> > >   CONFIG_USE_PREBOOT=y
> > >   CONFIG_SILENT_CONSOLE=y
> > >   CONFIG_CONSOLE_MUX=y
> > > diff --git a/configs/tinker-s-rk3288_defconfig b/configs/tinker-s-rk3288_defconfig
> > > index c851a93f31..106e24e8ca 100644
> > > --- a/configs/tinker-s-rk3288_defconfig
> > > +++ b/configs/tinker-s-rk3288_defconfig
> > > @@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y
> > >   CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000
> > >   CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000
> > >   CONFIG_SYS_MALLOC_F_LEN=0x4000
> > > +CONFIG_SPL_OF_LIBFDT=y
> > >   # CONFIG_ANDROID_BOOT_IMAGE is not set
> > > +CONFIG_MISC_INIT_R=y
> > >   CONFIG_USE_PREBOOT=y
> > >   CONFIG_SILENT_CONSOLE=y
> > >   CONFIG_CONSOLE_MUX=y
> >
> >
>
>
> --
> | Michael Nazzareno Trimarchi                     Amarula Solutions BV |
> | COO  -  Founder                                      Cruquiuskade 47 |
> | +31(0)851119172                                 Amsterdam 1018 AM NL |
> |                  [`as] http://www.amarulasolutions.com               |



-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |


More information about the U-Boot mailing list