Alexander Wynne published a book on history of meditation [1]. On the subject of jhana, he points that a description of the first jhana appears in a Mahābhārata passage "where it is said that for the sage who has the first dhyāna, there is vicāra, vitarka and viveka" -- no descriptions of further jhanas seem to appear.
He argues that it is likely that this passage was borrowed from Buddhism -- and overall, that it is likely there was interchange of knowledge of meditation between both traditions.
Maybe the formula and attainment of 1st jhana were known to ascetics in general. Maybe they could attain it, but had not systematize it (with it's factors and hindrances) and later borrowed the formula from the Buddha. Or maybe the Buddha came up with it on his own. If we trust the reading of the suttas where the Buddha remembers an early experience of jhana, and that this meant no contemporary teacher knew how to attain it, the later might be true.
Now, on formless meditation, Alexander concludes that (paraphrasing):
- The buddhist list of four formless spheres was inherited from Alara Kalama and Uddakha Ramaputta.
- Formless meditation is related to element meditation
- Therefore element meditation was borrowed from the same non-Buddhist source as was formless meditation (eg. from the two teachers)
- The doctrinal background of element meditation and formless meditation is provided by a list of six dhatu
- The list is based on early Brahminic cosmogonies
- Brahminic cosmogonies provide the doctrinal background to meditation in early Brahmanism
- Therefore, element meditation and formless meditation were borrowed from a brahmanic source
- The brahmanic source is probably these former teachers (Alara Kalama and Uddakha Ramaputta, Alara Kalama and Rāma, or perhaps the three?).
It might be worth to mention that the first ascetics the Buddha considered teaching after attaining nibbāna were Alara and Uddakha, for they had "little dust in their eyes" [2].
[1] The Origin of Buddhist Meditation, 2007
[2] Ariyapariyesana Sutta