Skip to content

fix booting from kernel for non-ubifs rootfs #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2015.10
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions include/configs/pistachio_bub.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,13 @@
#define BOOT_ENV_LEGACY \
"fdtaddr=0x0D000000\0"\
"fdtfile="PISTACHIO_BOARD_NAME".dtb\0"\
"legacy_bootfile=uImage\0"\
"legacy_nandroot=root=ubi0:rootfs rootfstype=ubifs\0"
"legacy_bootfile=uImage\0"

#define NAND_BOOTCOMMAND_LEGACY \
"setenv legacy_nandroot ubi.mtd=firmware$boot_partition $legacy_nandroot;"\
"setenv bootargs $console $earlycon $legacy_nandroot $bootextra $mtdparts panic=2;"\
"echo Loading legacy kernel from rootfs... && "\
"echo Loading legacy kernel (uImage) from rootfs... && "\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it's still a variable so you can't specify uImage

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually legacy bootfile is already uImage so it is always TRUE?

"ubifsload $loadaddr $bootdir$legacy_bootfile && "\
"ubifsload $fdtaddr $bootdir$fdtfile && "\
"bootm $loadaddr - $fdtaddr || "
"bootm $loadaddr - $fdtaddr || reset;"

#else

Expand All @@ -307,18 +304,25 @@

#endif

/*
* Openwrt have squashfs rootfs but legacy and other variant uses ubifs
* rootfs. To make all compatible dont pass root= for kernel booting
* from kernel ubi volume. For others, pass root= to correctly identify
* rootfs filesystem.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't explain why this works, nor does the commit message. I would expect the commit message to go into detail of the different boot scenarios this supports.

*/
#define NAND_BOOTCOMMAND \
"setenv nandroot ubi.mtd=firmware$boot_partition $nandroot;"\
"setenv bootargs $console $earlycon $nandroot $bootextra $mtdparts panic=2;"\
"echo Attempting to boot from firmware$boot_partition;"\
"setenv ubimtd ubi.mtd=firmware$boot_partition;"\
"ubi part firmware$boot_partition || reset;"\
"if ubi check kernel; then "\
"echo Loading kernel from volume...;"\
"setenv bootargs $console $earlycon $ubimtd $bootextra $mtdparts panic=2;"\
"ubi read $loadaddr kernel || reset;"\
"else "\
"echo Loading kernel from rootfs...;"\
"setenv bootargs $console $earlycon $ubimtd $nandroot $bootextra $mtdparts panic=2; && "\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a semicolon changes the logic:

pistachio # true || echo foo
pistachio # true; || echo foo
foo

I don't think you want the && at all?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i dont pass && somehow bootargs was not getting pass correctly to kernel, we could remove ; though. any idea?

"ubifsmount ubi:rootfs && "\
"ubifsload $loadaddr $bootdir$fitfile || "NAND_BOOTCOMMAND_LEGACY"reset;"\
"ubifsload $loadaddr $bootdir$fitfile || "NAND_BOOTCOMMAND_LEGACY" "\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably would move the || out of NAND_BOOTCOMMAND_LEGACY to here rather than moving the reset inside?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way i read is this:
Try ubifsload
if fail try nandboot
in nandboot
try booting (if success it will not return)
else if failed to boot reset
If ubifsload succeed proceed with booting or if case of failure reset.
So booting is something which is not expected to return if success. only in case it fails we want to reset. This is reason reset look more to be part with actually command for which we want to test the condition?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original idea was quite simple but we had to add legacy boot complications. Currently we attempted to follow this when loading kernel from the filesystem:

  1. try to load fit image from ubifs
  2. if fail try to load uImage from ubifs
  3. if fail reset

This means if we drop step 2 the device would still reset when step 1 fails.

"fi;"

#define ALT_BOOTCOMMAND \
Expand Down Expand Up @@ -355,7 +359,7 @@
"netroot=root=/dev/nfs rootfstype=nfs ip=dhcp\0"\
"usbroot=root=/dev/sda1\0"\
"mmcroot=root=/dev/mmcblk0p1\0"\
"nandroot=\0"\
"nandroot=root=ubi0:rootfs rootfstype=ubifs\0"\
"usbdev=0\0"\
"mmcdev=0\0"\
"usbboot="INIT_BOOTCOMMAND USB_BOOTCOMMAND FINAL_BOOTCOMMAND"\0"\
Expand Down