1HOST_DEFAULT_TARGETS = " \
2    multi-user.target.wants/obmc-host-reset@{}.target \
3    multi-user.target.wants/phosphor-discover-system-state@{}.service \
4    obmc-host-start@{}.target.requires/obmc-host-startmin@{}.target \
5    obmc-host-start@{}.target.requires/phosphor-reset-host-reboot-attempts@{}.service \
6    obmc-host-startmin@{}.target.wants/phosphor-set-host-transition-to-running@{}.service \
7    obmc-host-stop@{}.target.wants/phosphor-set-host-transition-to-off@{}.service \
8    obmc-host-reset@{}.target.requires/phosphor-reset-host-running@{}.service \
9    obmc-host-stop@{}.target.wants/phosphor-reset-sensor-states@{}.service \
10    obmc-host-shutdown@{}.target.requires/obmc-host-stop@{}.target \
11    obmc-host-graceful-quiesce@{}.target.wants/obmc-host-quiesce@{}.target \
12    obmc-host-graceful-quiesce@{}.target.wants/pldmSoftPowerOff.service \
13    obmc-host-quiesce@{}.target.wants/phosphor-reset-sensor-states@{}.service \
14    obmc-host-reboot@{}.target.requires/obmc-host-shutdown@{}.target \
15    obmc-host-reboot@{}.target.requires/phosphor-reboot-host@{}.service \
16    obmc-host-warm-reboot@{}.target.requires/xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service \
17    obmc-host-force-warm-reboot@{}.target.requires/obmc-host-stop@{}.target \
18    obmc-host-force-warm-reboot@{}.target.requires/phosphor-reboot-host@{}.service \
19    obmc-host-warm-reboot@{}.target.requires/obmc-host-force-warm-reboot@{}.target \
20"
21
22CHASSIS_DEFAULT_TARGETS = " \
23    obmc-chassis-poweron@{}.target.wants/phosphor-reset-host-recovery@{}.service \
24    obmc-chassis-poweron@{}.target.requires/obmc-power-start@{}.service \
25    obmc-chassis-poweron@{}.target.requires/phosphor-set-chassis-transition-to-on@{}.service \
26    obmc-host-shutdown@{}.target.requires/obmc-chassis-poweroff@{}.target \
27    obmc-chassis-poweroff@{}.target.requires/obmc-power-stop@{}.service \
28    obmc-chassis-poweroff@{}.target.requires/obmc-powered-off@{}.service \
29    obmc-chassis-poweroff@{}.target.wants/phosphor-clear-one-time@{}.service \
30    obmc-chassis-poweroff@{}.target.requires/phosphor-set-chassis-transition-to-off@{}.service \
31    obmc-chassis-blackout@{}.target.wants/phosphor-reset-sensor-states@{}.service \
32    obmc-chassis-powerreset@{}.target.requires/phosphor-reset-chassis-on@{}.service \
33    obmc-chassis-powerreset@{}.target.requires/phosphor-reset-chassis-running@{}.service \
34"
35
36# TODO: There are some targets that are chassis oriented, but there is no
37#       obvious way to map HOST<->CHASSIS relationships.  Making an assumption
38#       currently that there is a 1-to-1 relationship between the two.
39
40pkg_postinst:${PN}-obmc-targets:append() {
41    for i in ${OBMC_HOST_INSTANCES};
42    do
43        for j in ${HOST_DEFAULT_TARGETS};
44        do
45            LINK="$D$systemd_system_unitdir/${j}"
46            LINK="$(echo ${LINK} | sed s/{}/${i}/g )"
47            TARGET="../$(basename ${j} | sed s/{}//g )"
48            mkdir -p "$(dirname ${LINK})"
49            ln -s "${TARGET}" "${LINK}"
50        done
51    done
52
53    for i in ${OBMC_CHASSIS_INSTANCES};
54    do
55        for j in ${CHASSIS_DEFAULT_TARGETS};
56        do
57            LINK="$D$systemd_system_unitdir/${j}"
58            LINK="$(echo ${LINK} | sed s/{}/${i}/g )"
59            TARGET="../$(basename ${j} | sed s/{}//g )"
60            mkdir -p "$(dirname ${LINK})"
61            ln -s "${TARGET}" "${LINK}"
62        done
63    done
64}
65
66pkg_prerm:${PN}-obmc-targets:append() {
67    for i in ${OBMC_HOST_INSTANCES};
68    do
69        for j in ${HOST_DEFAULT_TARGETS};
70        do
71            LINK="$D$systemd_system_unitdir/${j}"
72            LINK="$(echo ${LINK} | sed s/{}/${i}/g )"
73            rm "${LINK}"
74        done
75    done
76
77    for i in ${OBMC_CHASSIS_INSTANCES};
78    do
79        for j in ${CHASSIS_DEFAULT_TARGETS};
80        do
81            LINK="$D$systemd_system_unitdir/${j}"
82            LINK="$(echo ${LINK} | sed s/{}/${i}/g )"
83            rm "${LINK}"
84        done
85    done
86}
87
88pkg_postinst:${PN}-chassis:append() {
89    for i in ${OBMC_CHASSIS_INSTANCES};
90    do
91        mkdir -p $D$systemd_system_unitdir/multi-user.target.requires
92        LINK="$D$systemd_system_unitdir/multi-user.target.requires/xyz.openbmc_project.State.Chassis@${i}.service"
93        TARGET="../xyz.openbmc_project.State.Chassis@.service"
94        ln -s $TARGET $LINK
95    done
96}
97
98pkg_prerm:${PN}-chassis:append() {
99    for i in ${OBMC_CHASSIS_INSTANCES};
100    do
101        LINK="$D$systemd_system_unitdir/multi-user.target.requires/xyz.openbmc_project.State.Chassis@${i}.service"
102        rm $LINK
103    done
104}
105
106pkg_postinst:${PN}-chassis-check-power-status:append() {
107    for i in ${OBMC_CHASSIS_INSTANCES};
108    do
109        mkdir -p $D$systemd_system_unitdir/obmc-chassis-poweron@${i}.target.requires
110        LINK="$D$systemd_system_unitdir/obmc-chassis-poweron@${i}.target.requires/phosphor-chassis-check-power-status@${i}.service"
111        TARGET="../phosphor-chassis-check-power-status@.service"
112        ln -s $TARGET $LINK
113    done
114}
115
116pkg_prerm:${PN}-chassis-check-power-status:append() {
117    for i in ${OBMC_CHASSIS_INSTANCES};
118    do
119        LINK="$D$systemd_system_unitdir/obmc-chassis-poweron@${i}.target.requires/phosphor-chassis-check-power-status@${i}.service"
120        rm $LINK
121    done
122}
123
124pkg_postinst:${PN}-chassis-poweron-log:append() {
125    for i in ${OBMC_CHASSIS_INSTANCES};
126    do
127        mkdir -p $D$systemd_system_unitdir/obmc-chassis-poweron@${i}.target.wants
128        LINK="$D$systemd_system_unitdir/obmc-chassis-poweron@${i}.target.wants/phosphor-create-chassis-poweron-log@${i}.service"
129        TARGET="../phosphor-create-chassis-poweron-log@.service"
130        ln -s $TARGET $LINK
131    done
132}
133
134pkg_prerm:${PN}-chassis-poweron-log:append() {
135    for i in ${OBMC_CHASSIS_INSTANCES};
136    do
137        LINK="$D$systemd_system_unitdir/obmc-chassis-poweron@${i}.target.wants/phosphor-create-chassis-poweron-log@${i}.service"
138        rm $LINK
139    done
140}
141
142pkg_postinst:${PN}-host:append() {
143    for i in ${OBMC_HOST_INSTANCES};
144    do
145        mkdir -p $D$systemd_system_unitdir/multi-user.target.requires
146        LINK="$D$systemd_system_unitdir/multi-user.target.requires/xyz.openbmc_project.State.Host@${i}.service"
147        TARGET="../xyz.openbmc_project.State.Host@.service"
148        ln -s $TARGET $LINK
149
150        if ${@bb.utils.contains('PACKAGECONFIG', 'host-gpio', 'true', 'false', d)}
151        then
152            LINK="$D$systemd_system_unitdir/multi-user.target.requires/phosphor-host-condition-gpio@${i}.service"
153            TARGET="../phosphor-host-condition-gpio@.service"
154            ln -s $TARGET $LINK
155        fi
156    done
157}
158
159pkg_prerm:${PN}-host:append() {
160    for i in ${OBMC_HOST_INSTANCES};
161    do
162        LINK="$D$systemd_system_unitdir/multi-user.target.requires/xyz.openbmc_project.State.Host@${i}.service"
163        rm $LINK
164    done
165}
166
167pkg_postinst:${PN}-scheduled-host-transition:append() {
168    for i in ${OBMC_HOST_INSTANCES};
169    do
170        mkdir -p $D$systemd_system_unitdir/multi-user.target.wants
171        LINK="$D$systemd_system_unitdir/multi-user.target.wants/xyz.openbmc_project.State.ScheduledHostTransition@${i}.service"
172        TARGET="../xyz.openbmc_project.State.ScheduledHostTransition@.service"
173        ln -s $TARGET $LINK
174    done
175}
176
177pkg_prerm:${PN}-scheduled-host-transition:append() {
178    for i in ${OBMC_HOST_INSTANCES};
179    do
180        LINK="$D$systemd_system_unitdir/multi-user.target.wants/xyz.openbmc_project.State.ScheduledHostTransition@${i}.service"
181        rm $LINK
182    done
183}
184