Holding a door open for someone is, by etymology, a cavalry maneuver. The word "chivalry" started out meaning soldiers on horseback.
Its root is Latin caballus. Merriam-Webster, in its entry for cavalier, glosses it as "work horse, gelding," a plain everyday animal rather than a noble steed. Classical Latin had a grander word, equus, but the Anglo-Norman Dictionary notes that equus left no everyday descendant in Anglo-Norman. It was caballus that became French cheval, and similar words across the Romance languages.
From caballus, Late Latin built caballārius, a rider. In Old French that became chevaler or chevalier. The Anglo-Norman Dictionary says the word first meant a mounted rider and later widened from "mounted soldier" to "knight" in general. Add the suffix -erie and you get chevalerie, the knights as a group.
English borrowed it around 1300, in a tangle of spellings. The Etymology Nerd lists chivalrie, cheualry, chewalrye and more. Merriam-Webster's first sense is still "mounted men-at-arms." Early uses could also mean knighthood itself, warfare or a kind of land tenure.
The moral meanings came later. Merriam-Webster lists the system and customs of medieval knighthood, then "the qualities of the ideal knight." Today the word mostly means honorable, courteous behavior.
The romantic picture owes a great deal to Sir Walter Scott. He wrote the essay on chivalry for the Encyclopaedia Britannica's supplement of 1815 to 1824. Even Scott said the primitive sense was simply cavalry. EBSCO's history overview credits his novel Ivanhoe with reviving interest in chivalry.
The horse also runs through words that took an Italian road. Merriam-Webster traces cavalry to Italian cavalleria, borrowed through French. Cavalier comes from the same caballārius. Puritans used "cavalier" with contempt for the royalists of Charles I. That use helped give the adjective its flippant sense, which is now its most common meaning.