Techniques for forming a magnetic device are provided. In one aspect, a
method of forming a via hole self-aligned with a magnetic device
comprises the following steps. A dielectric layer is formed over at least
a portion of the magnetic device. The dielectric layer is configured to
have an underlayer proximate to the magnetic device which comprises a
first material, and an overlayer on a side of the underlayer opposite the
magnetic device which comprises a second material. The first material is
different from the second material. In a first etching phase, a first
etchant is used to etch the dielectric layer, beginning with the
overlayer, and through the overlayer. In a second etching phase, a second
etchant which is selective for etching the underlayer is used to etch the
dielectric layer through the underlayer.