Hi Simon 2017-02-23 11:33 GMT+08:00 Simon Glass <s...@chromium.org>:
> Hi Eddie, > > On 22 February 2017 at 07:12, Eddie Cai <eddie.cai.li...@gmail.com> wrote: > > Hi Simon > > > > 2017-02-22 17:05 GMT+08:00 Eddie Cai <eddie.cai.li...@gmail.com>: > >> > >> Hi Simon > >> > >> 2017-02-22 11:59 GMT+08:00 Simon Glass <s...@chromium.org>: > >>> > >>> Hi Eddie, > >>> > >>> On 17 February 2017 at 00:57, Eddie Cai <eddie.cai.li...@gmail.com> > >>> wrote: > >>> > Auto write GPT table if fail to get GPT table when > >>> > scan_dev_for_boot_part > >>> > > >>> > Signed-off-by: Eddie Cai <eddie.cai.li...@gmail.com> > >>> > --- > >>> > arch/arm/mach-rockchip/rk3036-board.c | 20 ++++++++++++++- > >>> > arch/arm/mach-rockchip/rk3288-board.c | 20 ++++++++++++++- > >>> > arch/arm/mach-rockchip/rk3399-board.c | 46 > >>> > +++++++++++++++++++++++++++++++++++ > >>> > 3 files changed, 84 insertions(+), 2 deletions(-) > >>> > create mode 100644 arch/arm/mach-rockchip/rk3399-board.c > >>> > > >>> > diff --git a/arch/arm/mach-rockchip/rk3036-board.c > >>> > b/arch/arm/mach-rockchip/rk3036-board.c > >>> > index bf2b268..e9aeaff 100644 > >>> > --- a/arch/arm/mach-rockchip/rk3036-board.c > >>> > +++ b/arch/arm/mach-rockchip/rk3036-board.c > >>> > @@ -51,7 +51,25 @@ __weak int rk_board_late_init(void) > >>> > int board_late_init(void) > >>> > { > >>> > setup_boot_mode(); > >>> > - > >>> > + setenv("scan_dev_for_boot_part", > >>> > + "part list ${devtype} ${devnum} -bootable > test; > >>> > " > >>> > + "if env exists test; then " > >>> > + "echo Found valid partition table; " > >>> > + "else " > >>> > + "echo No valid partition table, write the > >>> > original partition table; " > >>> > + "gpt write ${devtype} ${devnum} > >>> > ${partitions}; " > >>> > + "mmc rescan;" > >>> > + "fi;" > >>> > + "part list ${devtype} ${devnum} -bootable > >>> > devplist; " > >>> > + "env exists devplist || setenv devplist 1; " > >>> > + "for distro_bootpart in ${devplist}; do " > >>> > + "if fstype ${devtype} " > >>> > + "${devnum}:${distro_bootpart} " > >>> > + "bootfstype; then " > >>> > + "run scan_dev_for_boot; " > >>> > + "fi; " > >>> > + "done\0" > >>> > + ); > >>> > return rk_board_late_init(); > >>> > } > >>> > > >>> > diff --git a/arch/arm/mach-rockchip/rk3288-board.c > >>> > b/arch/arm/mach-rockchip/rk3288-board.c > >>> > index 9894a25..386b155 100644 > >>> > --- a/arch/arm/mach-rockchip/rk3288-board.c > >>> > +++ b/arch/arm/mach-rockchip/rk3288-board.c > >>> > @@ -74,7 +74,25 @@ int board_late_init(void) > >>> > { > >>> > setup_boot_mode(); > >>> > rk3288_qos_init(); > >>> > - > >>> > + setenv("scan_dev_for_boot_part", > >>> > + "part list ${devtype} ${devnum} -bootable > test; > >>> > " > >>> > + "if env exists test; then " > >>> > + "echo Found valid partition table; " > >>> > + "else " > >>> > + "echo No valid partition table, write the > >>> > original partition table; " > >>> > + "gpt write ${devtype} ${devnum} > >>> > ${partitions}; " > >>> > + "mmc rescan;" > >>> > + "fi;" > >>> > + "part list ${devtype} ${devnum} -bootable > >>> > devplist; " > >>> > + "env exists devplist || setenv devplist 1; " > >>> > + "for distro_bootpart in ${devplist}; do " > >>> > + "if fstype ${devtype} " > >>> > + "${devnum}:${distro_bootpart} " > >>> > + "bootfstype; then " > >>> > + "run scan_dev_for_boot; " > >>> > + "fi; " > >>> > + "done\0" > >>> > + ); > >>> > return rk_board_late_init(); > >>> > } > >>> > > >>> > diff --git a/arch/arm/mach-rockchip/rk3399-board.c > >>> > b/arch/arm/mach-rockchip/rk3399-board.c > >>> > new file mode 100644 > >>> > index 0000000..3777643 > >>> > --- /dev/null > >>> > +++ b/arch/arm/mach-rockchip/rk3399-board.c > >>> > @@ -0,0 +1,46 @@ > >>> > +/* > >>> > + * (C) Copyright 2017 ockchip Electronics Co., Ltd > >>> > + * > >>> > + * SPDX-License-Identifier: GPL-2.0+ > >>> > + */ > >>> > + > >>> > +#include <common.h> > >>> > +#include <clk.h> > >>> > +#include <dm.h> > >>> > +#include <ram.h> > >>> > +#include <syscon.h> > >>> > +#include <asm/io.h> > >>> > +#include <asm/arch/clock.h> > >>> > +#include <asm/arch/periph.h> > >>> > + > >>> > +DECLARE_GLOBAL_DATA_PTR; > >>> > + > >>> > +__weak int rk_board_late_init(void) > >>> > +{ > >>> > + return 0; > >>> > +} > >>> > + > >>> > +int board_late_init(void) > >>> > +{ > >>> > + setenv("scan_dev_for_boot_part", > >>> > + "part list ${devtype} ${devnum} -bootable > test; > >>> > " > >>> > + "if env exists test; then " > >>> > + "echo Found valid partition table; " > >>> > + "else " > >>> > + "echo No valid partition table, write the > >>> > original partition table; " > >>> > + "gpt write ${devtype} ${devnum} > >>> > ${partitions}; " > >>> > + "mmc rescan;" > >>> > + "fi;" > >>> > + "part list ${devtype} ${devnum} -bootable > >>> > devplist; " > >>> > + "env exists devplist || setenv devplist 1; " > >>> > + "for distro_bootpart in ${devplist}; do " > >>> > + "if fstype ${devtype} " > >>> > + "${devnum}:${distro_bootpart} " > >>> > + "bootfstype; then " > >>> > + "run scan_dev_for_boot; " > >>> > + "fi; " > >>> > + "done\0" > >>> > >>> What is the purpose of this setenv()? > >> > >> Auto write GPT table when scan_dev_for_boot_part fail to find a valid > one > > > > To be more clearly. If the GPT table in the boot media corrupted. Or > there > > is no GPT table in the boot media. The original scan_dev_for_boot_part > will > > fail to find a bootable partition. I just let it write GPT table when > can > > not find a valid one. > >>> > > OK, but you should not be changing the environment in your code. Can > you add your changes to the default environment (and put them in a > common file so that we don't have to repeat the same thing in each > file)? > done > > Regards, > Simon > _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/listinfo/u-boot