mer-hybris / hybris-initrd

initrd generation submodule for flashable Sailfish OS image based boot images and recovery images.
2 stars 17 forks source link

[initrd] Pass device-specific environment variables to initrd. JB#54875 #49

Closed AndreevDmitry closed 3 years ago

AndreevDmitry commented 3 years ago

The problem is unable to set device-specific environment variable in both normal and recovery initrd environment without edit droid-hal-img-boot.inc. To resolve this issue we can use droid-hal-$DEVICE-img-boot.spec and define macro "initrd_env_vars" for example

%define initrd_env_vars \ FOO=bar\ XYZ=123\ %{nil}

and then handle it in initrd spec to forward variables to /etc/sysconfig/init Also we need to add /etc/sysconfig/init to allexport section of recovery-init so that variables appeared in recovery environment. Also we need to add allexport section to root-mount script for appear variables in boot initrd environment.

sledges commented 3 years ago

You can create a list of environment variables in the device-specific droid-hal-$DEVICE-img-boot.spec:

%define initrd_env_vars \
FOO=bar\
XYZ=123\
%{nil}

Then in the submodule's .inc:

%if 0%{?initrd_env_vars:1}
cat <<EOF >> $INIT_FILE
%{?initrd_env_vars}
EOF
%endif
AndreevDmitry commented 3 years ago

You can create a list of environment variables in the device-specific droid-hal-$DEVICE-img-boot.spec:

%define initrd_env_vars \
FOO=bar\
XYZ=123\
%{nil}

Then in the submodule's .inc:

%if 0%{?initrd_env_vars:1}
cat <<EOF >> $INIT_FILE
%{?initrd_env_vars}
EOF
%endif

In this case we will have one another place (droid-hal-$DEVICE-img-boot.spec) to set device specific things, because now it works via macro.xml from droid-prjconf (for example lvm_root_size). Do we really need this new extra interface for setting device specific environment?

sledges commented 3 years ago

Please do not use OBS project configuration (prjconf) for device settings.

We use lvm_root_size in the same .spec as all other macros shown in the top comments of https://github.com/mer-hybris/hybris-initrd/blob/master/droid-hal-device-img-boot.inc (example here).

Using prjconf for to control important build-time and runtime environments breaks the ability to build a device adaptation from command line (without OBS).

AndreevDmitry commented 3 years ago

Please do not use OBS project configuration (prjconf) for device settings.

We use lvm_root_size in the same .spec as all other macros shown in the top comments of https://github.com/mer-hybris/hybris-initrd/blob/master/droid-hal-device-img-boot.inc (example here).

Using prjconf for to control important build-time and runtime environments breaks the ability to build a device adaptation from command line (without OBS).

Thanks for explanation, updated.

AndreevDmitry commented 3 years ago

Thanks for comments, when I check this new solution I found that in boot initrd we do not have environment variables from

/etc/sysconfig/init
/etc/sysconfig/partitions
/etc/sysconfig/display

You can check it by input env in root-mount

+              env

        # Minimize power consumption by lowering display brightness to minimum
        write $DISPLAY_BRIGHTNESS_PATH $DISPLAY_BRIGHTNESS

And get log by UART, I have only

bootopt=64S3,32N2,32N2
ddr_speed=1066000
mrdump_ddrsv=yes
SHLVL=2
HOME=/
mrdump_rsvmem=0x41e00000,0x400000,0x42100000,0x1dc700,0x4e000000,0x80000,0x421dc6c0,0x9a
ddr_name=H9CKNNNBJTMPLR_NUH
boot_reason=4
TERM=linux
PWD=/
sledges commented 3 years ago

env lists only exported variables (set lists all). The result would be the same with both new and old solutions.

AndreevDmitry commented 3 years ago

env lists only exported variables (set lists all). The result would be the same with both new and old solutions.

I agree that it is not depend on new or old solution, but unfortunatelly my device specific variable were not added to environment without adding section set -o allexport to root-mount and appropriate functionality is not work. So do you agree to add section set -o allexport to root-mount as in https://github.com/mer-hybris/hybris-initrd/pull/49/files#diff-ead334f09df51312c052f2dee20cbbe741681bb0327716e8c6deab839724c866?

Thaodan commented 3 years ago

env lists only exported variables (set lists all). The result would be the same with both new and old solutions. I agree that it is not depend on new or old solution, but unfortunatelly my device specific variable were not added to environment without adding section set -o allexport to root-mount and appropriate functionality is not work. So do you agree to add section set -o allexport to root-mount as in https://github.com/mer-hybris/hybris-initrd/pull/49/files#diff-ead334f09df5 1312c052f2dee20cbbe741681bb0327716e8c6deab839724c866? But is that the purpose of those?

Usually those kind of vars go to droid-configs.

sledges commented 3 years ago

my device specific variable were not added to environment without adding section set -o allexport to root-mount and appropriate functionality is not work. So do you agree to add section set -o allexport to root-mount

This has already been done in recovery (https://github.com/mer-hybris/hybris-initrd/commit/2f6d2d982e93440affddd1f8789c472499e8e9d2) by @krnlyng. Shouldn't be a problem if your case is similar.

AndreevDmitry commented 3 years ago

my device specific variable were not added to environment without adding section set -o allexport to root-mount and appropriate functionality is not work. So do you agree to add section set -o allexport to root-mount

This has already been done in recovery (2f6d2d9) by @krnlyng. Shouldn't be a problem if your case is similar.

Yes, my case is similar

sledges commented 3 years ago

But is that the purpose of those? Usually those kind of vars go to droid-configs.

These variables are low level, and needed and used in initrd (pre-preinit, before rootfs switch). They are not available once the OS has booted, as /etc/sysconfig would be coming from another place (no longer initrd).

sledges commented 3 years ago

Now my bad, I didn't see one more filename inconsistency in the commit description, and forgot to ask you to also write documentation in the comments.

I did all that and pushed to this PR on your behalf. Thanks for your patience. Merging now.